Package boofcv.io.image
Class UtilImageIO
java.lang.Object
boofcv.io.image.UtilImageIO
Class for loading and saving images.
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic booleanUses mime type to determine if it's an image or not.static booleanisKnownSuffix(String suffix) static @Nullable BufferedImageA function that load the specified image.static <T extends ImageBase<T>>
Tstatic @Nullable BufferedImageA function that load the specified image.static <T extends ImageBase<T>>
Tstatic <T extends ImageGray<T>>
TLoads the image and converts into the specified image type.static @Nullable BufferedImagestatic <T extends ImageGray<T>>
Tstatic BufferedImageloadImageNotNull(String fileName) static BufferedImageloadImageNotNull(String directory, String fileName) static List<BufferedImage>loadImages(String directory, String regex) Loads all the image in the specified directory which match the provided regexstatic GrayS32loadLabeledRle(String fileName, @Nullable GrayS32 labeled) Loads a labeled image in a RLE format.static BufferedImageloadPGM(InputStream inputStream, @Nullable BufferedImage storage) Loads a PGM image from anInputStream.static BufferedImageloadPGM(String fileName, BufferedImage storage) Loads a PGM image from a file.static GrayU8loadPGM_U8(InputStream inputStream, @Nullable GrayU8 storage) Loads a PGM image from anInputStream.static GrayU8loadPGM_U8(String fileName, @Nullable GrayU8 storage) Loads a PGM image from anInputStream.static BufferedImageloadPPM(InputStream inputStream, @Nullable BufferedImage storage) Loads a PPM image from anInputStream.static BufferedImageloadPPM(String fileName, BufferedImage storage) Loads a PPM image from a file.loadPPM_U8(InputStream inputStream, Planar<GrayU8> storage, DogArray_I8 temp) Reads a PPM image file directly into a Planarimage. loadPPM_U8(String fileName, Planar<GrayU8> storage, DogArray_I8 temp) Reads a PPM image file directly into a Planarimage. static voidSaves the BoofCV formatted image.static voidsaveImage(BufferedImage img, String fileName) Saves theBufferedImageto the specified file.static voidsaveJpeg(BufferedImage img, String path, double quality) Saves a jpeg image to disk with an adjustable quality setting.static voidsaveLabeledRle(GrayS32 labeled, String fileName) Saves a labeled image in a RLE format.static voidSaves an image in PGM format.static voidsavePPM(Planar<GrayU8> rgb, String fileName, @Nullable DogArray_I8 temp) Saves an image in PPM format.static voidvideoToImages(String pathVideo, String pathOutput) Converts a video into a sequence of png images.
-
Field Details
-
IMAGE_SUFFIXES
List of supported image types
-
-
Constructor Details
-
UtilImageIO
public UtilImageIO()
-
-
Method Details
-
isKnownSuffix
-
loadImage
A function that load the specified image. If anything goes wrong it returns a null. -
loadImageNotNull
-
loadImage
-
loadImageNotNull
-
loadImages
Loads all the image in the specified directory which match the provided regex- Parameters:
directory- File directoryregex- Regex used to match file names- Returns:
- List of found images.
-
loadImage
A function that load the specified image. If anything goes wrong it returns a null. -
loadImage
Loads the image and converts into the specified image type.- Parameters:
fileName- Path to image file.imageType- Type of image that should be returned.- Returns:
- The image or null if the image could not be loaded.
-
loadImage
-
loadImage
-
loadImage
-
saveImage
Saves theBufferedImageto the specified file. The image type of the output is determined by the name's extension. By default the file is saved usingImageIO.write(RenderedImage, String, File)} but if that fails then it will see if it can save it using BoofCV native code for PPM and PGM.- Parameters:
img- Image which is to be saved.fileName- Name of the output file. The type is determined by the extension.
-
saveJpeg
Saves a jpeg image to disk with an adjustable quality setting.- Parameters:
img- Image that's to be savedpath- Where it should save the imagequality- 0 to 1.0. 0 = lowest quality and 1.0 = best quality.
-
saveImage
Saves the BoofCV formatted image. This is identical to the following code:
BufferedImage out = ConvertBufferedImage.convertTo(image,null,true); saveImage(out,fileName);
- Parameters:
image- Image which is to be saved.fileName- Name of the output file. The type is determined by the extension.
-
loadPPM
Loads a PPM image from a file.- Parameters:
fileName- Location of PPM imagestorage- (Optional) Storage for output image. Must be the width and height of the image being read. Better performance of type BufferedImage.TYPE_INT_RGB. If null or width/height incorrect a new image will be declared.- Returns:
- The read in image
- Throws:
IOException- Thrown if there is a problem reading the image
-
loadPGM
Loads a PGM image from a file.- Parameters:
fileName- Location of PGM imagestorage- (Optional) Storage for output image. Must be the width and height of the image being read. Better performance of type BufferedImage.TYPE_BYTE_GRAY. If null or width/height incorrect a new image will be declared.- Returns:
- The image
- Throws:
IOException- Thrown if there is a problem reading the image
-
loadPPM
public static BufferedImage loadPPM(InputStream inputStream, @Nullable @Nullable BufferedImage storage) throws IOException Loads a PPM image from anInputStream.- Parameters:
inputStream- InputStream for PPM imagestorage- (Optional) Storage for output image. Must be the width and height of the image being read. Better performance of type BufferedImage.TYPE_INT_RGB. If null or width/height incorrect a new image will be declared.- Returns:
- The read in image
- Throws:
IOException- Thrown if there is a problem reading the image
-
loadPGM
public static BufferedImage loadPGM(InputStream inputStream, @Nullable @Nullable BufferedImage storage) throws IOException Loads a PGM image from anInputStream.- Parameters:
inputStream- InputStream for PGM imagestorage- (Optional) Storage for output image. Must be the width and height of the image being read. Better performance of type BufferedImage.TYPE_BYTE_GRAY. If null or width/height incorrect a new image will be declared.- Returns:
- The read in image
- Throws:
IOException
-
loadPPM_U8
public static Planar<GrayU8> loadPPM_U8(String fileName, Planar<GrayU8> storage, DogArray_I8 temp) throws IOException Reads a PPM image file directly into a Planarimage. To improve performance when reading many images, the user can provide work space memory in the optional parameters - Parameters:
fileName- Location of PPM filestorage- (Optional) Where the image is written in to. Will be resized if needed. If null or the number of bands isn't 3, a new instance is declared.temp- (Optional) Used internally to store the image. Can be null.- Returns:
- The image.
- Throws:
IOException- Thrown if there is a problem reading the image
-
loadPPM_U8
public static Planar<GrayU8> loadPPM_U8(InputStream inputStream, Planar<GrayU8> storage, DogArray_I8 temp) throws IOException Reads a PPM image file directly into a Planarimage. To improve performance when reading many images, the user can provide work space memory in the optional parameters - Parameters:
inputStream- InputStream for PPM imagestorage- (Optional) Where the image is written in to. Will be resized if needed. If null or the number of bands isn't 3, a new instance is declared.temp- (Optional) Used internally to store the image. Can be null.- Returns:
- The image.
- Throws:
IOException- Thrown if there is a problem reading the image
-
loadPGM_U8
public static GrayU8 loadPGM_U8(String fileName, @Nullable @Nullable GrayU8 storage) throws IOException Loads a PGM image from anInputStream.- Parameters:
fileName- InputStream for PGM imagestorage- (Optional) Storage for output image. Must be the width and height of the image being read. If null a new image will be declared.- Returns:
- The read in image
- Throws:
IOException- Thrown if there is a problem reading the image
-
loadPGM_U8
public static GrayU8 loadPGM_U8(InputStream inputStream, @Nullable @Nullable GrayU8 storage) throws IOException Loads a PGM image from anInputStream.- Parameters:
inputStream- InputStream for PGM imagestorage- (Optional) Storage for output image. Must be the width and height of the image being read. If null a new image will be declared.- Returns:
- The read in image
- Throws:
IOException- Thrown if there is a problem reading the image
-
savePPM
public static void savePPM(Planar<GrayU8> rgb, String fileName, @Nullable @Nullable DogArray_I8 temp) throws IOException Saves an image in PPM format.- Parameters:
rgb- 3-band RGB imagefileName- Location where the image is to be written to.temp- (Optional) Used internally to store the image. Can be null.- Throws:
IOException- Thrown if there is a problem reading the image
-
savePGM
Saves an image in PGM format.- Parameters:
gray- Gray scale imagefileName- Location where the image is to be written to.- Throws:
IOException- Thrown if there is a problem reading the image
-
saveLabeledRle
Saves a labeled image in a RLE format.- Parameters:
labeled- (Input) Labeled image to savefileName- (Input) Location where the image is to be written to.- Throws:
IOException- Thrown if there is a problem reading the image- See Also:
-
loadLabeledRle
public static GrayS32 loadLabeledRle(String fileName, @Nullable @Nullable GrayS32 labeled) throws IOException Loads a labeled image in a RLE format.- Parameters:
fileName- Location where the image is to be read from.labeled- (Input) Optional storage for loaded labeled image- Throws:
IOException- Thrown if there is a problem reading the image- See Also:
-
isImage
Uses mime type to determine if it's an image or not. If mime fails it will look at the suffix. This isn't 100% correct. -
videoToImages
Converts a video into a sequence of png images. If the output does not exist a directory will be created.- Parameters:
pathVideo- Path to videopathOutput- Path to destination
-