Class ImageFactory

java.lang.Object
ai.djl.modality.cv.ImageFactory
Direct Known Subclasses:
BufferedImageFactory

public abstract class ImageFactory extends Object
ImageFactory contains image creation mechanism on top of different platforms like PC and Android. System will choose appropriate Factory based on the supported image type.
  • Constructor Details

    • ImageFactory

      public ImageFactory()
  • Method Details

    • getInstance

      public static ImageFactory getInstance()
      Gets new instance of Image factory from the provided factory implementation.
      Returns:
      ImageFactory
    • setImageFactory

      public static void setImageFactory(ImageFactory factory)
      Sets a custom instance of ImageFactory.
      Parameters:
      factory - a custom instance of ImageFactory
    • fromFile

      public abstract Image fromFile(Path path) throws IOException
      Gets Image from file.
      Parameters:
      path - the path to the image
      Returns:
      Image
      Throws:
      IOException - Image not found or not readable
    • fromUrl

      public Image fromUrl(URL url) throws IOException
      Gets Image from URL.
      Parameters:
      url - the URL to load from
      Returns:
      Image
      Throws:
      IOException - URL is not valid.
    • fromUrl

      public Image fromUrl(String url) throws IOException
      Gets Image from URL.
      Parameters:
      url - the String represent URL to load from
      Returns:
      Image
      Throws:
      IOException - URL is not valid.
    • fromInputStream

      public abstract Image fromInputStream(InputStream is) throws IOException
      Gets Image from InputStream.
      Parameters:
      is - InputStream
      Returns:
      Image
      Throws:
      IOException - image cannot be read from input stream.
    • fromImage

      public abstract Image fromImage(Object image)
      Gets Image from varies Java image types.

      Image can be BufferedImage or BitMap depends on platform

      Parameters:
      image - the image object.
      Returns:
      Image
    • fromNDArray

      public abstract Image fromNDArray(NDArray array)
      Gets Image from NDArray.
      Parameters:
      array - the NDArray with CHW format
      Returns:
      Image
    • fromPixels

      public abstract Image fromPixels(int[] pixels, int width, int height)
      Gets Image from array.
      Parameters:
      pixels - the array of ARGB values used to initialize the pixels.
      width - the width of the image
      height - the height of the image
      Returns:
      Image