-
Notifications
You must be signed in to change notification settings - Fork 0
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
Add .correct_mask
method
#27
base: main
Are you sure you want to change the base?
Conversation
Here's the code health analysis summary for commits Analysis Summary
Code Coverage Report
|
check against overlap with any annotation rather than just considering pts auto detected somwhere vs kept coordinates after fixing annotations
minor context update to example use section
watershed can be used upstream to separate conjoined things
…ed mask is handled
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Everything seems to work as intended. I put the notebook I used for testing in the Google Drive folder. It seems like there's just a test coverage issue and one deep source issue to fix. Once the coverage is good to go, I can re-run the tests and approve though!
I'm not certain we will be able to decrease the complexity, which is the deepsource complaint. But coverage is fixed now @annacasto at least! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's one deep source issue about code complexity that we're not sure can be resolved, so approving for now since tests pass and it was reviewed for functionality.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added some suggestions to reduce complexity
plantcv/annotate/classes.py
Outdated
for names in labelnames: | ||
for (x, y) in self.coords[names]: | ||
x = int(x) | ||
y = int(y) | ||
# Draw pt annotations onto a blank mask | ||
pts_mask = cv2.circle(pts_mask, (x, y), radius=0, color=(255), thickness=-1) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Take a look at itertools
, particularly itertools.product
I think to reduce nested for loops to one loop. This also applies to dealing with complexity below.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the feedback! I have simplified this helper function.
I spent most of this morning testing different ways to loop through all annotation coordinates, but I'm struggling to find a way to avoid the nested for
loop within the actual correct_mask
method. The part that I'm not sure how to get around is that the algorithm currently relies on being aware of the corresponding class label called names
, but I believe it's possible. If you have more suggestions I'm happy to implement them, and I'm also amenable if you want to make changes directly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
itertools.product?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have removed the nested for loop with a different approach (edited) butitertools.product
is the first way I tried this, and I'm just not sure how to use it in such a way that keeps awareness of the key
part of the dictionary rather than just gathering all coordinates. Here's the closest I got today:
import itertools
# still a bad product
for instance in itertools.product(counter.coords.keys(), counter.coords.values()):
print(instance)
('default', [(398, 416), (1262, 338), (1701, 378), (1806, 1025), (1518, 1505), (556, 1430), (481, 997), (1090, 754)])
('default', [(321, 486), (308, 888), (333, 993), (321, 1193), (338, 1489)])
('default', [(1423, 529), (1721, 399), (1864, 229)])
('germinated', [(398, 416), (1262, 338), (1701, 378), (1806, 1025), (1518, 1505), (556, 1430), (481, 997), (1090, 754)])
('germinated', [(321, 486), (308, 888), (333, 993), (321, 1193), (338, 1489)])
('germinated', [(1423, 529), (1721, 399), (1864, 229)])
('other', [(398, 416), (1262, 338), (1701, 378), (1806, 1025), (1518, 1505), (556, 1430), (481, 997), (1090, 754)])
('other', [(321, 486), (308, 888), (333, 993), (321, 1193), (338, 1489)])
('other', [(1423, 529), (1721, 399), (1864, 229)])
I found that this sum
syntax I've added to _create_pts_mask
does a nice job of combining all annotations into a single list, but for the algorithm to utilize this format of data, we would also need to create a list of the same length that contains the class label corresponding to each value. (I'm currently doing this with a for
loop over all annotations and looking up the key
for each value
)
I'm just not certain that itertools.product
is the method that can create this based on the googling & testing I was doing today, but that could be my lack of familiarity with the package. So if somebody else wants to replace the logic then feel welcomed to directly commit those improvements.
Describe your changes
Rewrite the
clickcount_correct
method, used to add and remove to make acorrected_mask
, which makes a labeled mask containing all objects that are resolvable in the input binary mask, based on Point annotations. Outputs can be used for size analysis. Unresolved objects cannot be measured but can still keep info about count.No longer includes the
_recover_circ
part of the algorithm which was changing the shape of objects in some cases and was too specific to the size & shape of pollen.Type of update
Is this a:
Associated issues
Additional context
Add any other context about the problem here.
For the reviewer
See this page for instructions on how to review the pull request.
plantcv/mkdocs.yml
updating.md