Which threshold method will work for my image?

2 ビュー (過去 30 日間)
Sabanam
Sabanam 2014 年 3 月 27 日
コメント済み: Sabanam 2014 年 3 月 30 日
I have implemented thresolding manually but it didn't separate foreground to background..plz help me to finalize threshold..need color information of mango part and want to remove background
rgb=imread(filepath);
% figure,imshow(rgb),title('Orignal Mango');
%% RGB to gray
% J = rgb2gray(rgb);
rr = rgb(:,:,1);
gg = rgb(:,:,2);
bb = rgb(:,:,3);
% figure,imshow(J),title('Gray image');
%% Threshold Image to black and white
[r1,c1]=size(rr);
rr1=zeros(r1,c1);
gg1=zeros(r1,c1);
bb1=zeros(r1,c1);
for i=1:r1
for j=1:c1
if(rr(i,j)>170)
rr1(i,j)=1;
end
if(gg(i,j)>170)
gg1(i,j)=1;
end
if(bb(i,j)>170)
bb1(i,j)=1;
end
end
end img = ~im2bw(cat(3,rr1,gg1,bb1));
figure,imshow(img),title('orignal Mango');

採用された回答

Sean de Wolski
Sean de Wolski 2014 年 3 月 28 日
I'd just use R2014a's color thresholder app. You can pick your colorspace, make your selections until you like the result and then generate code to repeat the process on other images. Here it is using b*
  5 件のコメント
Sabanam
Sabanam 2014 年 3 月 29 日
From above pic can you give me the segmentation code in Lab color space as i dont have 2014a...
Image Analyst
Image Analyst 2014 年 3 月 29 日
編集済み: Image Analyst 2014 年 3 月 29 日
You can see from the bottom plot that if b is less than 20, it's background, and if b is > 20 it's mango. However if you do that and have reddish mangos, you won't get them. You're going to have to use both a and b to calculate the saturation (chroma) like I showed you in my answer. Be sure to show the older comments so you see mine.

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

その他の回答 (1 件)

Image Analyst
Image Analyst 2014 年 3 月 28 日
Try the attached script, which uses color segmentation in the HSV color space. Basically your background has saturation values less than 0.1. So I found the background by thresholding at 0.1 and using that binary image to mask your original color images. The script produces this:
  25 件のコメント
Image Analyst
Image Analyst 2014 年 3 月 29 日
I actually ran your code too, and it ran with no errors. I just added an imshow(BW) so I could see the results. It's attached.
Sabanam
Sabanam 2014 年 3 月 30 日
its working now...I have uninstalled matlab and reinstall the matlab...Now its working. ..
cheers the results.vote of thanks to you

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

Community Treasure Hunt

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

Start Hunting!

Translated by