フィルターのクリア

Separate the red and purple pixels in a photo

5 ビュー (過去 30 日間)
hu
hu 2014 年 9 月 5 日
コメント済み: Image Analyst 2014 年 9 月 5 日
Hi,
I have a problem to separate the red and purple pixels in the attached 24 bit photo.
Therefore, how can I "isolate", show and count only them (red/purple pixels), an example would be great.
What are the techniques I should consider in this kind of problems?
Thanks.

回答 (2 件)

Rushikesh Tade
Rushikesh Tade 2014 年 9 月 5 日
Tried to separate out the colors using K-Means Clustering using guide shown http://www.mathworks.in/help/images/examples/color-based-segmentation-using-k-means-clustering.html
input_im=imread('T2.jpg');
sz_im=size(input_im);
cform = makecform('srgb2lab');
lab_he = applycform(input_im,cform);
ab = double(lab_he(:,:,2:3));
nrows = size(ab,1);
ncols = size(ab,2);
ab = reshape(ab,nrows*ncols,2);
nColors = 3;
% repeat the clustering 3 times to avoid local minima
[cluster_idx, cluster_center] = kmeans(ab,nColors,'distance','sqEuclidean', ...
'Replicates',3);
pixel_labels = reshape(cluster_idx,nrows,ncols);
imshow(pixel_labels,[]), title('image labeled by cluster index');
segmented_images = cell(1,3);
rgb_label = repmat(pixel_labels,[1 1 3]);
for k = 1:nColors
color = input_im;
color(rgb_label ~= k) = 0;
segmented_images{k} = color;
end
for k=1:nColors
figure
title_string=sprintf('objects in cluster %d',k);
imshow(segmented_images{k}), title(title_string);
end
Which provides results as follows:
Hope this helps !
  3 件のコメント
hu
hu 2014 年 9 月 5 日
Thanks. How can I count the number of non-black pixels in one of the segmented_images{k}?
Image Analyst
Image Analyst 2014 年 9 月 5 日
See my comment above in my answer.

サインインしてコメントする。


Image Analyst
Image Analyst 2014 年 9 月 5 日
  7 件のコメント
hu
hu 2014 年 9 月 5 日
Thanks again. I just prefer Matlab code than Java & a code like that will be excellent in the File exchange
Image Analyst
Image Analyst 2014 年 9 月 5 日
That's fine, but don't let a preference for MATLAB blind you to the use of other tools that may help you understand and solve your problem. I hope it let you see that there is no clear threshold(s), in any color space, that will definitively work. That said, you can still segment your image by "carving up" the gamut, and you have several ways to do that, with demos in my File Exchange. Good luck. I don't have the Stats toolbox so I don't have kmeans() and I can't help you if you decide to adapt the Mathworks demo.

サインインしてコメントする。

カテゴリ

Help Center および File Exchange3-D Volumetric Image Processing についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by