How to extract 4 portions of main object of image with black background

1 view (last 30 days)
Hi,
I have an image with a black background. I would like to extract 4 portions of the main object of the image, a leaf (as I show in the image B.png). I would like to extract 4 portions as matrixes of 100 x 100 pixels. I thought one way to do that it would be to split the leaf in 4 quadrants and then extract 1 portion of each quadrant.
The problem is that I need to do it without considering that black background of the image. So, when extracting those portions of the image, I don't want to get those black pixels too, only parts that are inside the leaf. Is this possible?
I need those portions to do a texture analysis with a Local Binary Pattern code I've developed.
I've attached both images: the original (A.png) and and example of what I need (B.png).
I really appreciate your help. Thank you in advance!

Accepted Answer

Image Analyst
Image Analyst on 17 Nov 2015
Just extract the parts you want with indexing
rect1 = grayImage(row1:row1+99, col1:col1+99);
rect2 = grayImage(row1:row1+99, col2:col2+99);
rect3 = grayImage(row2:row2+99, col1:col1+99);
rect4 = grayImage(row2:row2+99, col2:col2+99);
Just define row1, row2, col1, and col2. Just put your leaf in the middle of the field of view. If, for some reason, you're sloppy at laying down the leaves, then you can find the centroid with regionprops() and then use imtranslate() to shift it to the middle where you can then use your predefined template rectangle locations like I showed you above.
  7 Comments
Image Analyst
Image Analyst on 23 Nov 2015
Well somehow you're going to need to decide whether a pixel is a leaf pixel or a background pixel. As you scan the image, you could perhaps use local binary pattern like you said first, though that would not be my choice (perhaps just because I'm not that familiar with it) but you can also look at local things like mean colors, standard deviations, etc. You've never yet said what your overall goal is. So sure, you can measure a bunch of parameters/characteristics/attributes at each pixel, or of the image as a whole, but then what? I'm sure you're not done then. What are your plans after that? Determine a "health index" of the leaf? Determine the species of tree it came from? What?
Queila Martins
Queila Martins on 1 Dec 2015
Sorry I didn't answer you before, I didn't know you had one more answer for me (found out it now). Well, In fact I already know what's the leaf's disease (all of my images are from the same kind of plant). My project objectives are: check the similarity between leafs and then, yes, determine how much "sick" a leaf is (I have a leaf group which has been classified according to a "health index"). There is a group in my country that checks this currently, but the process is totally manual, so it takes a lot of time. If I'm able to reduce the manual steps, I'm going to help them a lot. So, now (at least in my mind), I have to find out how to split a leaf in for quadrants (my teacher's suggestion), then get four parts from the image (one from each quadrant), put them togeter, extract LBP vectors for each "new" image and finally run a distance function (euclidean, for example) to check their similarity. After all those steps, I'm gonna try a new proposed re-ranking method to improve the rate of effectiveness of the similarity rank that was created. The last method I'll try aggregates several rankings to get the best one (those methods are part of a recent paper I've been reading). So, yes, I still have a lot to do. But I'm thankful, your files and answers have been helping me a lot.

Sign in to comment.

More Answers (0)

Categories

Find more on Agriculture in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!