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

Interactive object count #754

Open
wants to merge 181 commits into
base: interactive-tools
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
181 commits
Select commit Hold shift + click to select a range
75aff20
Update transform_detect_color_card.md
HaleySchuhl Dec 1, 2023
bef9964
Update transform_affine_color_correction.md
HaleySchuhl Dec 1, 2023
ab3b01f
Update analyze_grayscale.md
HaleySchuhl Dec 1, 2023
e0a2ddb
Update get_color_matrix.md
HaleySchuhl Dec 1, 2023
39e8e9a
Update reassign_frame_labels.py
HaleySchuhl Dec 1, 2023
948979b
Update output_measurements.md
HaleySchuhl Dec 1, 2023
565f079
Update transform_detect_color_card.md
HaleySchuhl Dec 4, 2023
c476da5
Merge branch 'main' into updated_color_correction_tutorial
nfahlgren Jan 8, 2024
5bd2e14
Merge pull request #1415 from danforthcenter/updated_color_correction…
nfahlgren Jan 8, 2024
dd1b73d
Update PyPi deploy workflow to use OIDC authentication
nfahlgren Jan 16, 2024
72d85da
Merge pull request #1424 from danforthcenter/fix-pypi-deploy
nfahlgren Jan 16, 2024
fdc3c7f
watershed update
maliagehan Oct 2, 2023
6e5b008
add detect_discs function and update init
JorgeGtz Apr 13, 2021
3857e9a
add test for detect_discs
JorgeGtz Apr 13, 2021
e8c73ee
add get centroids function and update init
JorgeGtz Apr 14, 2021
e81c4ec
add testing for get_centroids
JorgeGtz Apr 14, 2021
a16ad17
Create click_count.py
DannieSheng Apr 23, 2021
a28bcbe
Update __init__.py
DannieSheng Apr 23, 2021
f5e4c15
Update tests.py
DannieSheng Apr 23, 2021
6354400
Create visualize_click_count.md
DannieSheng Apr 23, 2021
a1ea679
add documentation images
DannieSheng Apr 23, 2021
eb126f8
Update tests.py
DannieSheng Apr 26, 2021
b9a1c1d
Update click_count.py
DannieSheng Apr 27, 2021
993bf27
Update tests.py
DannieSheng Apr 27, 2021
91add2e
Update visualize_click_count.md
DannieSheng Apr 27, 2021
926bdb7
add documentation for detect discs
JorgeGtz Apr 28, 2021
abca7c3
add value of ecc_thresh x 10 to filename for debug print
JorgeGtz Apr 28, 2021
d764d8a
add documentation for get centroids
JorgeGtz Apr 28, 2021
d05a98f
switch mask type to uint8 (input in get centroids, output in detect d…
JorgeGtz Apr 28, 2021
0f0cc8f
output binary mask as 0-255 instead of 0-1
JorgeGtz Apr 28, 2021
6c0cc09
Update visualize_click_count.md
HaleySchuhl Sep 17, 2021
7d2a653
remove developing tag
HaleySchuhl Sep 17, 2021
7c77dea
Convert coord values to int
HaleySchuhl Sep 17, 2021
4782b59
Update detect_discs.py
HaleySchuhl Sep 17, 2021
c29f85f
remove accidental indent
HaleySchuhl Sep 17, 2021
2fbdd9e
revert back to integer conversion code
HaleySchuhl Sep 21, 2021
dbfe642
Create interactive_ClickCount_tutorial.md
HaleySchuhl Sep 21, 2021
f7ec1bf
add seed count tutorial
HaleySchuhl Sep 21, 2021
d1cebb9
update links to separate binder repos
HaleySchuhl Sep 21, 2021
8ee93c1
update links to new binder repo
HaleySchuhl Sep 21, 2021
1bd1509
Move tests to modules
nfahlgren May 2, 2023
c86cff5
Fix issues with number of findContour return vals
nfahlgren May 2, 2023
6635d7e
move detect_discs into annotate sub package
HaleySchuhl May 4, 2023
4e53a0d
move get_centroids too
HaleySchuhl May 4, 2023
b97de28
update annotates init file
HaleySchuhl May 4, 2023
5c48627
move test files into annotate dir
HaleySchuhl May 4, 2023
fd9f7fe
move test data import into annotate dir
HaleySchuhl May 4, 2023
d3a8e1f
remove test data from main package conftest
HaleySchuhl May 4, 2023
adf6caf
Update test_detect_discs.py
HaleySchuhl May 4, 2023
5794acc
Update test_get_centroids.py
HaleySchuhl May 4, 2023
63dec63
just trying to reorder something to resolve circular import
HaleySchuhl May 4, 2023
d0bd02f
Revert "just trying to reorder something to resolve circular import"
HaleySchuhl May 4, 2023
5fae057
change import order within detect_discs?
HaleySchuhl May 4, 2023
d4a1a2f
update import order within detect disks
HaleySchuhl May 4, 2023
6e4701f
move _find_closest_point into classes.py to get used directly
HaleySchuhl May 4, 2023
4f2a21e
Update test_detect_discs.py
HaleySchuhl May 4, 2023
aa22c51
also update to annotate_test_data in get_centroids
HaleySchuhl May 4, 2023
2978e44
update detect_discs.md to reflect moving into annotate
HaleySchuhl May 5, 2023
57c97ee
Update get_centroids.md
HaleySchuhl May 5, 2023
61593a8
add both new functions to updating.md
HaleySchuhl May 5, 2023
331cc4e
Update detect_discs.py
HaleySchuhl May 5, 2023
bc2bafa
Update get_centroids.py
HaleySchuhl May 5, 2023
da48833
Update detect_discs.py
HaleySchuhl May 5, 2023
e70fdc7
Update get_centroids.py
HaleySchuhl May 5, 2023
1f22468
Add end of file line return
nfahlgren May 5, 2023
df49c98
Add spacing between functions
nfahlgren May 5, 2023
b354b92
move ClickCount definition into classses.py
HaleySchuhl May 5, 2023
7d24e8e
Delete click_count.py
HaleySchuhl May 5, 2023
a0689eb
add ClickCount to main project init
HaleySchuhl May 5, 2023
a1da6eb
Create click_count.py
HaleySchuhl May 5, 2023
c8e574b
Update test_click_count.py
HaleySchuhl May 5, 2023
d68b105
Reorganize annotate methods
nfahlgren Sep 20, 2023
e1b9de1
Remove old test file that was reintroduced
nfahlgren Sep 20, 2023
47ed097
Replace print with warn
nfahlgren Sep 20, 2023
d873205
Add docstrings
nfahlgren Sep 20, 2023
0336ea4
No need to inherit from object
nfahlgren Sep 20, 2023
1f44dc3
Adjust docstring spacing
nfahlgren Sep 20, 2023
c5bd36a
Adjust docstring spacing
nfahlgren Sep 20, 2023
4b44576
Iterate over dictionary
nfahlgren Sep 20, 2023
66ce8e9
Rename and reorg docs files
nfahlgren Sep 20, 2023
ceab533
Rename docs
nfahlgren Sep 20, 2023
90866a7
Update annotate tools in TOC
nfahlgren Sep 20, 2023
7aa4ea1
Add links to ClickCount and Points docs
nfahlgren Sep 20, 2023
89725f1
Update get_centroid docs
nfahlgren Sep 20, 2023
7d4c102
Revise docs to add attributes and fix formatting
nfahlgren Sep 21, 2023
17569f6
Add debug code
nfahlgren Sep 21, 2023
af08ad7
Revise docs based on class formatting
nfahlgren Sep 21, 2023
3dfa2c1
Add device counter
nfahlgren Sep 21, 2023
821af89
Add device counter
nfahlgren Sep 21, 2023
1021e75
Reformat docstrings
nfahlgren Sep 21, 2023
5b7629b
Add module docstrings
nfahlgren Sep 21, 2023
2b7778f
Update changelog
nfahlgren Sep 21, 2023
0359c33
Fix source code URLs
nfahlgren Sep 21, 2023
7825e55
Fix mask to keep correct number of objects
nfahlgren Sep 26, 2023
7f13b46
added clickcount correct and label functions
maliagehan Oct 6, 2023
156ccbb
added tests for clickcount_labels and clickcount_correct
maliagehan Oct 9, 2023
5f7b94c
added documentation
maliagehan Oct 10, 2023
0621e7a
fixed tests to add coverage
maliagehan Oct 10, 2023
c8e8751
working on deepsource corrections
maliagehan Oct 10, 2023
01038b2
Update classes.py onclick in ClickCount to int
HaleySchuhl Oct 10, 2023
9fc8c83
deepsource corrections
maliagehan Oct 10, 2023
8c7ab9b
deepsource corrections
maliagehan Oct 10, 2023
ac2f90e
deepsource
maliagehan Oct 10, 2023
501adaf
clickcount file import
maliagehan Oct 11, 2023
e5755cc
deepsource corrections
maliagehan Oct 11, 2023
654ad4c
deepsource fix
maliagehan Oct 11, 2023
75d777c
removed dtype
maliagehan Oct 12, 2023
5c19fb1
add class output
maliagehan Oct 25, 2023
f2af74e
Update annotate_clickcount_correct.md
HaleySchuhl Nov 17, 2023
c4f8362
Update annotate_click_count.md
HaleySchuhl Nov 20, 2023
3cd47c4
Update annotate_clickcount_file_import.md
HaleySchuhl Nov 20, 2023
0227bde
Update annotate_clickcount_label.md
HaleySchuhl Nov 20, 2023
bf6ee4a
Update annotate_detect_discs.md
HaleySchuhl Nov 20, 2023
7bbc240
Update annotate_get_centroids.md
HaleySchuhl Nov 20, 2023
1d83ce4
Update tutorials.md
HaleySchuhl Nov 20, 2023
197421c
Update updating.md
HaleySchuhl Nov 20, 2023
6dc2ad3
Update classes.py
HaleySchuhl Nov 20, 2023
c31263f
Update classes.py
HaleySchuhl Nov 20, 2023
0c448fc
Update classes.py
HaleySchuhl Nov 20, 2023
15ab1cd
Update classes.py
HaleySchuhl Nov 20, 2023
c0b0b1b
Update clickcount_correct.py
HaleySchuhl Nov 20, 2023
1ae78fe
Update clickcount_file_import.py
HaleySchuhl Nov 20, 2023
c742fe4
Update clickcount_label.py
HaleySchuhl Nov 20, 2023
ac50397
Update detect_discs.py
HaleySchuhl Nov 20, 2023
9c7005c
Update get_centroids.py
HaleySchuhl Nov 20, 2023
3c36fbd
change return to be called "coords" in get_centroids
HaleySchuhl Nov 20, 2023
e90a984
detect_discs output "coords"
HaleySchuhl Nov 20, 2023
4669b47
clickcount_label param name update to label to match other analysis f…
HaleySchuhl Nov 20, 2023
1060da1
update param name to "filename" in clickcount_file_import
HaleySchuhl Nov 21, 2023
4546327
in clickcount correct change to coords
HaleySchuhl Nov 21, 2023
8d5252a
move clickcount_correct to .correct method in annotate/classes.py
HaleySchuhl Nov 21, 2023
5dd66a1
move file_import to method
HaleySchuhl Nov 21, 2023
99c90dd
move clickcount_label to method
HaleySchuhl Nov 21, 2023
416189b
Update test_clickcount_correct.py
HaleySchuhl Nov 21, 2023
1cba81b
Update test_clickcount_correct.py
HaleySchuhl Nov 21, 2023
2fb3b4b
Update test_clickcount_file_import.py
HaleySchuhl Nov 21, 2023
36785ce
Update test_clickcount_label.py
HaleySchuhl Nov 21, 2023
3c4d3c7
remove extra param from file_import method call in test
HaleySchuhl Nov 21, 2023
1ef3e0d
import syntax
HaleySchuhl Nov 21, 2023
a7dcb6d
typo ,
HaleySchuhl Nov 21, 2023
81057f2
Update __init__.py
HaleySchuhl Nov 21, 2023
8d38222
Update __init__.py
HaleySchuhl Nov 21, 2023
d40bb7d
Update classes.py
HaleySchuhl Nov 21, 2023
c32acfa
Update test_clickcount_label.py
HaleySchuhl Nov 21, 2023
141c328
Update classes.py
HaleySchuhl Nov 21, 2023
a3723c4
troubleshoot module error
HaleySchuhl Nov 21, 2023
e4418ec
Update updating.md
HaleySchuhl Nov 21, 2023
de22141
Update annotate_click_count.md
HaleySchuhl Nov 28, 2023
a68ba75
Update annotate_click_count.md
HaleySchuhl Nov 28, 2023
32d0b80
Update annotate_click_count.md
HaleySchuhl Nov 28, 2023
079be30
rename save_coords parameter to filename
HaleySchuhl Nov 28, 2023
4718b81
save_coords to filename in docs
HaleySchuhl Nov 28, 2023
c93c057
Update annotate_click_count.md
HaleySchuhl Nov 28, 2023
b99968c
Update annotate_click_count.md
HaleySchuhl Nov 29, 2023
d3c06d5
Update classes.py
HaleySchuhl Nov 29, 2023
d608c24
Update annotate_click_count.md
HaleySchuhl Nov 29, 2023
5b3c0ab
Update test_clickcount_correct.py
HaleySchuhl Nov 29, 2023
8289f0a
Update annotate_click_count.md
HaleySchuhl Nov 29, 2023
412d100
Update annotate_click_count.md
HaleySchuhl Nov 30, 2023
f0bd06b
add doc image and gif
HaleySchuhl Nov 30, 2023
7c90380
remove doc pages that got combined into methods
HaleySchuhl Nov 30, 2023
af38213
Update annotate_click_count.md
HaleySchuhl Nov 30, 2023
380f1ee
Update Figure-4.png
HaleySchuhl Nov 30, 2023
c9d2b6a
Update annotate_click_count.md
HaleySchuhl Nov 30, 2023
84e8b82
Update annotate_click_count.md
HaleySchuhl Nov 30, 2023
b437a1e
add some temp comments
HaleySchuhl Dec 1, 2023
6bf9cf4
Create temp_file.py
HaleySchuhl Dec 13, 2023
56db517
Update temp_file.py
HaleySchuhl Dec 13, 2023
64848ab
Update temp_file.py
HaleySchuhl Jan 4, 2024
ae80341
move detect_discs filter into main plantcv function space
HaleySchuhl Jan 11, 2024
be9a4a7
update init files in both places
HaleySchuhl Jan 11, 2024
59fde85
Update annotate_detect_discs.md
HaleySchuhl Jan 11, 2024
672169f
rename doc page
HaleySchuhl Jan 11, 2024
49e5697
move and update test for detect_discs
HaleySchuhl Jan 11, 2024
7fa65ed
rename and update ref imgs in doc page for detect_discs
HaleySchuhl Jan 11, 2024
aa0bcbd
Update detect_discs.py
HaleySchuhl Jan 11, 2024
94302f7
Update updating.md
HaleySchuhl Jan 11, 2024
ca8f498
update input image in detect_discs unit test
HaleySchuhl Jan 11, 2024
6618607
Update __init__.py
HaleySchuhl Jan 11, 2024
e5cb828
Update test_detect_discs.py
HaleySchuhl Jan 11, 2024
9137049
Update get_centroids.py
HaleySchuhl Jan 18, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions .github/workflows/publish-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,11 @@ jobs:
deploy:
needs: build
runs-on: ubuntu-latest

environment:
name: pypi
url: https://pypi.org/p/plantcv
permissions:
id-token: write
steps:
- uses: actions/checkout@main
with:
Expand All @@ -46,10 +50,8 @@ jobs:
run: |
python -m pip install --upgrade pip
pip install setuptools wheel twine
- name: Build and publish
env:
TWINE_USERNAME: ${{ secrets.PYPI_USERNAME }}
TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }}
- name: Build
run: |
python setup.py sdist bdist_wheel
twine upload dist/*
- name: Publish to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
2 changes: 1 addition & 1 deletion docs/analyze_grayscale.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ the values out to the [Outputs class](outputs.md). Can also return/plot/print ou
- **Example use:**
* [Grayscale Image Tutorial](tutorials/grayscale_tutorial.md)

- **Output data stored:** Data ('gray_frequencies', 'gray_mean', 'gray_median', 'nir_stdev') automatically gets stored to
- **Output data stored:** Data ('gray_frequencies', 'gray_mean', 'gray_median', 'gray_stdev') automatically gets stored to
the [`Outputs` class](outputs.md) when this function is ran. These data can always get accessed during a workflow (example
below). For more detail about data output see [Summary of Output Observations](output_measurements.md#summary-of-output-observations)

Expand Down
208 changes: 208 additions & 0 deletions docs/annotate_click_count.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,208 @@
## Click and count objects

`ClickCount` is a class that allows users to interactively count objects and other annotation tasks.

*class* **plantcv.annotate.ClickCount**(*img*, *figsize*=(12, 6))

- img - Image data
- figsize - Interactive plot figure size (default = (12,6))

### Attributes
**img**: input image.

**points**: a dictionary of coordinates for every class.
HaleySchuhl marked this conversation as resolved.
Show resolved Hide resolved

**colors**: a dictionary of colors for every class.

**counts**: a dictionary of count for every class.

**figsize**: figure size.

**events**: a list of events.

**label**: current label.

**color**: current color.

**view_all**: a flag indicating whether or not view all labels.

**fig**: matplotlib figure.

**ax**: matplotlib axis.

**p_not_current**: a list of matplotlib patches that are not current label.

---
### Methods
---
**view(*label*="total", *color*="c", *view_all*=False)**

View marked image, and update markers/annotations if needed.

- Parameters:
- label - class label to show on the marked image. By default `label="total`.
- color - desired color to show the class. By default `color="c"`.
- view_all - a flag indicating whether to show markers for all classes or not.
---
**import_coords(*coords*, *label*="total")**

Import coordinates from a list of coordinates.

- Parameters:
- coords - a list of available coordintes.
- label - class label for imported coordinates. By default `label="total`.
---
**file_import**(*filename*)

Import coordinates from file to a ClickCount object instance

- **Parameters:**
- filename - path to a coordinates file
- **Context:**
- Loads coordinates from a file (probably created with the `.save_coords` method) to ClickCount object instance
---
**save_coords(*filename*)**

Save the collected coordinates to a JSON file.

- Parameters:
- filename - (json) file name to save the coordinates of collected points.
---
**correct**(*bin_img*, *bin_img_recover*, *coords*)

Make corrections to annotations

**returns** recovered image

- **Parameters:**
- bin_img - binary image, image with selected objects (e.g. mask output of [`pcv.annotate.detect_discs`](annotate_detect_discs.md))
- bin_img_recover - binary image, image with all potential objects (binary image to recover objects from)
- coords - list of coordinates of 'auto' detected points (e.g. coordinate output of `pcv.annotate.detect_discs`)
- **Context:**
- Make corrections to the number of objects in a binary image with information from the ClickCount class object instance (both remove and recover objects). Also corrects the ClickCount object instance with coordinates at the center of each object (rather than click location).
---
**create_labels**(*gray_img*, *label='default'*)

Label ClickCount Objects after they have been segmented

**returns** labeled object image, labeled class image, ordered list of names, number of objects

- **Parameters:**
- gray_img - gray image with objects uniquely labeled (e.g. output of [pcv.watershed_segmentation](watershed.md))
- label - option to put in list of labels, defaults to 'default' if not included
- **Context:**
- Labels each object with a class ID (e.g. germinated, and/or total) that matches classes from ClickCount, returns a list of names for input into analyze steps, renumbers objects to equal the total number of objects, and stores coordinates to `Outputs`.
- **Output data stored:** Data ('count') for each ClickCount category automatically gets stored to the [`Outputs` class](outputs.md) when this function is
run. These data can be accessed during a workflow (example below). For more detail about data output see
[Summary of Output Observations](output_measurements.md#summary-of-output-observations)
---
### Pollen Annotation Example
- **Note**: used in Jupyter notebook.
```python
# Include the line of code below to allow interactive activities
%matplotlib widget

# Import packages
from plantcv import plantcv as pcv
import os

# Define workflow inputs
args = WorkflowInputs(images=["rgb_pollen_image.jpg",
names="image1",
result="imgID_results.json",
outdir=".",
writeimg=True,
debug="plot")
# Set global debug behavior to "plot" (Jupyter Notebooks or X11)
pcv.params.debug = args.debug

# Read image
img, path, fname = pcv.readimage(filename=args.image1)
```
**Original RGB image**

![Screenshot](img/documentation_images/annotate_clickcount_label/crop_pollen.png)

```python
# Segmentation, this might include many clean up functions
gray = pcv.rgb2gray_lab(img, channel='l')
mask = pcv.threshold.mean(gray_img=gray, ksize=201, offset=20, object_type='dark')

# Discard objects that are not circular
discs, coords = pcv.annotate.detect_discs(img_l_post, ecc_thresh=0.5)
```

**Detect Disc mask output**

![Screenshot](img/documentation_images/annotate_clickcount_correct/pollen_detectdisc_mask.png)

```python
# ClickCount Initialization
counter = pcv.annotate.ClickCount(img)

# Click on the plotted image to annotate
counter.view(label="total", color="r", view_all=False)
```
**View and Update ClickCount Coordinates**

![screen-gif](img/documentation_images/annotate_click_count/clickcount_view.gif)

```python
# Save out ClickCount coordinates file
counter.save_coords(os.path.join(args.outdir, str(args.result) + '.coords'))

# OPTIONALLY, import coordinates to ClickCount object
# (e.g. pick up where you left off)
file = os.path.join(args.outdir, str(args.result) + ".coords")
counter.file_import(img=img, filename=file)
# View "total" class
counter.view(label="total", color="r", view_all=False)

print(f"There are {counter.count['total']} selected objects")

# Launch interactive tool to select objects with a different class
counter.view(label="germinated", color="b", view_all=False)

print(f"There are {counter.count['germinated']} selected objects")

# Associate a unique label to each grain for segmentation,
# recover the missing grains, and create a complete mask
completed_mask = counter.correct(bin_img=discs, bin_img_recover=mask, coords=coords)
```

**Recovered (after `.correct`) Objects Image**

![Screenshot](img/documentation_images/annotate_clickcount_correct/Figure-4.png)

```python
# Watershed egmentation to separate touching grains
seg = pcv.watershed_segmentation(rgb_img=img, mask=completed_mask, distance=1)
```

**Output of Watershed Segementation**

![Screenshot](img/documentation_images/annotate_clickcount_label/Figure6.png)

```python
# Assign a single label to each grain & store to outputs
class_label, class_count_dict, class_list, num = counter.create_labels(gray_img=seg, label="total")
```
**Labeled Objects Image**

![Screenshot](img/documentation_images/annotate_clickcount_label/Figure7.png)
![Screenshot](img/documentation_images/annotate_clickcount_label/Figure8.png)

```python
# Optional, run additional trait analysis
shape_img = pcv.analyze.size(img=img, labeled_mask=class_label, n_labels=num, label=class_list)

# Save the results with "long" format. If using analyze.color this might get too long.
pcv.outputs.save_results(filename=os.path.join(args.outdir, args.result + ".csv"), outformat="csv")
pcv.outputs.clear()
```

**Size Analysis debug image**

![Screenshot](img/documentation_images/annotate_click_count/pollen_shape_annotations.png)

**Source Code:** [Here](https://github.com/danforthcenter/plantcv/blob/main/plantcv/plantcv/annotate/classes.py)
46 changes: 46 additions & 0 deletions docs/annotate_get_centroids.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
## Get centroids

Get the coordinates (row, column) of the centroid of each connected region
in a binary image.

**plantcv.annotate.get_centroids**(*bin_img*)

**returns** list containing coordinates of centroids

- **Parameters:**
- bin_img - Binary image containing the connected regions to consider
- **Context:**
- Given an arbitrary mask of the objects of interest, `get_centroids`
returns a list of coordinates that can the be imported into the annotation classes
[ClickCount](annotate_click_count.md) and [Points](annotate_points.md).

- **Example use:**
- Below

**Binary image**

![count_img](img/documentation_images/annotate_detect_discs/discs_mask_scaled.png)

```python

from plantcv import plantcv as pcv

# Set global debug behavior to None (default), "print" (to file),
# or "plot"
pcv.params.debug = "plot"

# Apply get centroids to the binary image
coords = pcv.annotate.get_centroids(bin_img=binary_img)
print(coords)
# [[1902, 600], [1839, 1363], [1837, 383], [1669, 1977], [1631, 1889], [1590, 1372], [1550, 1525],
# [1538, 1633], [1522, 1131], [1494, 2396], [1482, 1917], [1446, 1808], [1425, 726], [1418, 2392],
# [1389, 198], [1358, 1712], [1288, 522], [1289, 406], [1279, 368], [1262, 1376], [1244, 1795],
# [1224, 1327], [1201, 624], [1181, 725], [1062, 85], [999, 840], [885, 399], [740, 324], [728, 224],
# [697, 860], [660, 650], [638, 2390], [622, 1565], [577, 497], [572, 2179], [550, 2230], [547, 1826],
# [537, 892], [538, 481], [524, 2144], [521, 2336], [497, 201], [385, 1141], [342, 683], [342, 102],
# [332, 1700], [295, 646], [271, 60], [269, 1626], [210, 1694], [189, 878], [178, 1570], [171, 2307],
# [61, 286], [28, 2342]]

```

**Source Code:** [Here](https://github.com/danforthcenter/plantcv/blob/main/plantcv/plantcv/annotate/get_centroids.py)
35 changes: 25 additions & 10 deletions docs/Points.md → docs/annotate_points.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,27 @@
## 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
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)*)
*class* **plantcv.annotate.Points**(*img, figsize=(12, 6)*)

**returns** interactive image class
- img - Image data
- figsize - Interactive plot figure size (default = (12,6))

- **Parameters:**
- img - Image data
- figsize - Interactive plot figure size (default = (12,6))
### Attributes
**points**: a dictionary of coordinates for every class.

- **Attributes:**
- points - Coordinates (x,y) of the collected points as a list of tuples
**fig**: matplotlib figure.

**ax**: matplotlib axis.

**events**: a list of events.

### Methods
**onclick(*event*)**

Handles mouse click events.

- **Context:**
- Used to define a list of coordinates of interest.
Expand All @@ -23,10 +32,16 @@ closest collected point.


```python
%matplotlib widget

from plantcv import plantcv as pcv

# Set global debug behavior to None (default), "print" (to file),
# or "plot"
pcv.params.debug = "plot"

# Create an instance of the Points class
marker = pcv.Points(img=img, figsize=(12,6))
marker = pcv.annotate.Points(img=img, figsize=(12,6))

# Click on the plotted image to collect coordinates

Expand All @@ -44,4 +59,4 @@ roi1 = pcv.roi.custom(img=img, vertices=marker.points)
![Screenshot](img/documentation_images/annotate_Points/custom_roi.jpg)


**Source Code:** [Here](https://github.com/danforthcenter/plantcv/blob/master/plantcv/plantcv/classes.py)
**Source Code:** [Here](https://github.com/danforthcenter/plantcv/blob/main/plantcv/plantcv/annotate/classes.py)
Loading
Loading