weecology / weecology/DeepForest

geo_to_image_coordinates output still needs manual processing before it is ready to be used as annotations input

Open
#835 1 comment 0 reactions 1 assignee View on GitHub

Nobody has claimed this yet.

API bug
Dominant language
Python
Stars
774
Forks
265
PR merge metrics
No merged PRs in 30d

Description

Hi There,

I've annotated an RGB image to use as training data to improve prediction in our area. To this end I am using the shapefile_to_annotations function which I expected to output something that I might save to csv directly to be used by the trainer. This is also stated in the docstring for the function. This is not the case however, as it outputs a gdf with a geometry column, and not the desired xmin, ymin, xmax, ymax columns.

I don't know if there is another function to handle this, if so, it wasn't immediately clear from available function names or documentation. I also noticed that bounding boxes in this translation can go out of image bounds, which results in an error further on. I've now fixed both problems locally by modifying the end of geo_to_image_coordinates function:

    image_coordinates = transformed_gdf.geometry.bounds.rename(
        columns={"minx": "xmin", "miny": "ymin", "maxx": "xmax", "maxy": "ymax"}
    ).copy()

    image_coordinates[image_coordinates < 0] = 0
    max_possible_x = (right - left) / image_resolution
    max_possible_y = (top - bottom) / image_resolution
    image_coordinates.loc[image_coordinates.xmax > max_possible_x, "xmax"] = (
        max_possible_x
    )
    image_coordinates.loc[image_coordinates.ymax > max_possible_y, "ymax"] = (
        max_possible_y
    )

    transformed_gdf = transformed_gdf.join(
        image_coordinates.astype(int), how="left", validate="1:1"
    ).drop("geometry", axis=1)
    transformed_gdf.crs = None

    return transformed_gdf

It works now, but I was wondering if I am overlooking a function that is already doing this? Am I using the wrong function to convert my shape?

Cheers,
Levi

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.