Package ai.djl.modality.cv
Class ImageFactory
java.lang.Object
ai.djl.modality.cv.ImageFactory
- Direct Known Subclasses:
BufferedImageFactory
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 Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionabstract ImageGetsImagefrom file.abstract ImageGetsImagefrom varies Java image types.abstract ImageGetsImagefromInputStream.abstract ImagefromNDArray(NDArray array) abstract ImagefromPixels(int[] pixels, int width, int height) GetsImagefrom array.fromRequestUrl(String url) GetsImagefrom a URL that arrived with a request, such as theimage_urlof a JSON input.GetsImagefrom string representation.GetsImagefrom URL.static ImageFactoryGets new instance of Image factory from the provided factory implementation.static voidsetImageFactory(ImageFactory factory) Sets a custom instance ofImageFactory.
-
Constructor Details
-
ImageFactory
public ImageFactory()
-
-
Method Details
-
getInstance
Gets new instance of Image factory from the provided factory implementation.- Returns:
ImageFactory
-
setImageFactory
Sets a custom instance ofImageFactory.- Parameters:
factory- a custom instance ofImageFactory
-
fromFile
GetsImagefrom file.- Parameters:
path- the path to the image- Returns:
Image- Throws:
IOException- Image not found or not readable
-
fromUrl
GetsImagefrom URL.- Parameters:
url- the URL to load from- Returns:
Image- Throws:
IOException- URL is not valid.
-
fromUrl
GetsImagefrom string representation.A string that is not an absolute URL is loaded as a local file. Use
fromRequestUrl(String)for a URL that arrived with a request.- Parameters:
url- the String represent URL or base64 encoded image to load from- Returns:
Image- Throws:
IOException- URL is not valid.
-
fromRequestUrl
GetsImagefrom a URL that arrived with a request, such as theimage_urlof a JSON input.Unlike
fromUrl(String), this only accepts a base64data:URI or anhttporhttpsURL, and the URL is fetched withUtils.openUrl(URL), so it gets the same checks as other remote resources. SetDJL_ALLOW_INSECURE_URL=true(or-Dai.djl.allow_insecure_url=true) to accept any URL or file path, asfromUrl(String)does; as for other remote resources, nothing is fetched in offline mode.- Parameters:
url- thedata:URI, or thehttporhttpsURL- Returns:
Image- Throws:
IOException- if the URL is not supported, or the image cannot be read
-
fromInputStream
GetsImagefromInputStream.- Parameters:
is-InputStream- Returns:
Image- Throws:
IOException- image cannot be read from input stream.
-
fromImage
GetsImagefrom varies Java image types.Image can be BufferedImage or BitMap depends on platform
- Parameters:
image- the image object.- Returns:
Image
-
fromNDArray
- Parameters:
array- the NDArray with CHW format- Returns:
Image
-
fromPixels
GetsImagefrom array.- Parameters:
pixels- the array of ARGB values used to initialize the pixels.width- the width of the imageheight- the height of the image- Returns:
Image
-