Segment certain regions of a binary image

I have a binary image, which i would like to extract segments (labeled 1,2,3,4) from.
My previous approach to this was to sum the non-zero pixels on each line, and eventually get a plots with peaks. Using this plot, I determined the location of each peak using the built-in findpeaks function, along with their widths, in order to isolate these portions. This worked fairly well. However, using widths and location of the peaks does not give an accurate representation of the starting and ending points of the peaks.
I'm wondering if there is an alternative approach to this. Any suggestions would be appreciated.
Attached is a .mat file containing the binary data for this image.

6 Comments

It would not be too hard except for the region between 2 and 3. One could make the argument that 2 and 3 are just one big region instead of 2 separate regions. How "messy" can the region between regions become?
This example is one of the average looking images. Ideally the regions between regions are what you see between 1 & 2. This is a picture of a certain plant (don't ask), and the regions of interests are their leaves/number of locations with leaves. I know 2 and 3 are different regions simply because there are new "leaves" originating from these regions.
Thanks for your time!
Edit: Regarding the region between 2 and 3, the illustrated bottom boundaries are not hard boundaries, meaning that it is okay to be either above or below what I have illustrated, but never below the top boundary of the next region.
How many of these do you have to do? Thousands? Or just a few dozen? If it's just a few dozen, what's wrong with just using imrect() or rbbox() to manually outline the boxes?
@Image Analysis, I have over 60,000 of such images, hence the attempt at making an automatic framework. I am also expecting more images to come in the future, so putting time into this will definitely benefit me more in the long run compared to manually doing imrect() on such a large set.
Do you always know there will be straight segments in between the bushy ones? What if the whole plant looks like a bushy pine tree with no long "trunk-only" sections? Could that happen? Actually your section 3 and 4 don't have a straight run between them, and it's not straight after 4 either. How is some algorithm to know that segment 4 should not go all the way to the bottom? It looks like there are so many variations that you're going to have to have tons of special "rules" in any algorithm that can detect special cases/shapes.
@Image Analyst, Most times there should be a straight segment between them. It definitely may happen where it becomes bushy and the trunk becomes covered by these leaves. However, plants that look like that is only a small subset of the entire set, so if an algorithm fails there, it is fine with me.
As for segment 4, i am able to find the stop point by a simple row-wise pixel count. So if the number of pixels in that row exceed a threshold, I remove all the rows beneath it.
Plants are very tricky to work with as they tend to grow in many different shapes. I understand that having one robust algorithm that is able to work on thousands of different images is next to impossible due to the complexity of the way plants grow. I am just wondering if there is a way to work with these simpler looking images so that majority of the analysis can be done with a computer, while I can manually crop the ones that are too complex.

Sign in to comment.

Answers (1)

Asked:

on 10 Nov 2015

Commented:

on 18 Nov 2015

Community Treasure Hunt

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

Start Hunting!