Skip to content

Commit

Permalink
Merge branch 'main' into 30-napari-draw-mask
Browse files Browse the repository at this point in the history
  • Loading branch information
HaleySchuhl authored Sep 12, 2024
2 parents fcf5bb5 + 888e3db commit 52472d4
Show file tree
Hide file tree
Showing 28 changed files with 1,206 additions and 55 deletions.
4 changes: 4 additions & 0 deletions .coveragerc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[run]
omit =
config.py
config-3.py
2 changes: 1 addition & 1 deletion .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,6 @@ See [this page](https://plantcv.readthedocs.io/en/latest/pr_review_process/) for
- [ ] Test coverage remains 100%
- [ ] Documentation tested
- [ ] New documentation pages added to `plantcv/mkdocs.yml`
- [ ] Changes to function input/output signatures added to `updating.md`
- [ ] Changes to function input/output signatures added to `changelog.md`
- [ ] Code reviewed
- [ ] PR approved
8 changes: 4 additions & 4 deletions .github/workflows/continuous-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
runs-on: ${{ matrix.os }}
strategy:
matrix:
python-version: ['3.8', '3.9', '3.10']
python-version: ['3.9', '3.10', '3.11']
os: [ubuntu-latest]
env:
OS: ${{ matrix.os }}
Expand All @@ -30,8 +30,7 @@ jobs:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
sudo apt-get update
sudo apt-get install --no-install-recommends libyaml-dev libegl1-mesa libxkbcommon-x11-0 libxcb-icccm4 libxcb-image0 libxcb-keysyms1 libxcb-randr0 libxcb-render-util0 libxcb-xinerama0 libxcb-shape0 libxcb-cursor0 xserver-xephyr xvfb
sudo apt-get install --no-install-recommends libyaml-dev libegl1-mesa libxkbcommon-x11-0 libxcb-icccm4 libxcb-image0 libxcb-keysyms1 libxcb-randr0 libxcb-render-util0 libxcb-xinerama0 libxcb-shape0 libxcb-cursor0 xserver-xephyr
python -m pip install --upgrade pip
pip install flake8 pytest pytest-cov pytest-qt pytest-xvfb ipython anyio
- name: Lint with flake8
Expand All @@ -48,8 +47,9 @@ jobs:
pip uninstall -y opencv-python
pip install opencv-python-headless
- name: Tests
uses: aganders3/headless-gui@v2
uses: aganders3/headless-gui@v2.2
with:
xvfb-screen-size: 1280x720x24
run: pytest --cov-report=xml --cov=./
- name: Upload coverage to Deepsource
uses: deepsourcelabs/test-coverage-action@master
Expand Down
373 changes: 373 additions & 0 deletions LICENSE

Large diffs are not rendered by default.

32 changes: 32 additions & 0 deletions docs/changelog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,35 @@
## Changelog

All notable changes to this project will be documented below.

#### annotate.get_centroids

* v0.1dev: coords_list = **annotate.get_centroids**(*bin_img*)

#### annotate.napari_classes

* v0.1dev: class_list = **annotate.napari_classes**(*viewer*)

#### annotate.napari_join_labels

* v0.1dev: relabeled_mask, mask_dict = **annotate.napari_join_labels**(*img, viewer*)

#### annotate.napari_label_classes

* v0.1dev: viewer = **annotate.napari_label_classes**(*img, classes, size=10, shape='square', importdata=False, show=True*)

#### annotate.napari_open

* v0.1dev: viewer = **annotate.napari_open**(*img, mode = 'native', show=True*)

#### annotate.napari_read_coor

* v0.1dev: data = **annotate.napari_read_coor**(*coor, dataformat='yx'*)

#### annotate.napari_save_coor

* v0.1dev: datadict = **annotate.napari_save_coor**(*viewer, filepath*)

#### annotate.Points

* v0.1dev: viewer = **annotate.Points**(*img, figsize=(12,6), label="dafault"*)
44 changes: 44 additions & 0 deletions docs/get_centroids.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
## Get Centroids

Extract the centroid coordinate (column,row) from regions 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 class [Points](Points.md).

- **Example use:**
- Below

**Binary image**

![count_img](img/documentation_images/get_centroids/discs_mask.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-annotate/blob/main/plantcv/annotate/get_centroids.py)
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions docs/napari_join_labels.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ img, path, name = pcv.readimage("./grayimg.png")

viewer = pcvan.napari_label_classes(img=img, ['background', 'wing','seed'])

labeledmask, mask_dict = pcvan.napari_join_lables(img=img, viewer)

# Should open interactive napari viewer

labeledmask, mask_dict = pcvan.napari_join_lables(img=img, viewer=viewer)

```

![Screenshot](img/documentation_images/napari_label_classes/napari_label_classes.png)
Expand Down
22 changes: 12 additions & 10 deletions docs/napari_label_classes.md
Original file line number Diff line number Diff line change
@@ -1,24 +1,27 @@
## Label Image with Napari

This function opens an image in Napari and then defines a set of classes to label. A random shape label is assigned to each class.
Image can be annotate as long as viewer is open.
This function opens an image in Napari and then defines a set of Points layers with the user-defined labels called `classes`. A random `shape` of the annotation symbol is assigned to each of the `classes`.
Image can be annotated as long as viewer is open.

**plantcv.annotate.napari_label_classes*(*img, classes, size=10, importdata=False, show=True*)

**plantcv.annotate.napari_label_classes*(*img, classes, size=10, shape='square', importdata=False, show=True*)

**returns** napari viewer object

- **Parameters:**
- img - image data (compatible with gray, RGB, and hyperspectral data. If data is hyperspecral it should be the array e.g. hyperspectral.array_data)
- classes - list of classes to label. This option is not necessary if data is data is imported.
- size - integer pixel size of label, best if even number
- size - integer pixel size of label (also adjustable from the interactive Napari viewer)
- shape - shape of the annotation symbol. Can be 'o', 'arrow', 'clobber', 'cross', 'diamond', 'disc', 'hbar', 'ring', 'square' (default), 'star', 'tailed_arrow',
'triangle_down', 'triangle_up', 'vbar', or 'x' (also adjustable from the interactive Napari viewer)
- importdata - dictionary of data, data saved from napari_save_coor or data imported from napari_read_coor
- show - if show = True, viewer is launched. False setting is useful for test purposes.
- show - if `show=True`, viewer is launched. `False` setting is useful for test purposes.

- **Context:**
- Adding class labels to images. Works best on an image that has objects segmented/classified with contours/clusters labeled with values (e.g. labeled mask, output of kmeans clustering).
- Adding one or more classes of points layer for annotation of the image.

- **Example use:**
- Labeling output of kmeans clustering into classes. Labeling points.
- Ground truth counting, labeling classes of objects of interest.


```python
Expand All @@ -29,9 +32,8 @@ import napari
# Create an instance of the Points class
img, path, name = pcv.readimage("./grayimg.png")

viewer = pcvan.napari_label_classes(img=img, classes=['background', 'wing','seed'], size = 30)

# Should open interactive napari viewer
# Opens interactive napari viewer
viewer = pcvan.napari_label_classes(img=img, classes=['background', 'wing','seed'], size=30)

```

Expand Down
9 changes: 5 additions & 4 deletions docs/napari_open.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
## Open Image with Napari

Open image data (e.g. RGB, gray, hyperspectral) with an interactive Napari viewer. If a gray image is opened, the image will be pseudocolored for better visualization.
Open image data (e.g. RGB, gray, hyperspectral) with an interactive Napari viewer. Labeled masks may be colorized for better visualization.

**plantcv.annotate.napari_open**(*img, show=True*)
**plantcv.annotate.napari_open**(*img, mode='native', show=True*)

**returns** napari viewer object

- **Parameters:**
- img - image data (compatible with gray, RGB, and hyperspectral data. If data is hyperspecral it should be the array e.g. hyperspectral.array_data)
- img - image data (compatible with gray, RGB, and hyperspectral data. If data is hyperspecral it should be the array e.g. `hyperspectral.array_data`)
- mode - 'native' or 'colorize'. If 'colorized' is selected gray images will be colorized.
- show - if show = True, viewer is launched. False setting is useful for test purposes.

- **Context:**
Expand All @@ -24,7 +25,7 @@ import plantcv.annotate as pcvan
# Create an instance of the Points class
img, path, name = pcv.readimage("./grayimg.png")

viewer = pcvan.napari_open(img=img)
viewer = pcvan.napari_open(img=img, mode='colorize')

# Should open interactive napari viewer

Expand Down
6 changes: 3 additions & 3 deletions docs/napari_read_coor.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ Save Points Labeled in Napari to a File
**returns** dictionary of points labeled by class

- **Parameters:**
- coor - dictionary object of coordinates or a path to json datafile with dictionary of point coordinates
- coor - dictionary object of coordinates, or a path to json datafile with dictionary of point coordinates
- dataformat - either 'yx' or 'xy', Napari takes data as y,x format. If data is 'xy' data is converted from x,y to y,x

- **Context:**
- Import data from a file and convert to Napari format data if necessary
- Import previously labeled points, or points from other functions (e.g. [`pcvan.napari_read_coor`](napari_read_coor.md))

- **Example use:**
- Import previously labeled points, or points from other functions (e.g. detect_centroid)
- Below


```python
Expand Down
6 changes: 2 additions & 4 deletions docs/napari_save_coor.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Save Points Labeled in Napari to a File
- Filepath - File to save data. If the file exits an extension will be added.

- **Context:**
- Save points labeled in Napari to a file in case the same points need to be used.
- Save points labeled in Napari to a file to checkpoint annotation progress or reuse.

- **Example use:**
- Save points labeled to a file
Expand All @@ -23,13 +23,11 @@ import plantcv.annotate as pcvan

# Create an instance of the Points class
img, path, name = pcv.readimage("./grayimg.png")

# Should open interactive napari viewer
viewer = pcvan.napari_label_classes(img=img, classes=['background', 'wing','seed'])

dictobj = pcvan.napari_save_coor(viewer, 'testdata.txt')

# Should open interactive napari viewer

```

![Screenshot](img/documentation_images/napari_label_classes/napari_label_classes.png)
Expand Down
2 changes: 1 addition & 1 deletion mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ nav:
- Napari Read Coor: napari_read_coor.md
- Napari Save Coor: napari_save_coor.md
- Points: Points.md

- Get Centroids: get_centroids.md
markdown_extensions:
- toc:
permalink: True
Expand Down
7 changes: 7 additions & 0 deletions plantcv/annotate/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
from importlib.metadata import version
from plantcv.annotate.classes import Points
from plantcv.annotate.get_centroids import get_centroids
from plantcv.annotate.napari_classes import napari_classes
from plantcv.annotate.napari_open import napari_open
from plantcv.annotate.napari_label_classes import napari_label_classes
Expand All @@ -6,8 +9,12 @@
from plantcv.annotate.napari_read_coor import napari_read_coor
from plantcv.annotate.napari_points_mask import napari_points_mask

# Auto versioning
__version__ = version("plantcv-annotate")

__all__ = [
"Points",
"get_centroids",
"napari_classes",
"napari_open",
"napari_label_classes",
Expand Down
Loading

0 comments on commit 52472d4

Please sign in to comment.