Skip to content

Commit

Permalink
update napari_open
Browse files Browse the repository at this point in the history
update napari_open function tests and docs so the default behavior is not to colorize gray images by adding  a mode option.
  • Loading branch information
maliagehan committed Aug 23, 2024
1 parent d0faaee commit 2281451
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 6 deletions.
5 changes: 3 additions & 2 deletions docs/napari_open.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@

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*)
**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)
- mode - 'native' or 'colorize'. If 'colorized' is selected grayimages 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
10 changes: 6 additions & 4 deletions plantcv/annotate/napari_open.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@
import napari


def napari_open(img, show=True):
def napari_open(img, mode='native', show=True):
"""
open img in napari
Inputs:
img = img (grayimg, rgbimg, or hyperspectral image array data e.g.
hyperspectraldata.array_data)
mode = 'native or 'colorize'
show = if show is True the viewer is launched. This option is useful for
running tests without triggering the viewer.
Expand All @@ -25,9 +26,10 @@ def napari_open(img, show=True):
"""
shape = np.shape(img)
if len(shape) == 2:
colorful = label2rgb(img)
img = (255*colorful).astype(np.uint8)
img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
if mode == 'colorize':
colorful = label2rgb(img)
img = (255*colorful).astype(np.uint8)
img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
if len(shape) == 3:
if shape[2] == 3:
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 2281451

Please sign in to comment.