Which threshold method will work for my image?

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

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Introduction to Installation and Licensing 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by