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

Exclude Objects touching/overlapping ROI border #1651

Open
jksshack opened this issue Jan 16, 2025 · 2 comments
Open

Exclude Objects touching/overlapping ROI border #1651

jksshack opened this issue Jan 16, 2025 · 2 comments
Labels
new feature New feature ideas and solutions

Comments

@jksshack
Copy link

Is your feature request related to a problem? Please describe.
To the best of my knowledge currently the roi.filter only provides the option to either cut objects at the defined border of the roi or include objects that overlap the roi. There is no option to exclude objects that overlap the border of the roi.
In the images I am using, the roi borders are defined as the border of the image. Objects that touch the roi border are not fully in the image.

Describe the solution you'd like
An additional option for the roi_type that would exclude objects touching the roi border.

Describe alternatives you've considered

  • Shrinking the roi, works in some cases, but not all.

  • Taking the image at a greater height to include more objects of interest in the image, (so the roi can be significantly shrunk without sacrificing # of objects) - however the height at which I can take an image above the plants is a constraint.

-auto_grid, however the objects are not spaced consistently across images so roi_filter works much better than auto_grid

Additional context
Attached a photo
If there's a way to do this that I've missed or haven't thought of (I'm pretty new to plantcv, opencv, etc...), would really appreciate your insight! ty!!

Image

@jksshack jksshack added the new feature New feature ideas and solutions label Jan 16, 2025
@HaleySchuhl
Copy link
Contributor

Thanks @jksshack for opening this issue. This sounds like a helpful addition to ROI filtering options.

We do have a within_frame quality control type function that tests whether objects are touching the border, but doesn't currently have an option to remove them for downstream workflow steps such as auto_grid.

In the short term, I would approach filtering like this with reverse approach (using image data from the multi plant tutorial as an example):

# Detect objects at the top border
roi1 = pcv.roi.rectangle(img=img, x=0, y=0, h=300, w=img.shape[1])
removed_obs = pcv.roi.filter(mask=a_fill, roi=roi1, roi_type='partial')
# lower border
roi2 = pcv.roi.rectangle(img=img, x=0, y=(img.shape[0] - 500), h=500, w=img.shape[1])
removed_obs2 = pcv.roi.filter(mask=a_fill, roi=roi2, roi_type='partial')
# Combine mask of things to remove
removed = removed_obs + removed_obs2
# Filter from the plant mask 
filtered_mask = a_fill - removed
pcv.plot_image(filtered_mask)

all plants
Image

filtered plants

Image

@jksshack
Copy link
Author

Thank you, really appreciate your advice on how to deal with this!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
new feature New feature ideas and solutions
Projects
None yet
Development

No branches or pull requests

2 participants