From ac3caf536fb619bfc4acc332b5fdcb76ad7e9cff Mon Sep 17 00:00:00 2001 From: Simon Liu Date: Wed, 27 Nov 2024 11:28:20 -0800 Subject: [PATCH] make fill kernel optional defaults to none --- README.md | 2 +- podaac/forge_py/strategies/open_cv_footprint.py | 8 +++++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 84ce7c9..61f9cc4 100644 --- a/README.md +++ b/README.md @@ -46,7 +46,7 @@ The configuration file specifies the parameters for generating footprints from v * **`open_cv`**: * **`pixel_height`** (int, optional, default: 1800): Desired pixel height for the input image. * **`min_area`** (int, optional): Minimum area for polygons to be retained. - * **`fill_kernel`** (list of int, optional, default: [20,20]): Kernel size for filling holes in polygons. + * **`fill_kernel`** (list of int, optional, default: None): Kernel size for filling holes in polygons. * **`simplify`** (float, optional,): Controls the level of simplification applied to extracted polygons. * **`fill_value`** (float, optional, default: np.nan): Fill value in the latitude, longitude arrays. diff --git a/podaac/forge_py/strategies/open_cv_footprint.py b/podaac/forge_py/strategies/open_cv_footprint.py index 704883f..f6ff5da 100644 --- a/podaac/forge_py/strategies/open_cv_footprint.py +++ b/podaac/forge_py/strategies/open_cv_footprint.py @@ -311,7 +311,7 @@ def calculate_width_from_height(height): return width -def footprint_open_cv(lon, lat, pixel_height=1800, path=None, threshold_value=185, fill_kernel=(20, 20), fill_value=np.nan, **kwargs): +def footprint_open_cv(lon, lat, pixel_height=1800, path=None, threshold_value=185, fill_kernel=None, fill_value=np.nan, **kwargs): """ Main pipeline for processing geographic coordinates to create a footprint polygon using image processing techniques. @@ -322,6 +322,7 @@ def footprint_open_cv(lon, lat, pixel_height=1800, path=None, threshold_value=18 - height (int, optional): Height of the output image in pixels. Default is 900. - threshold_value (int, optional): Threshold value for binarizing the image. Default is 185. - fill_value: (float, optional): Fill value in the latitude, longitude arrays. Default = np.nan; the default + - fill_kernel (array or tuple of int, optional): The size of the structuring element for morphological operations. Returns: - str: Well-Known Text (WKT) representation of the simplified polygon created from the input coordinates. @@ -358,8 +359,9 @@ def footprint_open_cv(lon, lat, pixel_height=1800, path=None, threshold_value=18 processed_filename = f"{path}/image_processed_{uuid.uuid4()}.png" write_image(new_lat, new_lon, original_filename, image_width=pixel_width, image_height=pixel_height) - img_th = read_and_threshold_image(original_filename, threshold_value) - img_cleaned = apply_morphological_operations(img_th, fill_kernel=fill_kernel, output_path=processed_filename) + img_cleaned = read_and_threshold_image(original_filename, threshold_value) + if fill_kernel: + img_cleaned = apply_morphological_operations(img_cleaned, fill_kernel=fill_kernel, output_path=processed_filename) contours, hierarchy = cv2.findContours(img_cleaned, cv2.RETR_CCOMP, cv2.CHAIN_APPROX_NONE) hierarchy = hierarchy[0] if hierarchy is not None else []