How to extract 4 portions of main object of image with black background
1 view (last 30 days)
Show older comments
Queila Martins
on 17 Nov 2015
Commented: Queila Martins
on 1 Dec 2015
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!
0 Comments
Accepted Answer
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
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?
More Answers (0)
See Also
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!