forte icon indicating copy to clipboard operation
forte copied to clipboard

ImagePayload initialized with image size

Open hepengfe opened this issue 3 years ago • 0 comments

Is your feature request related to a problem? Please describe. Current ImageAnnoatation get image size by get the datapack's image at corresponding payload and then get the shape of image by a fixed function image_data.shape. It has an assumption that image_data is a numpy array which is not always the case. ImagePayload could store image object from other third-party library such as pillow image object or cv2 image object. Also, their shape order could be (width, height) or (height, width). Therefore, we want to store image size in ImagePayload for easier access for ImageAnnoatation.

Therefore, it's better to initialize width and height ahead to ensure the consistency of ImageAnnoatation's functions.

Describe the solution you'd like

  • add parameters image_height and image_width in ImageAnnotation.__init__
  • adjust init functions in ImageAnnotation's child classes accordingly
  • remove ImageAnnotation.set_image_shape

Describe alternatives you've considered The second way of implementing this is get the image size of image data object directly. For example, we could do the following

  if isinstance(self.image, np.ndarray):
      return self.image.shape
  elif isinstance(self.image, PIL.Image.Image):
      return self.image.size

However, it requires importing corresponding third-party libraries in top.py which is not desired.

Third third possible implementation is we let ImagePayload to return the meta data of image.

Additional context Add any other context or screenshots about the feature request here.

hepengfe avatar Jul 14 '22 21:07 hepengfe