Which threshold method will work for my image?
2 次查看(过去 30 天)
显示 更早的评论
Sabanam
2014-3-27
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
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
2014-3-28
编辑:Sabanam
2014-3-28
Is it available in matlab2013b?..Where can i find it?Actully,I have 200 image database and i have to remove background but images have unequal distribution of background which is very harder to remove.I have to work on this real data set...So please provide some code which can help to subtract background..as soon as possible..
Image Analyst
2014-3-28
I don't believe so but Brett's tool is similar: http://www.mathworks.com/matlabcentral/fileexchange/38484-segmenttool-an-interactive-gui-for-segmenting-images
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
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
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 个评论
Sabanam
2014-3-28
编辑:Sabanam
2014-3-28
Sir,you have used HSV color space for color image segmentation but in my reaserch work i have focused on CIEL*a*b* color model and its advantage using image segmentation.So can you show same thing using CIEL*a*b* color model?Can it possible?
If yes then How?..Please reply as i need very urgent for Presentation
Thank in advance...
Image Analyst
2014-3-28
Try the new utility Sean is showing you. There is the ability to export the code. Otherwise you can convert to lab with makecform()
% Convert image from RGB colorspace to lab color space.
cform = makecform('srgb2lab');
lab_Image = applycform(im2double(rgbImage),cform);
% Extract out the color bands from the original image
% into 3 separate 2D arrays, one for each color component.
LChannel = lab_Image(:, :, 1);
aChannel = lab_Image(:, :, 2);
bChannel = lab_Image(:, :, 3);
but to segment out neutral colored pixels you'll have to compute the saturation anyway (sqrt(a^2+b^2))
mask = sqrt(aChannel .^2 + aChannel .^ 2) > 0.1;
or you'll have to threshold out a box in ab space. That might be okay if you have a big difference between your background and your mangos. Like
mask = abs(aChannel)<aThresh & abs(bChannel) < bThresh;
Salaheddin Hosseinzadeh
2014-3-28
@ Image Analyst
I'm wondering if you have some sort of tutorial for image processing beginners. I thought of reading a book, but then I realized I need to know the principles first. So I read about Mathematical Morpolog and ...
I really appreciate if you share your experience.
Tnx
Image Analyst
2014-3-28
Steve Eddins http://blogs.mathworks.com/steve/ has a book. All I have is my File Exchange http://www.mathworks.com/matlabcentral/fileexchange/?term=authorid%3A31862 which gives a basic tutorial on image segmentation (find coins on a uniform background) and color segmentation (red red or yellow objects). Plus I have about 130 other demos that I upload one at a time every now and then. Someday I'll group them all together into a gray bag of image processing demos and upload them.
Salaheddin Hosseinzadeh
2014-3-28
@ Image Analyst
Thanks for your help.
Series of demos would be awesome, I already checked your file exchange, those examples are beyond my basic level. I'll be waiting for the demos!
Thanks in advanec.
Image Analyst
2014-3-29
It means to just scale the image from min to max for display. I always do it, though you don't really need it for logical images or RGB images, only for grayscale images. Basically it shows the min gray level, whatever it is, as 0, and the max gray level, whatever it may be, as 255.
Sabanam
2014-3-29
One more thing i want to ask that i clearly understand how in hsv you have taken threshold in saturation but not getting how to take threshold in CIELab color model..you had explained how to convert to Lab and all but not getting in which channel i should take threshold..So please kindly send me function of Lab based segmentation for my image which i can directly put and analyse my code..because m not practically getting about Lab model for segmentation..Please reply as soon as possible...
Image Analyst
2014-3-29
编辑:Image Analyst
2014-3-29
Please fix your post so we can read it: http://www.mathworks.com/matlabcentral/answers/13205-tutorial-how-to-format-your-question-with-markup
Also, you read an image into the variable rgb, so it's a 3D uint8 image variable, but then you pass it to HSV_segment which expects a string (a filename) because you call imread again inside it. You can't call imread on a 3d uint8 numerical array, it needs a filename string.
Sabanam
2014-3-29
Sir,I have try ur HSV based segmentation for below green
image but its not as accurate as above images...Please tell me which thresold will be better for saturation including below and above images...
Image Analyst
2014-3-29
It worked pretty good for those. Just a few small noise particles that I got rid of using bwareaopen(). See attached script. Anyway, you accepted Sean's answer so I thought you were using that method instead.
Sabanam
2014-3-29
Sir...i didnt know which answer i should accept as i am new in this mathworks..So i just pressed it...I have implemented your's one using Lab and HSV as you have given idea but in HSV for above image it didnt work..so i ll just try it and acknowledge hows it giving results...
Vote of thanks to you sir....
Sabanam
2014-3-29
Shows the error in your last updated code...
Undefined function 'eml_assert_all_constant' for input arguments of type 'double'.
Image Analyst
2014-3-29
I just ran my code again and it worked fine. You must have changed it. You did not let me know the change you made. Please post your code (attach your m-file with paper clip icon) if you want me to find out how you broke the code.
Sabanam
2014-3-29
Actually i m running just your test file but dont know y its happening..
if true
% filepath='D:\mt-prc\Mango db\size_fuzzy\large\totapuri\1.jpg';
rgb=imread(filepath);
%%RGB to gray
J = rgb2gray(rgb);
%%Segmentation using HSV
BW=hsv2seg(rgb);
end
< <https://www.dropbox.com/s/b1wjca4nx5mrgo8/error1.JPG> >
Image Analyst
2014-3-29
What is "size_using_fuzzy"? That's not in my code. The vast majority of my code you commented out. Also, you did not attach 1.jpg.
Sabanam
2014-3-29
I just noticed that even m running your test.m file it shows above error...Don't y happening actually?
Image Analyst
2014-3-29
I ran test.m on it and it ran fine. No errors whatsoever. Here's a screenshot as proof.
Sabanam
2014-3-29
编辑:Sabanam
2014-3-29
Ya..but in my matlab it shows like
Undefined function 'eml_assert_all_constant' for input arguments of type 'double'.
I will fix the bug.Don't you show a proof..I think it may have internal toolbox error..So i ll tell if not short out this bug...Thank you for the help....It means a lot to giving a time for this session..
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
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!发生错误
由于页面发生更改,无法完成操作。请重新加载页面以查看其更新后的状态。
您也可以从以下列表中选择网站:
如何获得最佳网站性能
选择中国网站(中文或英文)以获得最佳网站性能。其他 MathWorks 国家/地区网站并未针对您所在位置的访问进行优化。
美洲
- América Latina (Español)
- Canada (English)
- United States (English)
欧洲
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom(English)
亚太
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)