Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Option to return masks of segemented leaves #10

Open
LittleAri opened this issue Jun 25, 2024 · 2 comments
Open

Option to return masks of segemented leaves #10

LittleAri opened this issue Jun 25, 2024 · 2 comments
Assignees

Comments

@LittleAri
Copy link

Hi! I am currently using LeafMachine to segment leaves on Herbarium sheets. I know I can see this in the resulting plots, and the bounding boxes in the output are helpful too, but I think it will be very useful to have the outlines of masks resulting from the segmentation step. I am currently extracting this information by saving Project.project_data_list as a numpy file, within "machine" in machine.py, for each image, and extracting the leaf outlines from the dictionary there, as a post-processing step. Was hoping to know a neater way of doing this! Thank you!

@Gene-Weaver
Copy link
Owner

Hello! You are correct, the current version is very messy. I have an update that I have not pushed yet that exports all of the leaf masks as a very simple txt file. The new method uses a new key point detection algorithm to orient the leaves vertically (lamina tip at the top, lamina base at the bottom) and then saves the oriented points like this:
BR_1839844133_Erythropalaceae_Heisteria_parvifolia__L__1139-6-1676-1349.txt
Line 1: the angle the contour was rotated from the original orientation

Based on location in the mask:
Line 2: top-most point, not guaranteed to be the lamina tip for an emarginate leaf apex, but would be the true tip for most leaf apex types
Line 3: bottom-most point, not guaranteed to be the lamina base

Based on ML predicted location:
Line 4: closest contour point to the predicted tip, may not be the true tip
Line 5: closest contour point to the predicted base, may not be the true base

Line 6: beginning of the contour starting at the top-most point, all subsequent points are ordered clockwise based on Line 2, but you can write a script to reorder based on Line 4 if you want.

I would use the Line 2 point to be the tip, and Line 5 point to be the base. Line 5 will be more robust to strange lamina base shapes. Line 2 will give the most consistent 'tip' value (unless the leaf has an inverted tip)

Below are visualizations, the code should be pushed this week if all goes well.

BR_1839844133_Erythropalaceae_Heisteria_parvifolia__L__1139-6-1676-1349

BR_1839844133_Erythropalaceae_Heisteria_parvifolia__L__1139-6-1676-1349

@Gene-Weaver Gene-Weaver self-assigned this Jun 25, 2024
@LittleAri
Copy link
Author

That's fantastic! And those closest contours would be highly useful! And the text file format in the example is perfect! Right now I've been extracting the coordiantes from ['polygon_closed'] from ['Segmentation_Whole{/Partial}_Leaf'] from the Project file. As these have been normalised to start from the origin, I approximately reparameterize the coordinates so I can visualise them again on the herbarium sheet using the bounding boxes in that same Project file dictionary.

image
In this example I've found the outlines from the Project.project_data_list dictionary and plotted them with a thin line. I've also plotted the bounding boxes. For one leaf I've then translated the contours using the bounding box information - and this can be seen with a thicker red line.

Thanks for the heads up! Will certainly keep an eye out for the next update!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants