From 22814516a14c4bc3dc62df256b030ae471f26a1f Mon Sep 17 00:00:00 2001 From: Malia Gehan Date: Thu, 22 Aug 2024 21:10:59 -0500 Subject: [PATCH] update napari_open update napari_open function tests and docs so the default behavior is not to colorize gray images by adding a mode option. --- docs/napari_open.md | 5 +++-- plantcv/annotate/napari_open.py | 10 ++++++---- tests/test_napari_open.py | 13 +++++++++++++ 3 files changed, 22 insertions(+), 6 deletions(-) diff --git a/docs/napari_open.md b/docs/napari_open.md index c699a85..30fef49 100644 --- a/docs/napari_open.md +++ b/docs/napari_open.md @@ -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:** @@ -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 diff --git a/plantcv/annotate/napari_open.py b/plantcv/annotate/napari_open.py index 59fa317..e2c56ff 100755 --- a/plantcv/annotate/napari_open.py +++ b/plantcv/annotate/napari_open.py @@ -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. @@ -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) diff --git a/tests/test_napari_open.py b/tests/test_napari_open.py index 602e3ef..c6d1376 100644 --- a/tests/test_napari_open.py +++ b/tests/test_napari_open.py @@ -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