Marker controlled watershed segmentation
15 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
I am trying to segment images with overlapping objects in Matlab.For that I am using watershed transform.The input image is
In this image I want to seperate the leaf from the small portion of weed.
This is the code I am using
if true
% code
end
I= imread('E:\cotton29.jpg');
Irgb = rgb2gray(I);
hy = fspecial('sobel');
hx = hy';
Iy = imfilter(double(Irgb), hy, 'replicate');
Ix = imfilter(double(Irgb), hx, 'replicate');
Igradmag = sqrt(Ix.^2 + Iy.^2);
figure
imshow(Igradmag,[]), title('Gradient magnitude (gradmag)')
Igrad = Igradmag;
% segmenting the image
[Ibinary]= segmentationbycolor(I);
%%foreground marker
se1 = strel('disk',50);
Ierode = imerode(Ibinary,se1);
figure();imshow(Ierode);
Ibwopen = bwareaopen(Ierode,150);
figure();imshow(Ibwopen);
Itemp = Irgb;
Itemp(Ibwopen)=255;
figure();imshow(Itemp);
%%background marker
D = bwdist(Ibinary);
DL = watershed(D);
bgm = DL == 0;
figure
imshow(bgm), title('Watershed ridge lines (bgm)')
%%impose minima
gradmag2 = imimposemin(Igrad, bgm | Ibwopen);
L = watershed(gradmag2);
%%visualize
I4 = Irgb;
I4(imdilate(L == 0, ones(3, 3)) | bgm | Ibwopen) = 255;
figure
imshow(I4)
The output is
My question is why am I not getting exact boundary?Is something wrong in the code? Does the gradient of image play an important role in this watershed segmentation? Sorry but I am not able to remove the initial if ,end in the code.
0 Commenti
Risposte (1)
Image Analyst
il 6 Feb 2017
Modificato: Image Analyst
il 7 Feb 2017
What is the "segmentationbycolor" function?
"My question is why am I not getting exact boundary?" <=== because your approach is wrong. The first mistake is to throw away the most valuable feature distinguishing the plants from the dirt, and that is the color. And then you did edge detection for some reason? Why did you do that?
I know all beginners, for some reason, think that edge detection is a necessary part of image analysis, but it is not. Often/usually it is not even needed at all. What you should do is color segmentation based on hue. I have demos for that in my File Exchange http://www.mathworks.com/matlabcentral/fileexchange/?term=authorid%3A31862, and here in the forum if you'll search for "leaf".
Once you separate the green from the brown you can work on distinguishing the very small weed from the larger leaf. However, if you find an algorithm that does it for this image, it will probably be specific to this image, and probably won't be robust enough to handle any number of leaves of one type with weed leaves of the other slightly different color. I think you need to rethink the entire aim of the project. For example if it's your goal to get an estimate of weeds in a crop on a farm, then you might be able to get a good estimate by finding the bare dirt rows between the plants and then investigating those rows only for the area fraction in them that is green. I think you're getting "lost in the weeds", so to speak, if you try to do it on a very small field of view like this.
2 Commenti
Image Analyst
il 7 Feb 2017
I did suggest other approaches.
Like I said,
- I've given code for leaf segmentation before in this forum if you search for it.
- Or you can make slight adaptations to my color segmentation demos in my File Exchanges.
- Lastly, you can use the Color Thresholder app on the Apps tab of the tool ribbon.
Vedere anche
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!