![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/174676/image.png)
이 질문을 팔로우합니다.
- 팔로우하는 게시물 피드에서 업데이트를 확인할 수 있습니다.
- 정보 수신 기본 설정에 따라 이메일을 받을 수 있습니다.
Which threshold method will work for my image?
조회 수: 1 (최근 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*
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/174676/image.png)
댓글 수: 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:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/174675/image.jpeg)
댓글 수: 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
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/178285/image.jpeg)
image but its not as accurate as above images...Please tell me which thresold will be better for saturation including below and above images...
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/178286/image.jpeg)
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.
![](https://www.mathworks.com/matlabcentral/images/broken_image.png)
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
참고 항목
카테고리
Help Center 및 File 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!오류 발생
페이지가 변경되었기 때문에 동작을 완료할 수 없습니다. 업데이트된 상태를 보려면 페이지를 다시 불러오십시오.
웹사이트 선택
번역된 콘텐츠를 보고 지역별 이벤트와 혜택을 살펴보려면 웹사이트를 선택하십시오. 현재 계신 지역에 따라 다음 웹사이트를 권장합니다:
또한 다음 목록에서 웹사이트를 선택하실 수도 있습니다.
사이트 성능 최적화 방법
최고의 사이트 성능을 위해 중국 사이트(중국어 또는 영어)를 선택하십시오. 현재 계신 지역에서는 다른 국가의 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 (한국어)