Skip to content

Add method to trim polygons according to image witdth & height

Linked to https://gitlab.com/arkindex/backend/-/issues/976

Please create a new method in arkindex_worker.images named trim_ploygon that uses as input:

  • a polygon which must be a list of integer coordinates
  • a positive integer image_width
  • a positive integer image_height

The method must return a polygon where all points are contained in the image:

  • all X coordinates must be set in range (0, image_width)
  • all Y coordinates must be set in range (0, image_height)

A simple heuristic to do the trimming (when some coordinates are not in the image) would be to update every point outside the image to the image border:

polygon = [
   (
      min(image_width, max(0, x)),
      min(image_height, max(0, y)),
   )
   for x, y in polygon
]

And then to remove all consecutive identical points (create a set, iterate over the polygon, if the point is not alredy in the set add it to the polygon and the set).

This method is not used automatically, but will be used by ML workers.

Please add multiple test cases...