I want to detect leaf shape by line tracing.

2 views (last 30 days)
Hi, I am trying to mask leaf shapes using Matlab.
I reached to the stage where I can detect the difference between leaf / non-leaf by pixel (as you can see in the figure),
but I can't find a way to mask the whole leaf area.
Yes - the masking isn't perfectly done - but this is the best masking I can do right now.
The concept I am thinking about is making a leaf figure by line tracing, and masking the whole pixel inside the lines.
I've tried several ways, but can't find a way to mask the leaf.
(if possible, I want to divide three leaves in seperate masking - but if not, adding a straight line between the leaves is also possible.)
openfig Q;
  2 Comments
Matt J
Matt J on 27 Feb 2025
Edited: Matt J on 27 Feb 2025
I don't really understand the difference between,
"detect the difference between leaf / non-leaf by pixel "
and
"mask the whole leaf area"
The very definition of a mask is an image that shows the difference between one region and another, which you clearly have created because that's what your figure shows.
Aside from that, it is not clear what help you are looking for. You have shown us no code or input data for us to recommend changes to.
Argon
Argon on 28 Feb 2025
@Matt J Thank you for your advice, I have uploaded additional content to make my question clear.

Sign in to comment.

Accepted Answer

Image Analyst
Image Analyst on 27 Feb 2025
Edited: Image Analyst on 27 Feb 2025
Do a search of this forum for the tag "leaf". There are lots of examples. Basically you can probably segment the code by color (green) and then fill the mask with imfill and then call bwboundaries. Use the Color Thresholder on the Apps tab of the tool ribbon.
Why do you want to do this? Did someone hire you to do this for some reason? Is it your homework? Some other reason?
Post your original image if you need more help, or at the very least attach your binary image (not the pseudocolored one like you did). We'd rather have a PNG image file than a fig file. Make it easy for us to help you, not hard.
To split the full leaf into parts, you might take a look at watershed, superpixels, or grabcut.
  5 Comments
Image Analyst
Image Analyst on 4 Mar 2025
I don't know what you're clicking. I just call it and tell it some parameter and it does it automatically, like
L = superpixels(rgbImage, 30);
imshow(L, []);
axis on image
Argon
Argon on 5 Mar 2025
I made an upgrade code using superpixels, and it seems it's quite working well, regarding its accuracy.
Thanks for your help! Your comments were useful on image analyzing.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!