-
Notifications
You must be signed in to change notification settings - Fork 0
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 #13 from danforthcenter/napari-join-labels
Napari join labels
- Loading branch information
Showing
28 changed files
with
1,200 additions
and
21 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,4 @@ | ||
[run] | ||
omit = | ||
config.py | ||
config-3.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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+163 KB
docs/img/documentation_images/napari_label_classes/napari_label_classes.png
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,32 @@ | ||
## Open Image with Napari | ||
|
||
Get class names from Napari Viewer Object. | ||
|
||
**plantcv.annotate.napari_classes**(*viewer*) | ||
|
||
**returns** list of napari classes | ||
|
||
- **Parameters:** | ||
- viewer - Napari viewer object | ||
|
||
- **Context:** | ||
- Get names of Napari classes. This is mainly an internal function but can be useful in other context. | ||
|
||
- **Example use:** | ||
- Get names of Napari classes/labels. | ||
|
||
|
||
```python | ||
import plantcv.plantcv as pcv | ||
import plantcv.annotate as pcvan | ||
|
||
# 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']) | ||
|
||
classes = pcvan.napari_classes(viewer) | ||
|
||
``` | ||
|
||
**Source Code:** [Here](https://github.com/danforthcenter/plantcv-annotate/blob/main/plantcv/annotate/napari_classes.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
## Join Labels with Napari | ||
|
||
This function joins classes with the same label. This function would be run after classes are labeled with napari_label_classes. | ||
|
||
**plantcv.annotate.napari_join_labels*(*img, viewer*) | ||
|
||
**returns** relabeled mask, dictionary of masks for each class | ||
|
||
- **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) | ||
- viewer - viewer with labeled classes. If no points are selected for a class, | ||
data without labels will default to this class when napari_join_labels | ||
is run. If all classes have points labeled, any clusters not labeled | ||
will default to the last class in the list if napari_join_labels is | ||
run. | ||
|
||
- **Context:** | ||
- This function would be run after labeling classes in Napari is complete. | ||
|
||
- **Example use:** | ||
- Joining classes labeled as the same, for example for joining classes from output of kmeans clustering | ||
|
||
|
||
```python | ||
import plantcv.plantcv as pcv | ||
import plantcv.annotate as pcvan | ||
import napari | ||
|
||
# Create an instance of the Points class | ||
img, path, name = pcv.readimage("./grayimg.png") | ||
|
||
viewer = pcvan.napari_label_classes(img=img, ['background', 'wing','seed']) | ||
|
||
# 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) | ||
|
||
![Screenshot](img/documentation_images/napari_join_labels/1_labeled_mask.png) | ||
|
||
|
||
**Source Code:** [Here](https://github.com/danforthcenter/plantcv-annotate/blob/main/plantcv/annotate/napari_label_classes.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
## 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 annotated as long as viewer is open. | ||
|
||
**plantcv.annotate.napari_label_classes*(*img, classes, 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. If no points are selected for a class, | ||
data without labels will default to this class when napari_join_labels | ||
is run. If all classes have points labeled, any clusters not labeled | ||
will default to the last class in the list if napari_join_labels is | ||
run. | ||
- 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). | ||
|
||
- **Example use:** | ||
- Labeling output of kmeans clustering into classes. Labeling points. | ||
|
||
|
||
```python | ||
import plantcv.plantcv as pcv | ||
import plantcv.annotate as pcvan | ||
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']) | ||
|
||
# Should open interactive napari viewer | ||
|
||
``` | ||
|
||
![Screenshot](img/documentation_images/napari_label_classes/napari_label_classes.png) | ||
|
||
|
||
**Source Code:** [Here](https://github.com/danforthcenter/plantcv-annotate/blob/main/plantcv/annotate/napari_label_classes.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
## 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. | ||
|
||
**plantcv.annotate.napari_open**(*img, 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) | ||
- show - if show = True, viewer is launched. False setting is useful for test purposes. | ||
|
||
- **Context:** | ||
- Used to open image data with Napari. | ||
|
||
- **Example use:** | ||
- Open image data to annotate it with other Napari functions (e.g. napari_label_classes) | ||
|
||
|
||
```python | ||
import plantcv.plantcv as pcv | ||
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) | ||
|
||
# Should open interactive napari viewer | ||
|
||
``` | ||
|
||
![Screenshot](img/documentation_images/napari_open/napari_open.png) | ||
|
||
|
||
**Source Code:** [Here](https://github.com/danforthcenter/plantcv-annotate/blob/main/plantcv/annotate/napari_open.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
# run: conda env create --file environment.yml | ||
# optionally, change channel name with -n {plantcv-dev} | ||
name: plantcv | ||
dependencies: | ||
- python=3.10 | ||
- matplotlib>=1.5 | ||
- numpy>=1.11 | ||
- pandas | ||
- python-dateutil | ||
- scipy | ||
- scikit-image>=0.19 | ||
- scikit-learn | ||
- dask | ||
- dask-jobqueue | ||
- opencv | ||
- statsmodels | ||
- xarray>=2022.11.0 | ||
- mkdocs | ||
- pytest | ||
- pytest-cov | ||
- flake8 | ||
- ipympl | ||
- nodejs | ||
- jupyterlab | ||
- altair | ||
- vl-convert-python | ||
- napari | ||
- pyqt | ||
- pytest-qt | ||
|
||
channels: | ||
- conda-forge | ||
- defaults |
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 |
---|---|---|
@@ -1,11 +1,19 @@ | ||
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 | ||
from plantcv.annotate.napari_join_labels import napari_join_labels | ||
|
||
# Auto versioning | ||
__version__ = version("plantcv-annotate") | ||
|
||
__all__ = [ | ||
"Points", | ||
"get_centroids" | ||
"get_centroids", | ||
"napari_classes", | ||
"napari_open", | ||
"napari_label_classes", | ||
"napari_join_labels" | ||
] |
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,31 @@ | ||
# Get Napari Keys | ||
|
||
import re | ||
|
||
|
||
def napari_classes(viewer): | ||
""" | ||
get names of napari keys | ||
Inputs: | ||
viewer = napari viewer object | ||
Returns: | ||
classes = napari class value names | ||
:param viewer: napari.viewer.Viewer | ||
:return labels: numpy.ndarray, list | ||
""" | ||
keylist = list(viewer.layers) | ||
keylist = ''.join(str(keylist)) | ||
keylist = keylist.split(',') | ||
|
||
classes = [] | ||
for x in keylist: | ||
if re.search('Image layer', x): | ||
pass | ||
else: | ||
y = x.split(" ") | ||
classes.append(y[3].strip("\'")) | ||
|
||
return classes |
Oops, something went wrong.