How to segment this image correctly?

2 views (last 30 days)

Accepted Answer

Image Analyst
Image Analyst on 25 Dec 2016
See Steve's blog for how you can use watershed segmentation to separate the blobs: http://blogs.mathworks.com/steve/2013/11/19/watershed-transform-question-from-tech-support/
  4 Comments
smallmonster
smallmonster on 28 Dec 2016
I'm so sorry i didn't make myself clear. In fact i want to get 3 blocks from the first picture, and Steve's method is enough for me. Thank you for your help.
John BG
John BG on 7 Jan 2017
fine to me, you choose as accepted answer IA's, it's ok.
But it's worth mentioning that with dell2 you get 3 blocks and there is no contour deformation whatsoever.
Yet with IA suggested segmentation when each block too close each other the 'corridors' suffer deformation.
Your original image has a more or less diagonal alley between the first from left segment and the 2nd segment, kind of hand written, yet IA proposed segmentation returns a Z-like straight segments uniformly narrow alley which is clearly different from the original image.

Sign in to comment.

More Answers (2)

John BG
John BG on 25 Dec 2016
Edited: John BG on 27 Dec 2016
I tried watershed and label2rgb but didn't produce the desired result
1.
A=imread('im1.jpg');imshow(A)
BW=watershed(A)
Lrgb=label2rgb(BW);imshow(Lrgb)
2.
the Laplacian seems to get somewhere yet the contour is still a bit noisy
A1=double(A(:,:,1))
B=del2(A1);
figure(2);imshow(B)
3.
So I cleaned it with the following basic lines and the contour shows up
A1(A1<80)=0
A1(A1>120)=255
C=del2(A1);
figure(3);imshow(C)
and it also works for the fragmented image
A=imread('im2.jpg');figure(4);imshow(A)
A2=double(A(:,:,1))
A2(A2<80)=0
A2(A2>120)=255
C2=del2(A2);
figure(3);figure(5);imshow(C2)
if you find these lines useful would you please mark my answer as Accepted Answer?
To any other reader, if you find this answer of any help, please click on the thumbs-up vote link,
thanks in advance for time and attention
John BG
  5 Comments
Image Analyst
Image Analyst on 28 Dec 2016
Edited: Image Analyst on 28 Dec 2016
No of course I don't mind you asking John. Honestly I didn't try either your method or Steve Eddins method.
But with either method, the bad jpeg artifacts should be repaired so that you're starting with a pure binary image.
I saw a lot of clutter in your first two images that just didn't seem right and I think that if he had posted the pure binary images, you wouldn't have all that clutter and you might get different results. But with a binary image you wouldn't want to or need to do the Laplacian. If you just wanted to find the edges you can use bwperim() or bwboundaries(). Have you tried your method after the jpeg junk has been removed/repaired? Maybe you could attach your entire algorithm in one chunk/file so we can easily copy and paste it.
Again, smallmonster, never use JPEG format to save images that you want to do image analysis on. Use PNG instead.
smallmonster
smallmonster on 28 Dec 2016
Thank you for your advice. I must say i am a beginner at image processing and i won't do it again. Steve Eddins result is not as good as the 2nd picture i posted, but it's enough for me.
Thanks again.

Sign in to comment.


Walter Roberson
Walter Roberson on 25 Dec 2016
imerode until the number of regions is 3

Community Treasure Hunt

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

Start Hunting!