From 22814516a14c4bc3dc62df256b030ae471f26a1f Mon Sep 17 00:00:00 2001 From: Malia Gehan Date: Thu, 22 Aug 2024 21:10:59 -0500 Subject: [PATCH 1/5] 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 From fd8c66f70bc205f500158d7a33eb3add80e0b5e3 Mon Sep 17 00:00:00 2001 From: Malia Gehan Date: Thu, 22 Aug 2024 21:15:22 -0500 Subject: [PATCH 2/5] deepsource if statement combined if statements for deepsource --- plantcv/annotate/napari_open.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/plantcv/annotate/napari_open.py b/plantcv/annotate/napari_open.py index e2c56ff..5c08e5d 100755 --- a/plantcv/annotate/napari_open.py +++ b/plantcv/annotate/napari_open.py @@ -25,11 +25,10 @@ def napari_open(img, mode='native', show=True): """ shape = np.shape(img) - if len(shape) == 2: - if mode == 'colorize': - colorful = label2rgb(img) - img = (255*colorful).astype(np.uint8) - img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB) + if len(shape) == 2 and 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) From 5be390037b196c39cc796eb6f35d404ad5e2dbbb Mon Sep 17 00:00:00 2001 From: HaleySchuhl Date: Tue, 3 Sep 2024 09:52:36 -0500 Subject: [PATCH 3/5] initial docs for changelog --- docs/changelog.md | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/docs/changelog.md b/docs/changelog.md index 820a7f1..cb9e2bd 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -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"*) From 5678c688d65cce15236f632ba23d369fb3a9390b Mon Sep 17 00:00:00 2001 From: HaleySchuhl Date: Tue, 3 Sep 2024 10:12:25 -0500 Subject: [PATCH 4/5] minor updates to docs page --- docs/napari_open.md | 8 ++++---- plantcv/annotate/napari_open.py | 26 +++++++++++++------------- 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/docs/napari_open.md b/docs/napari_open.md index 30fef49..395cc98 100644 --- a/docs/napari_open.md +++ b/docs/napari_open.md @@ -1,14 +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, mode = 'native', 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. + - 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:** diff --git a/plantcv/annotate/napari_open.py b/plantcv/annotate/napari_open.py index 5c08e5d..a229e50 100755 --- a/plantcv/annotate/napari_open.py +++ b/plantcv/annotate/napari_open.py @@ -7,22 +7,22 @@ def napari_open(img, mode='native', show=True): - """ - open img in napari + """Open an image with a napari interactive viewer - 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 + 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 and mode == 'colorize': From 4a99ed00333df0f9bf89d0d0761e80ce04bac310 Mon Sep 17 00:00:00 2001 From: HaleySchuhl Date: Tue, 3 Sep 2024 10:14:40 -0500 Subject: [PATCH 5/5] remove extra * in changelog.md --- docs/changelog.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/changelog.md b/docs/changelog.md index cb9e2bd..fa2561f 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -2,7 +2,7 @@ All notable changes to this project will be documented below. -#### annotate.get_centroids** +#### annotate.get_centroids * v0.1dev: coords_list = **annotate.get_centroids**(*bin_img*)