-
Notifications
You must be signed in to change notification settings - Fork 266
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #816 from danforthcenter/interactive_roi
Annotation sub-package and point annotation tool (a.k.a. interactive CustomROI)
- Loading branch information
Showing
10 changed files
with
195 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
## Interactive Point Annotation Tool | ||
|
||
Using [Jupyter Notebooks](jupyter.md) it is possible to interactively click to collect coordinates from an image, which can be used in various downstream applications. Left click on the image to collect a point. Right click removes the | ||
closest collected point. | ||
|
||
**plantcv.Points**(*img, figsize=(12, 6)*) | ||
|
||
**returns** interactive image class | ||
|
||
- **Parameters:** | ||
- img - Image data | ||
- figsize - Interactive plot figure size (default = (12,6)) | ||
|
||
- **Attributes:** | ||
- points - Coordinates (x,y) of the collected points as a list of tuples | ||
|
||
- **Context:** | ||
- Used to define a list of coordinates of interest. | ||
- For example the [`pcv.roi.custom`](roi_custom.md) function defines a polygon Region of Interest based on a list of vertices, which can be labor intensive to define but is streamlined with the ability to click for point collection. | ||
- The list of vertices output has also shown to be helpful while using [pcv.roi.multi](roi_multi.md) in cases where centers are defined with a custom list of vertices. | ||
- **Example use:** | ||
- Below | ||
|
||
|
||
```python | ||
from plantcv import plantcv as pcv | ||
|
||
# Create an instance of the Points class | ||
marker = pcv.Points(img=img, figsize=(12,6)) | ||
|
||
# Click on the plotted image to collect coordinates | ||
|
||
# Use the identified coordinates to create a custom polygon ROI | ||
roi_contour, roi_hierarchy = pcv.roi.custom(img=img, vertices=marker.points) | ||
|
||
``` | ||
|
||
**Selecting Coordinates** | ||
|
||
![screen-gif](img/documentation_images/annotate_Points/custom_roi.gif) | ||
|
||
**Resulting ROI** | ||
|
||
![Screenshot](img/documentation_images/annotate_Points/custom_roi.jpg) | ||
|
||
|
||
**Source Code:** [Here](https://github.com/danforthcenter/plantcv/blob/master/plantcv/plantcv/classes.py) |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# Point/vertice annotation tool(s) | ||
|
||
import numpy as np | ||
from scipy.spatial import distance | ||
|
||
## INTERACTIVE ROI TOOLS ## | ||
|
||
|
||
def _find_closest_pt(pt, pts): | ||
""" Given coordinates of a point and a list of coordinates of a bunch of points, find the point that has the | ||
smallest Euclidean to the given point | ||
:param pt: (tuple) coordinates of a point | ||
:param pts: (a list of tuples) coordinates of a list of points | ||
:return: index of the closest point and the coordinates of that point | ||
""" | ||
if pt in pts: | ||
idx = pts.index(pt) | ||
return idx, pt | ||
|
||
dists = distance.cdist([pt], pts, 'euclidean') | ||
idx = np.argmin(dists) | ||
return idx, pts[idx] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters