Home » Source Code » » colorseg.m

## colorseg.m ( File view )

From：
• By 2010-08-14
• View(s)：45
• 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

Point(s): 2

0 lines left, continue to read

## File list

Tips: You can preview the content of files by clicking file names^_^
Name Size Date
average.m651.00 B16-12-04 13:36
bayesgauss.m2.96 kB16-12-04 13:36
bound2eight.m2.99 kB16-12-04 13:36
bound2four.m2.42 kB16-12-04 13:36
bound2im.m2.17 kB16-12-04 13:36
boundaries.m5.64 kB16-12-04 13:36
bsubsamp.m3.87 kB16-12-04 13:36
changeclass.m592.00 B16-12-04 13:36
colorseg.m2.37 kB16-12-04 13:36
compare.m1.15 kB16-12-04 13:36
connectpoly.m1.02 kB16-12-04 13:36
Contents.m5.98 kB16-12-04 13:36
conwaylaws.m799.00 B16-12-04 13:36
covmatrix.m977.00 B16-12-04 13:36
dftcorr.m687.00 B16-12-04 13:36
dftfilt.m882.00 B16-12-04 13:36
dftuv.m736.00 B16-12-04 13:36
diameter.m6.47 kB16-12-04 13:36
endpoints.m874.00 B16-12-04 13:36
entropy.m1.00 kB16-12-04 13:36
fchcode.m8.55 kB16-12-04 13:36
frdescp.m1.42 kB16-12-04 13:36
fwtcompare.m992.00 B16-12-04 13:36
gmean.m447.00 B16-12-04 13:36
gscale.m2.04 kB16-12-04 13:36
histroi.m920.00 B16-12-04 13:36
hough.m2.64 kB16-12-04 13:36
houghlines.m2.82 kB16-12-04 13:36
houghpeaks.m2.65 kB16-12-04 13:36
houghpixels.m1.02 kB16-12-04 13:36
hpfilter.m1.23 kB16-12-04 13:36
hsi2rgb.m1.94 kB16-12-04 13:36
huff2mat.m2.46 kB16-12-04 13:36
huffman.m2.82 kB16-12-04 13:36
ice.fig45.71 kB16-12-04 13:36
ice.m26.30 kB16-12-04 13:36
ice_stand_alone.m46.55 kB16-12-04 13:36
DIPUM_toolbox_m-file_v1[1].1.3_part1.rar60.11 kB13-04-09 20:38
ifrdescp.m1.38 kB16-12-04 13:36
ifwtcompare.m1.12 kB16-12-04 13:36
im2jpeg.m2.90 kB16-12-04 13:36
im2jpeg2k.m3.97 kB16-12-04 13:36
imnoise2.m4.20 kB16-12-04 13:36
imnoise3.m2.12 kB16-12-04 13:36
improd.m791.00 B16-12-04 13:36
imratio.m1.30 kB16-12-04 13:36
imstack2vectors.m1.83 kB16-12-04 13:36
intline.m1.20 kB16-12-04 13:36
intrans.m3.25 kB16-12-04 13:36
invmoments.m3.24 kB16-12-04 13:36
jpeg2im.m2.41 kB16-12-04 13:36
jpeg2k2im.m1.90 kB16-12-04 13:36
lpc2mat.m1.42 kB16-12-04 13:36
lpfilter.m1.44 kB16-12-04 13:36
mahalanobis.m1.97 kB16-12-04 13:36
manualhist.m1.75 kB16-12-04 13:36
mat2huff.m2.75 kB16-12-04 13:36
mat2lpc.m1.28 kB16-12-04 13:36
minperpoly.m7.15 kB16-12-04 13:36
pixeldup.m950.00 B16-12-04 13:36
polyangles.m6.14 kB16-12-04 13:36
princomp.m2.88 kB16-12-04 13:36
quantize.m1.33 kB16-12-04 13:36
randvertex.m1.15 kB16-12-04 13:36
regiongrow.m1.66 kB16-12-04 13:36
rgb2hsi.m1.46 kB16-12-04 13:36
rgbcube.m1.98 kB16-12-04 13:36
signature.m4.45 kB16-12-04 13:36
specxture.m2.57 kB16-12-04 13:36
spfilt.m3.78 kB16-12-04 13:36
splitmerge.m4.13 kB16-12-04 13:36
statmoments.m1.72 kB16-12-04 13:36
statxture.m1.55 kB16-12-04 13:36
strsimilarity.m1.78 kB16-12-04 13:36
subim.m713.00 B16-12-04 13:36
twodsin.m1.04 kB16-12-04 13:36
twomodegauss.m1.16 kB16-12-04 13:36
unravel.dll7.00 kB16-12-04 13:36
unravel.m967.00 B16-12-04 13:36
unravel.mexaxp24.00 kB16-12-04 13:36
unravel.mexglx18.97 kB16-12-04 13:36
unravel.mexhpux12.00 kB16-12-04 13:36
unravel.mexmac8.68 kB16-12-04 13:36
unravel.mexrs62.71 kB16-12-04 13:36
unravel.mexsg24.44 kB16-12-04 13:36
unravel.mexsol8.54 kB16-12-04 13:36
vistformfwd.m1.66 kB16-12-04 13:36
wave2gray.m4.67 kB16-12-04 13:36
waveback.m4.52 kB16-12-04 13:36
wavecopy.m940.00 B16-12-04 13:36
wavecut.m1.06 kB16-12-04 13:36
wavefast.m4.14 kB16-12-04 13:36
wavefilter.m4.77 kB16-12-04 13:36
wavepaste.m1.04 kB16-12-04 13:36
wavework.m3.45 kB16-12-04 13:36
wavezero.m696.00 B16-12-04 13:36
x2majoraxis.m3.59 kB16-12-04 13:36
DIPUM_toolbox_m-file_v1[1].1.3_part2.rar85.71 kB13-04-09 20:39
<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>0.00 B02-07-09 16:26
<冈萨雷斯（matlab）>0.00 B02-07-09 16:26
...
• Sent successfully!
• 2 point
×

### colorseg.m (304.87 kB)

Need 2 point

Get point immediately by PayPal

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

Submit your source codes. Get more point

×

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

### 切换到中文版？

CodeForge Chinese Version
CodeForge English Version
×

×

### ^_^"Oops ...

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

### Warm tip!

Favorite by Ctrl+D