geo_to_image_coordinates output still needs manual processing before it is ready to be used as annotations input
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
This will be closed by #1210