Filter löschen
Filter löschen

Which threshold method will work for my image?

1 Ansicht (letzte 30 Tage)
Sabanam
Sabanam am 27 Mär. 2014
Kommentiert: Sabanam am 30 Mär. 2014
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');

Akzeptierte Antwort

Sean de Wolski
Sean de Wolski am 28 Mär. 2014
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 Kommentare
Sabanam
Sabanam am 29 Mär. 2014
From above pic can you give me the segmentation code in Lab color space as i dont have 2014a...
Image Analyst
Image Analyst am 29 Mär. 2014
Bearbeitet: Image Analyst am 29 Mär. 2014
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.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

Image Analyst
Image Analyst am 28 Mär. 2014
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 Kommentare
Image Analyst
Image Analyst am 29 Mär. 2014
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 am 30 Mär. 2014
its working now...I have uninstalled matlab and reinstall the matlab...Now its working. ..
cheers the results.vote of thanks to you

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Introduction to Installation and Licensing finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by