Skip to content

Commit

Permalink
Merge pull request #36 from danforthcenter/35-update-napari_open
Browse files Browse the repository at this point in the history
update napari_open
  • Loading branch information
HaleySchuhl authored Sep 3, 2024
2 parents d0faaee + 4a99ed0 commit 2badc75
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 18 deletions.
24 changes: 24 additions & 0 deletions docs/changelog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,27 @@
## 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, show=True*)

#### annotate.napari_open

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

#### annotate.Points

* v0.1dev: viewer = **annotate.Points**(*img, figsize=(12,6), label="dafault"*)
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
29 changes: 15 additions & 14 deletions plantcv/annotate/napari_open.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,26 @@
import napari


def napari_open(img, show=True):
"""
open img in napari
def napari_open(img, mode='native', show=True):
"""Open an image with a napari interactive viewer
Inputs:
img = img (grayimg, rgbimg, or hyperspectral image array data e.g.
hyperspectraldata.array_data)
show = if show is True the viewer is launched. This option is useful for
Parameters
----------
img : numpy.ndarray
Image to be opened, img can be gray, rgb, or multispectral
mode: str
Viewing mode, either 'native' (default) or 'colorize'
show: bool
if show is True the viewer is launched. This option is useful for
running tests without triggering the viewer.
Returns:
viewer = napari viewer object
:param img: numpy.ndarray
:return viewer: napari viewer object
Returns
-------
napari.viewer.Viewer
Napari viewer object
"""
shape = np.shape(img)
if len(shape) == 2:
if len(shape) == 2 and mode == 'colorize':
colorful = label2rgb(img)
img = (255*colorful).astype(np.uint8)
img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
Expand Down
13 changes: 13 additions & 0 deletions tests/test_napari_open.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,19 @@ def test_napari_open_gray(test_data):
viewer.close()


def test_napari_open_gray1(test_data):
"""Test for PlantCV.Annotate"""
# Read in test data
img, _, _ = readimage(test_data.kmeans_seed_gray_img)
viewer = napari_open(img, mode='colorize', show=False)
coor = [(25, 25), (50, 50)]
viewer.add_points(np.array(coor), symbol="o", name="total",
face_color="red", size=1)

assert len(viewer.layers['total'].data) == 2
viewer.close()


def test_napari_open_envi(test_data):
"""Test for PlantCV.Annotate"""
# Read in test data
Expand Down

0 comments on commit 2badc75

Please sign in to comment.