-
Notifications
You must be signed in to change notification settings - Fork 265
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 #1616 from danforthcenter/1615-adding-houghcircles
- Loading branch information
Showing
12 changed files
with
263 additions
and
2 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
## Autodetect Cicular Regions of Interest (ROI) | ||
|
||
**plantcv.roi.auto_wells**(*gray_img, mindist, candec, accthresh, minradius, maxradius, nrows, ncols, radiusadjust=None*) | ||
|
||
**returns** roi_objects | ||
|
||
- **Parameters:** | ||
- gray_img = Gray single channel image data | ||
- mindist = minimum distance between detected circles | ||
- candec = higher threshold of canny edge detector | ||
- accthresh = accumulator threshold for the circl centers | ||
- minradius = minimum circle radius | ||
- maxradius = maximum circle radius | ||
- nrows = expected number of rows | ||
- ncols = expected number of columns | ||
- radiusadjust = amount to adjust the average radius, this can be desirable if you want ROI to sit inside a well, for example (in that case you might set it to a negative value). | ||
- **Context:** | ||
- Uses a Hough Circle detector to find circular shapes, then uses a gaussian mixture model to sort found circular objects so they are ordered from | ||
top left to bottom right. We assume that circles are of approximately equal size because we calculate an average radius of all of the found circles. | ||
The average radius size can be adjusted with the radius adjust parameter, for example in the case that you'd like the ROI to sit inside of the well. | ||
|
||
**Reference Image** | ||
|
||
![Screenshot](img/documentation_images/roi_auto_wells/circle-wells.png) | ||
|
||
```python | ||
|
||
from plantcv import plantcv as pcv | ||
|
||
# Set global debug behavior to None (default), "print" (to file), | ||
# or "plot" (Jupyter Notebooks or X11) | ||
pcv.params.debug = "plot" | ||
|
||
# Detect Circular Shapes and Use as ROIs | ||
rois1 = pcv.roi.auto_wells(gray_img=gray_img, mindist = 20, candec = 50, | ||
accthresh = 30, minradius = 40, maxradius = 50, nrows=4, ncols=6, radiusadjust=-10) | ||
|
||
``` | ||
|
||
**Grid of ROIs** | ||
|
||
![Screenshot](img/documentation_images/roi_auto_wells/21_roi.png) | ||
|
||
**Source Code:** [Here](https://github.com/danforthcenter/plantcv/blob/main/plantcv/plantcv/roi/roi_methods.py) |
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import cv2 | ||
import pytest | ||
from plantcv.plantcv._helpers import _hough_circle | ||
|
||
|
||
def test_hough_circle(test_data): | ||
"""Test for PlantCV.""" | ||
img = cv2.imread(test_data.hough_circle, -1) | ||
df, _ = _hough_circle(img, 20, 50, 30, 40, 50, 24) | ||
|
||
assert df.shape == (24, 3) | ||
|
||
|
||
def test_hough_circle_warn(test_data): | ||
"""Test for PlantCV.""" | ||
img = cv2.imread(test_data.hough_circle, -1) | ||
df, _ = _hough_circle(img, 20, 50, 30, 35, 50, 24) | ||
|
||
assert df.shape == (24, 3) | ||
|
||
|
||
def test_hough_circle_none(test_data): | ||
"""Test for PlantCV.""" | ||
img = cv2.imread(test_data.hough_circle, -1) | ||
df, _ = _hough_circle(img, 20, 50, 30, 40, 50, None) | ||
|
||
assert df.shape == (24, 3) | ||
|
||
|
||
def test_hough_no_circles(test_data): | ||
"""Test for PlantCV.""" | ||
# Read in test data | ||
img = cv2.imread(test_data.hough_circle, -1) | ||
with pytest.raises(RuntimeError): | ||
_, _ = _hough_circle(img, 20, 50, 30, 50, 50, None) |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.