Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
GitMup opened this issue Nov 12, 2024 · 0 comments

Comments

@GitMup
Copy link

GitMup commented Nov 12, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant