Class CategoryMask

    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      static class  CategoryMask.SegmentationSerializer
      A customized Gson serializer to serialize the Segmentation object.
    • Constructor Summary

      Constructors 
      Constructor Description
      CategoryMask​(java.util.List<java.lang.String> classes, int[][] mask)
      Constructs a Mask with the given data.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void drawMask​(Image image, int opacity)
      Highlights the detected object on the image with random colors.
      void drawMask​(Image image, int opacity, int background)
      Highlights the detected object on the image with random colors.
      void drawMask​(Image image, int classId, int color, int opacity)
      Highlights the specified object with specific color.
      Image getBackgroundImage​(Image image)
      Extracts the background from the image.
      java.util.List<java.lang.String> getClasses()
      Returns the list of classes.
      int[][] getMask()
      Returns the class for each pixel.
      Image getMaskImage​(Image image)
      Extracts the detected objects from the image.
      Image getMaskImage​(Image image, int classId)
      Extracts the specified object from the image.
      java.nio.ByteBuffer toByteBuffer()
      Returns the ByteBuffer presentation of the object.
      java.lang.String toJson()
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • CategoryMask

        public CategoryMask​(java.util.List<java.lang.String> classes,
                            int[][] mask)
        Constructs a Mask with the given data.
        Parameters:
        classes - the list of classes
        mask - the category mask for each pixel in the image
    • Method Detail

      • getClasses

        public java.util.List<java.lang.String> getClasses()
        Returns the list of classes.
        Returns:
        list of classes
      • getMask

        public int[][] getMask()
        Returns the class for each pixel.
        Returns:
        the class for each pixel
      • toByteBuffer

        public java.nio.ByteBuffer toByteBuffer()
        Returns the ByteBuffer presentation of the object.
        Specified by:
        toByteBuffer in interface BytesSupplier
        Returns:
        the ByteBuffer presentation of the object
      • toJson

        public java.lang.String toJson()
        Specified by:
        toJson in interface ai.djl.util.JsonSerializable
      • getMaskImage

        public Image getMaskImage​(Image image)
        Extracts the detected objects from the image.
        Parameters:
        image - the original image
        Returns:
        the detected objects from the image
      • getMaskImage

        public Image getMaskImage​(Image image,
                                  int classId)
        Extracts the specified object from the image.
        Parameters:
        image - the original image
        classId - the class to extract from the image
        Returns:
        the specific object on the image
      • getBackgroundImage

        public Image getBackgroundImage​(Image image)
        Extracts the background from the image.
        Parameters:
        image - the original image
        Returns:
        the background of the image
      • drawMask

        public void drawMask​(Image image,
                             int opacity)
        Highlights the detected object on the image with random colors.
        Parameters:
        image - the original image
        opacity - the opacity of the overlay. Value is between 0 and 255 inclusive, where 0 means the overlay is completely transparent and 255 means the overlay is completely opaque.
      • drawMask

        public void drawMask​(Image image,
                             int opacity,
                             int background)
        Highlights the detected object on the image with random colors.
        Parameters:
        image - the original image
        opacity - the opacity of the overlay. Value is between 0 and 255 inclusive, where 0 means the overlay is completely transparent and 255 means the overlay is completely opaque.
        background - replace the background with specified background color, use transparent color to remove background
      • drawMask

        public void drawMask​(Image image,
                             int classId,
                             int color,
                             int opacity)
        Highlights the specified object with specific color.
        Parameters:
        image - the original image
        classId - the class to draw on the image
        color - the rgb color with opacity
        opacity - the opacity of the overlay. Value is between 0 and 255 inclusive, where 0 means the overlay is completely transparent and 255 means the overlay is completely opaque.