Skip to content

Commit

Permalink
make fill kernel optional defaults to none
Browse files Browse the repository at this point in the history
  • Loading branch information
sliu008 committed Nov 27, 2024
1 parent d21b538 commit ac3caf5
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
8 changes: 5 additions & 3 deletions podaac/forge_py/strategies/open_cv_footprint.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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.
Expand Down Expand Up @@ -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 []
Expand Down

0 comments on commit ac3caf5

Please sign in to comment.