Package boofcv.io.image
Class UtilImageIO
java.lang.Object
boofcv.io.image.UtilImageIO
public class UtilImageIO extends Object
Class for loading and saving images.
-
Field Summary
Fields Modifier and Type Field Description static String[]
IMAGE_SUFFIXES
List of supported image types -
Constructor Summary
Constructors Constructor Description UtilImageIO()
-
Method Summary
Modifier and Type Method Description static boolean
isImage(File file)
Uses mime type to determine if it's an image or not.static boolean
isKnownSuffix(String suffix)
static @Nullable BufferedImage
loadImage(@Nullable URL url)
A function that load the specified image.static <T extends ImageBase<T>>
TloadImage(File image, boolean orderRgb, ImageType<T> imageType)
static @Nullable BufferedImage
loadImage(String fileName)
A function that load the specified image.static <T extends ImageBase<T>>
TloadImage(String imagePath, boolean orderRgb, T output)
static <T extends ImageGray<T>>
TloadImage(String fileName, Class<T> imageType)
Loads the image and converts into the specified image type.static @Nullable BufferedImage
loadImage(String directory, String fileName)
static <T extends ImageGray<T>>
TloadImage(String directory, String fileName, Class<T> imageType)
static BufferedImage
loadImageNotNull(String fileName)
static BufferedImage
loadImageNotNull(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 GrayS32
loadLabeledRle(String fileName, @Nullable GrayS32 labeled)
Loads a labeled image in a RLE format.static BufferedImage
loadPGM(InputStream inputStream, @Nullable BufferedImage storage)
Loads a PGM image from anInputStream
.static BufferedImage
loadPGM(String fileName, BufferedImage storage)
Loads a PGM image from a file.static GrayU8
loadPGM_U8(InputStream inputStream, @Nullable GrayU8 storage)
Loads a PGM image from anInputStream
.static GrayU8
loadPGM_U8(String fileName, @Nullable GrayU8 storage)
Loads a PGM image from anInputStream
.static BufferedImage
loadPPM(InputStream inputStream, @Nullable BufferedImage storage)
Loads a PPM image from anInputStream
.static BufferedImage
loadPPM(String fileName, BufferedImage storage)
Loads a PPM image from a file.static Planar<GrayU8>
loadPPM_U8(InputStream inputStream, Planar<GrayU8> storage, DogArray_I8 temp)
Reads a PPM image file directly into a Planarimage. static Planar<GrayU8>
loadPPM_U8(String fileName, Planar<GrayU8> storage, DogArray_I8 temp)
Reads a PPM image file directly into a Planarimage. static void
saveImage(ImageBase<?> image, String fileName)
Saves the BoofCV formatted image.static void
saveImage(BufferedImage img, String fileName)
Saves theBufferedImage
to the specified file.static void
saveLabeledRle(GrayS32 labeled, String fileName)
Saves a labeled image in a RLE format.static void
savePGM(GrayU8 gray, String fileName)
Saves an image in PGM format.static void
savePPM(Planar<GrayU8> rgb, String fileName, @Nullable DogArray_I8 temp)
Saves an image in PPM format.
-
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 theBufferedImage
to 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.
-
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 IOExceptionLoads 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 IOExceptionLoads 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 IOExceptionReads 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 IOExceptionReads 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 IOExceptionLoads 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 IOExceptionLoads 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 IOExceptionSaves 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:
LabeledImageRleCodec
-
loadLabeledRle
public static GrayS32 loadLabeledRle(String fileName, @Nullable @Nullable GrayS32 labeled) throws IOExceptionLoads 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:
LabeledImageRleCodec
-
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.
-