From 45c3607c45be8fa262a18f25b276a9f9ae682de1 Mon Sep 17 00:00:00 2001 From: afinit Date: Thu, 29 Jun 2023 12:59:54 -0500 Subject: [PATCH] remove max_val param from threshold.mean() --- docs/mean_threshold.md | 13 ++++++------- docs/updating.md | 2 +- plantcv/plantcv/threshold/threshold_methods.py | 10 ++++------ tests/plantcv/threshold/test_threshold_methods.py | 6 +++--- 4 files changed, 14 insertions(+), 17 deletions(-) diff --git a/docs/mean_threshold.md b/docs/mean_threshold.md index 322eff82c..7ecb65987 100644 --- a/docs/mean_threshold.md +++ b/docs/mean_threshold.md @@ -8,7 +8,7 @@ This local threshold depends on the local average, computed in a squared portion In the mean adaptive threshold, the local average is the average of the pixel values in the block. -**plantcv.threshold.mean**(*gray_img, block_size, offset, object_type="light", max_value=255*) +**plantcv.threshold.mean**(*gray_img, block_size, offset, object_type="light"*) **returns** thresholded/binary image @@ -19,10 +19,9 @@ In the mean adaptive threshold, the local average is the average of the pixel va A negative offset sets the local threshold above the local average. - object_type - "light" or "dark" (default: "light"). - "light" for objects brighter than the background, sets the pixels above - the local threshold to max_value and the pixels below to 0. + the local threshold to 255 and the pixels below to 0. - "dark" for objects darker than the background, sets the pixels below the - local threshold to max_value and the pixels above to 0. - - max_value - Value to apply above threshold (default: 255 = white) + local threshold to 255 and the pixels above to 0. - **Context:** - Useful for unevenly illuminated images @@ -41,13 +40,13 @@ pcv.params.debug = "plot" # Adaptive threshold with different parameters threshold_mean1 = pcv.threshold.mean(gray_img=gray_img, block_size=250, offset=25, - object_type='dark', max_value=255) + object_type='dark') threshold_mean2 = pcv.threshold.mean(gray_img=gray_img, block_size=15, offset=5, - object_type='dark', max_value=255) + object_type='dark') threshold_mean3 = pcv.threshold.mean(gray_img=gray_img, block_size=2000, offset=25, - object_type='dark', max_value=255) + object_type='dark') ``` **Thresholded image** diff --git a/docs/updating.md b/docs/updating.md index 75f3a5373..d459b5ef7 100644 --- a/docs/updating.md +++ b/docs/updating.md @@ -1047,7 +1047,7 @@ pages for more details on the input and output variable types. * pre v3.0dev2: NA * post v3.0dev2: bin_img = **plantcv.threshold.mean**(*gray_img, max_value, object_type="light"*) -* post v4.0: bin_img = **plantcv.threshold.mean**(*gray_img, block_size, offset, object_type="light", max_value=255*) +* post v4.0: bin_img = **plantcv.threshold.mean**(*gray_img, block_size, offset, object_type="light"*) #### plantcv.threshold.otsu diff --git a/plantcv/plantcv/threshold/threshold_methods.py b/plantcv/plantcv/threshold/threshold_methods.py index 32afa9761..11e1a655d 100644 --- a/plantcv/plantcv/threshold/threshold_methods.py +++ b/plantcv/plantcv/threshold/threshold_methods.py @@ -104,7 +104,7 @@ def gaussian(gray_img, block_size, offset, object_type="light", max_value=255): # Mean adaptive threshold -def mean(gray_img, block_size, offset, object_type="light", max_value=255): +def mean(gray_img, block_size, offset, object_type="light"): """Creates a binary image from a grayscale image based on the mean adaptive threshold method. Adaptive thresholds use a threshold value that varies across the image. @@ -120,10 +120,9 @@ def mean(gray_img, block_size, offset, object_type="light", max_value=255): A negative offset sets the local threshold above the local average. object_type = "light" or "dark" (default: "light") - "light" (for objects brighter than the background) sets the pixels above - the local threshold to max_value and the pixels below to 0. + the local threshold to 255 and the pixels below to 0. - "dark" (for objects darker than the background) sets the pixels below the - local threshold to max_value and the pixels above to 0. - max_value = Value to apply above threshold (default: 255 = white) + local threshold to 255 and the pixels above to 0. Returns: bin_img = Thresholded, binary image @@ -132,7 +131,6 @@ def mean(gray_img, block_size, offset, object_type="light", max_value=255): :param block_size: int :param offset: float :param object_type: str - :param max_value: int :return bin_img: numpy.ndarray """ # Set the threshold method @@ -146,7 +144,7 @@ def mean(gray_img, block_size, offset, object_type="light", max_value=255): params.device += 1 - bin_img = _call_adaptive_threshold(gray_img, block_size, offset, max_value, cv2.ADAPTIVE_THRESH_MEAN_C, + bin_img = _call_adaptive_threshold(gray_img, block_size, offset, 255, cv2.ADAPTIVE_THRESH_MEAN_C, threshold_method, "_mean_threshold_") return bin_img diff --git a/tests/plantcv/threshold/test_threshold_methods.py b/tests/plantcv/threshold/test_threshold_methods.py index 2c9937940..17ba24afc 100644 --- a/tests/plantcv/threshold/test_threshold_methods.py +++ b/tests/plantcv/threshold/test_threshold_methods.py @@ -47,7 +47,7 @@ def test_mean(objtype, size, threshold_test_data): """Test for PlantCV.""" # Read in test data gray_img = cv2.imread(threshold_test_data.small_gray_img, -1) - binary_img = mean(gray_img=gray_img, block_size=size, offset=2, object_type=objtype, max_value=255) + binary_img = mean(gray_img=gray_img, block_size=size, offset=2, object_type=objtype) # Assert that the output image has the dimensions of the input image and is binary assert gray_img.shape == binary_img.shape and np.array_equal(np.unique(binary_img), np.array([0, 255])) @@ -57,7 +57,7 @@ def test_mean_incorrect_object_type(threshold_test_data): # Read in test data gray_img = cv2.imread(threshold_test_data.small_gray_img, -1) with pytest.raises(RuntimeError): - _ = mean(gray_img=gray_img, block_size=11, offset=2, object_type="lite", max_value=255) + _ = mean(gray_img=gray_img, block_size=11, offset=2, object_type="lite") def test_mean_incorrect_block_size(threshold_test_data): @@ -65,7 +65,7 @@ def test_mean_incorrect_block_size(threshold_test_data): # Read in test data gray_img = cv2.imread(threshold_test_data.small_gray_img, -1) with pytest.raises(RuntimeError): - _ = mean(gray_img=gray_img, block_size=1, offset=2, object_type="dark", max_value=255) + _ = mean(gray_img=gray_img, block_size=1, offset=2, object_type="dark") @pytest.mark.parametrize("objtype", ["dark", "light"])