Home » Source Code » » colorseg.m

colorseg.m ( File view )

From:
  • By 2010-08-14
  • View(s):45
  • Download(s):4
  • Point(s): 2
			function I = colorseg(varargin)
%COLORSEG Performs segmentation of a color image.
%   S = COLORSEG('EUCLIDEAN', F, T, M) performs segmentation of color
%   image F using a Euclidean measure of similarity. M is a 1-by-3
%   vector representing the average color used for segmentation (this
%   is the center of the sphere in Fig. 6.26 of DIPUM). T is the
%   threshold against which the distances are compared.
%
%   S = COLORSEG('MAHALANOBIS', F, T, M, C) performs segmentation of
%   color image F using the Mahalanobis distance as a measure of
%   similarity. C is the 3-by-3 covariance matrix of the sample color
%   vectors of the class of interest. See function covmatrix for the
%   computation of C and M. 
%
%   S is the segmented image (a binary matrix) in which 0s denote the
%   background. 

%   Copyright 2002-2004 R. C. Gonzalez, R. E. Woods, & S. L. Eddins
%   Digital Image Processing Using MATLAB, Prentice-Hall, 2004
%   $Revision: 1.5 $  $Date: 2003/11/21 14:28:34 $

% Preliminaries.
% Recall that varargin is a cell array.
f = varargin{
2
};
if (ndims(f) ~= 3) | (size(f, 3) ~= 3)
   error('Input image must be RGB.');
end
M = size(f, 1); N = size(f, 2);
% Convert f to vector format using function imstack2vectors.
[f, L] = imstack2vectors(f);
f = double(f);
% Initialize I as a column vector.  It will be reshaped later
% into an image.
I = zeros(M*N, 1); 
T = varargin{
3
};
m = varargin{
4
};
m = m(:)'; % Make sure that m is a row vector.

if length(varargin) == 4 
   method = 'euclidean';
elseif length(varargin) == 5 
   method = 'mahalanobis';
else 
   error('Wrong number of inputs.');
end

switch method
case 'euclidean'
   % Compute the Euclidean distance between all rows of X and m. See
   % Section 12.2 of DIPUM for an explanation of the following
   % expression. D(i) is the Euclidean distance between vector X(i,:)
   % and vector m. 
   p = length(f);
   D = sqrt(sum(abs(f - repmat(m, p, 1)).^2, 2));
case 'mahalanobis'
   C = varargin{
5
};
   D = mahalanobis(f, C, m);
otherwise 
   error('Unknown segmentation method.')
end

% D is a vector of size MN-by-1 containing the distance computations
% from all the color pixels to vector m. Find the distances <= T.
J = find(D <= T);

% Set the values of I(J) to 1.  These are the segmented
% color pixels.
I(J) = 1;

% Reshape I into an M-by-N image.
I = reshape(I, M, N);  
			
...
Expand> <Close

Want complete source code? Download it here

Point(s): 2

Download
0 lines left, continue to read
Sponsored links

File list

Tips: You can preview the content of files by clicking file names^_^
Name Size Date
code file 0_Read_Me_First.txt0_Read_Me_First.txt5.00 kB16-12-04 13:36
code file adpmedian.madpmedian.m1.54 kB16-12-04 13:36
code file average.maverage.m651.00 B16-12-04 13:36
code file bayesgauss.mbayesgauss.m2.96 kB16-12-04 13:36
code file bound2eight.mbound2eight.m2.99 kB16-12-04 13:36
code file bound2four.mbound2four.m2.42 kB16-12-04 13:36
code file bound2im.mbound2im.m2.17 kB16-12-04 13:36
code file boundaries.mboundaries.m5.64 kB16-12-04 13:36
code file bsubsamp.mbsubsamp.m3.87 kB16-12-04 13:36
code file changeclass.mchangeclass.m592.00 B16-12-04 13:36
code file colorgrad.mcolorgrad.m2.30 kB16-12-04 13:36
code file colorseg.mcolorseg.m2.37 kB16-12-04 13:36
code file compare.mcompare.m1.15 kB16-12-04 13:36
code file connectpoly.mconnectpoly.m1.02 kB16-12-04 13:36
code file Contents.mContents.m5.98 kB16-12-04 13:36
code file conwaylaws.mconwaylaws.m799.00 B16-12-04 13:36
code file covmatrix.mcovmatrix.m977.00 B16-12-04 13:36
code file dftcorr.mdftcorr.m687.00 B16-12-04 13:36
code file dftfilt.mdftfilt.m882.00 B16-12-04 13:36
code file dftuv.mdftuv.m736.00 B16-12-04 13:36
code file diameter.mdiameter.m6.47 kB16-12-04 13:36
code file endpoints.mendpoints.m874.00 B16-12-04 13:36
code file entropy.mentropy.m1.00 kB16-12-04 13:36
code file fchcode.mfchcode.m8.55 kB16-12-04 13:36
code file frdescp.mfrdescp.m1.42 kB16-12-04 13:36
code file fwtcompare.mfwtcompare.m992.00 B16-12-04 13:36
code file gmean.mgmean.m447.00 B16-12-04 13:36
code file gscale.mgscale.m2.04 kB16-12-04 13:36
code file histroi.mhistroi.m920.00 B16-12-04 13:36
code file hough.mhough.m2.64 kB16-12-04 13:36
code file houghlines.mhoughlines.m2.82 kB16-12-04 13:36
code file houghpeaks.mhoughpeaks.m2.65 kB16-12-04 13:36
code file houghpixels.mhoughpixels.m1.02 kB16-12-04 13:36
code file hpfilter.mhpfilter.m1.23 kB16-12-04 13:36
code file hsi2rgb.mhsi2rgb.m1.94 kB16-12-04 13:36
code file huff2mat.mhuff2mat.m2.46 kB16-12-04 13:36
code file huffman.mhuffman.m2.82 kB16-12-04 13:36
源码文件 ice.figice.fig45.71 kB16-12-04 13:36
code file ice.mice.m26.30 kB16-12-04 13:36
code file ice_stand_alone.mice_stand_alone.m46.55 kB16-12-04 13:36
源码文件 DIPUM_toolbox_m-file_v1[1].1.3_part1.rarDIPUM_toolbox_m-file_v1[1].1.3_part1.rar60.11 kB13-04-09 20:38
code file ifrdescp.mifrdescp.m1.38 kB16-12-04 13:36
code file ifwtcompare.mifwtcompare.m1.12 kB16-12-04 13:36
code file im2jpeg.mim2jpeg.m2.90 kB16-12-04 13:36
code file im2jpeg2k.mim2jpeg2k.m3.97 kB16-12-04 13:36
code file imnoise2.mimnoise2.m4.20 kB16-12-04 13:36
code file imnoise3.mimnoise3.m2.12 kB16-12-04 13:36
code file improd.mimprod.m791.00 B16-12-04 13:36
code file imratio.mimratio.m1.30 kB16-12-04 13:36
code file imstack2vectors.mimstack2vectors.m1.83 kB16-12-04 13:36
code file intline.mintline.m1.20 kB16-12-04 13:36
code file intrans.mintrans.m3.25 kB16-12-04 13:36
code file invmoments.minvmoments.m3.24 kB16-12-04 13:36
code file jpeg2im.mjpeg2im.m2.41 kB16-12-04 13:36
code file jpeg2k2im.mjpeg2k2im.m1.90 kB16-12-04 13:36
code file lpc2mat.mlpc2mat.m1.42 kB16-12-04 13:36
code file lpfilter.mlpfilter.m1.44 kB16-12-04 13:36
code file mahalanobis.mmahalanobis.m1.97 kB16-12-04 13:36
code file manualhist.mmanualhist.m1.75 kB16-12-04 13:36
code file mat2huff.mmat2huff.m2.75 kB16-12-04 13:36
code file mat2lpc.mmat2lpc.m1.28 kB16-12-04 13:36
code file minperpoly.mminperpoly.m7.15 kB16-12-04 13:36
code file paddedsize.mpaddedsize.m1.29 kB16-12-04 13:36
code file pixeldup.mpixeldup.m950.00 B16-12-04 13:36
code file polyangles.mpolyangles.m6.14 kB16-12-04 13:36
code file princomp.mprincomp.m2.88 kB16-12-04 13:36
code file quantize.mquantize.m1.33 kB16-12-04 13:36
code file randvertex.mrandvertex.m1.15 kB16-12-04 13:36
code file Readme.mReadme.m5.30 kB16-12-04 13:36
code file regiongrow.mregiongrow.m1.66 kB16-12-04 13:36
code file rgb2hsi.mrgb2hsi.m1.46 kB16-12-04 13:36
code file rgbcube.mrgbcube.m1.98 kB16-12-04 13:36
code file signature.msignature.m4.45 kB16-12-04 13:36
code file specxture.mspecxture.m2.57 kB16-12-04 13:36
code file spfilt.mspfilt.m3.78 kB16-12-04 13:36
code file splitmerge.msplitmerge.m4.13 kB16-12-04 13:36
code file statmoments.mstatmoments.m1.72 kB16-12-04 13:36
code file statxture.mstatxture.m1.55 kB16-12-04 13:36
code file strsimilarity.mstrsimilarity.m1.78 kB16-12-04 13:36
code file subim.msubim.m713.00 B16-12-04 13:36
code file twodsin.mtwodsin.m1.04 kB16-12-04 13:36
code file twomodegauss.mtwomodegauss.m1.16 kB16-12-04 13:36
源码文件 unravel.dllunravel.dll7.00 kB16-12-04 13:36
code file unravel.munravel.m967.00 B16-12-04 13:36
源码文件 unravel.mexaxpunravel.mexaxp24.00 kB16-12-04 13:36
源码文件 unravel.mexglxunravel.mexglx18.97 kB16-12-04 13:36
源码文件 unravel.mexhpuxunravel.mexhpux12.00 kB16-12-04 13:36
源码文件 unravel.mexmacunravel.mexmac8.68 kB16-12-04 13:36
源码文件 unravel.mexrs6unravel.mexrs62.71 kB16-12-04 13:36
源码文件 unravel.mexsgunravel.mexsg24.44 kB16-12-04 13:36
源码文件 unravel.mexsolunravel.mexsol8.54 kB16-12-04 13:36
code file vistformfwd.mvistformfwd.m1.66 kB16-12-04 13:36
code file wave2gray.mwave2gray.m4.67 kB16-12-04 13:36
code file waveback.mwaveback.m4.52 kB16-12-04 13:36
code file wavecopy.mwavecopy.m940.00 B16-12-04 13:36
code file wavecut.mwavecut.m1.06 kB16-12-04 13:36
code file wavefast.mwavefast.m4.14 kB16-12-04 13:36
code file wavefilter.mwavefilter.m4.77 kB16-12-04 13:36
code file wavepaste.mwavepaste.m1.04 kB16-12-04 13:36
code file wavework.mwavework.m3.45 kB16-12-04 13:36
code file wavezero.mwavezero.m696.00 B16-12-04 13:36
code file x2majoraxis.mx2majoraxis.m3.59 kB16-12-04 13:36
源码文件 DIPUM_toolbox_m-file_v1[1].1.3_part2.rarDIPUM_toolbox_m-file_v1[1].1.3_part2.rar85.71 kB13-04-09 20:39
源码文件 <DIPUM_toolbox_m-file_v1[1].1.3_part1><DIPUM_toolbox_m-file_v1[1].1.3_part1>0.00 B02-07-09 16:26
源码文件 <DIPUM_toolbox_m-file_v1[1].1.3_part2><DIPUM_toolbox_m-file_v1[1].1.3_part2>0.00 B02-07-09 16:26
源码文件 <冈萨雷斯(matlab)><冈萨雷斯(matlab)>0.00 B02-07-09 16:26
...
Sponsored links
×

colorseg.m (304.87 kB)

Need 2 point
Your Point(s)

Your Point isn't enough.

Get point immediately by PayPal

More(Debit card / Credit card / PayPal Credit / Online Banking)

Submit your source codes. Get more point

×

LOGIN

Don't have an account? Register now
Need any help?
Mail to: support@codeforge.com
×

切换到中文版?

CodeForge Chinese Version
CodeForge English Version
×

Where are you going?

×

^_^"Oops ...

Sorry!This guy is mysterious, its blog hasn't been opened, try another, please!
OK
×

Warm tip!

CodeForge to FavoriteFavorite by Ctrl+D