Code covered by the BSD License  

Highlights from
color image segmentation

image thumbnail

color image segmentation

by

 

24 Nov 2010 (Updated )

segment color image robust to texture

colorImgSeg(img_dir, ...
function L  =  colorImgSeg(img_dir, ...
                              n_colors, J_scale,...
                              local_neighbor,...
                              J_threshold, J_sigma,...
                              merging_th)
%An implementation of [1]
%inputs:
%  img: input image
%J_map parameters:
%  n_colors: number of color levels to quantilized
%  J_scale: the scale of J-window
%valley parameters:
%  local_neighbor: the radius of the local valley
%speed map parameter:
%  J_threshold: threshold that above which is recognize as edge
%  J_sigma: the range of J-value belonging to edge
%merging parameters:
%  merging_th: the distance less than which would be merged
%outputs:
% L: image labels
%reference:
%[1]Yining Deng, B.S. Manjunath, Hyundoo Shin, "Color Image Segmentation," 
%   cvpr, vol. 2, pp.2446, 1999 IEEE Computer Society Conference on Computer 
%   Vision and Pattern Recognition (CVPR'99)- Volume 2, 1999

%color image segmentation:
img = imread(img_dir);
img = im2double(img);
%compute the Jmap
[Jmap, q_img] = cmp_Jmap(img, J_scale, n_colors);
%find the valleys:
Jmap_seeds = local_min_img(-Jmap, local_neighbor);
Jmap_seeds = im2double(Jmap_seeds);
%comput the speed map:
speed_map = speedTrans(Jmap, J_threshold, J_sigma);
%comput the oversegmentation:
labels = seededRegionGrowing(Jmap_seeds, speed_map);
%region merging:
L = Region_merging(q_img, labels-1, n_colors, max(labels(:)), merging_th);
%comput the boundary:
[cx, cy] = gradient(L);
cont = cx.^2+cy.^2;
bw_cont = cont>1;
seg_img = img;
for i=1:size(img, 3)
    sub_img = seg_img(:, :, i);
    sub_img(bw_cont) = 1;
    seg_img(:, :, i) = sub_img;
end
%display the segmented image:
figure, imshow(seg_img, []);
%display the results:
figure,
subplot(2, 2, 1), imshow(img);
subplot(2, 2, 2), imshow(Jmap+Jmap_seeds, []), title('seeds');
subplot(2, 2, 3), imshow(label2rgb(labels)), title('over segmentation');
subplot(2, 2, 4), imshow(label2rgb(L)), title('segmentation');

Contact us