Skip to content

Commit

Permalink
fix flake
Browse files Browse the repository at this point in the history
  • Loading branch information
sliu008 committed Oct 29, 2024
1 parent 6e0a332 commit ec61429
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions podaac/forge_py/open_cv_footprint.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from shapely.geometry import Polygon, MultiPolygon
from PIL import Image


def read_and_threshold_image(image_path, threshold_value=185):
"""
Reads an image from the specified file path, converts it to grayscale, and applies a binary threshold.
Expand All @@ -27,6 +28,7 @@ def read_and_threshold_image(image_path, threshold_value=185):
_, img_th = cv2.threshold(gray, threshold_value, 255, cv2.THRESH_BINARY)
return img_th


def apply_morphological_operations(image, kernel_size=(5, 5)):
"""
Applies morphological operations to clean up binary images by filling gaps and removing small noise.
Expand All @@ -48,6 +50,7 @@ def apply_morphological_operations(image, kernel_size=(5, 5)):
img_cleaned = cv2.morphologyEx(img_cleaned, cv2.MORPH_OPEN, kernel) # Remove small noise
return img_cleaned


def pixel_to_lonlat(x, y, width, height):
"""
Converts pixel coordinates (x, y) in an image to geographic coordinates (longitude, latitude).
Expand All @@ -70,6 +73,7 @@ def pixel_to_lonlat(x, y, width, height):
lat = 90 - y * (180 / height)
return lon, lat


def contour_to_lonlat(contour, width, height):
"""
Converts a contour from pixel coordinates to geographic coordinates (longitude, latitude).
Expand Down Expand Up @@ -97,6 +101,7 @@ def contour_to_lonlat(contour, width, height):
lonlat_contour.append([lon, lat])
return np.array(lonlat_contour)


def create_polygon_from_contours(outer_contour, holes, width, height):
"""
Creates a polygon from an outer contour and optional inner contours (holes), converting pixel coordinates
Expand Down Expand Up @@ -185,6 +190,7 @@ def process_multipolygons(contours, hierarchy, width, height):
return polygons[0]
return None


def process_mask(image, kernel_size=(20, 20)):
"""
Applies morphological closing to an image mask to fill small gaps, enhancing contiguous regions.
Expand Down

0 comments on commit ec61429

Please sign in to comment.