Skip to content

Documentation for convert_geotiff_and_polygon_to_coco

Path: utils/convert_geotiff_and_polygon_to_coco.py

Functions

convert_geotiff_to_jpg

Convert a GeoTIFF file to a JPG image.

Args: geotiff_path (str): Path to the input GeoTIFF file. output_dir (str): Directory where the output JPG file will be saved.

Returns: tuple: A tuple containing: - str: Path to the saved JPG file. - tuple: Size of the image as (width, height).

geo_coords_to_pixel_coords

Convert geographic coordinates to pixel coordinates.

Args: geometry (shapely.geometry.Polygon or shapely.geometry.MultiPolygon): The geometry to convert. transform (affine.Affine): Affine transform of the GeoTIFF. width (int): Width of the image in pixels. height (int): Height of the image in pixels.

Returns: list: A list of Shapely Polygons in pixel coordinates.

polygon_to_coco_segmentation

Convert a Shapely polygon to COCO segmentation format.

Args: polygon (shapely.geometry.Polygon): The polygon to convert.

Returns: list: A list containing the segmentation in COCO format.

polygon_to_coco_bbox

Convert a Shapely polygon to COCO bounding box format.

Args: polygon (shapely.geometry.Polygon): The polygon to convert.

Returns: list: A list containing the bounding box in COCO format [x, y, width, height].

geojson_to_coco

Convert GeoTIFF and GeoJSON files to a COCO dataset.

Args: geotiff_dir (str): Directory containing GeoTIFF and GeoJSON files. output_dir (str): Directory where the COCO dataset will be saved.

Returns: str: Path to the generated COCO JSON file.