Class UtilImageIO

java.lang.Object
boofcv.io.image.UtilImageIO

public class UtilImageIO extends Object
Class for loading and saving images.
  • Field Details

    • IMAGE_SUFFIXES

      public static final String[] IMAGE_SUFFIXES
      List of supported image types
  • Constructor Details

    • UtilImageIO

      public UtilImageIO()
  • Method Details

    • isKnownSuffix

      public static boolean isKnownSuffix(String suffix)
    • loadImage

      @Nullable public static @Nullable BufferedImage loadImage(String fileName)
      A function that load the specified image. If anything goes wrong it returns a null.
    • loadImageNotNull

      public static BufferedImage loadImageNotNull(String fileName)
    • loadImage

      @Nullable public static @Nullable BufferedImage loadImage(String directory, String fileName)
    • loadImageNotNull

      public static BufferedImage loadImageNotNull(String directory, String fileName)
    • loadImages

      public static List<BufferedImage> loadImages(String directory, String regex)
      Loads all the image in the specified directory which match the provided regex
      Parameters:
      directory - File directory
      regex - Regex used to match file names
      Returns:
      List of found images.
    • loadImage

      @Nullable public static @Nullable BufferedImage loadImage(@Nullable @Nullable URL url)
      A function that load the specified image. If anything goes wrong it returns a null.
    • loadImage

      @Nullable public static <T extends ImageGray<T>> T loadImage(String fileName, Class<T> imageType)
      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

      @Nullable public static <T extends ImageGray<T>> T loadImage(String directory, String fileName, Class<T> imageType)
    • loadImage

      @Nullable public static <T extends ImageBase<T>> T loadImage(File image, boolean orderRgb, ImageType<T> imageType)
    • loadImage

      @Nullable public static <T extends ImageBase<T>> T loadImage(String imagePath, boolean orderRgb, T output)
    • saveImage

      public static void saveImage(BufferedImage img, String fileName)
      Saves the BufferedImage to the specified file. The image type of the output is determined by the name's extension. By default the file is saved using ImageIO.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

      public static void saveJpeg(BufferedImage img, String path, double quality)
      Saves a jpeg image to disk with an adjustable quality setting.
      Parameters:
      img - Image that's to be saved
      path - Where it should save the image
      quality - 0 to 1.0. 0 = lowest quality and 1.0 = best quality.
    • saveImage

      public static void saveImage(ImageBase<?> image, String fileName)

      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

      public static BufferedImage loadPPM(String fileName, BufferedImage storage) throws IOException
      Loads a PPM image from a file.
      Parameters:
      fileName - Location of PPM image
      storage - (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(String fileName, BufferedImage storage) throws IOException
      Loads a PGM image from a file.
      Parameters:
      fileName - Location of PGM image
      storage - (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 an InputStream.
      Parameters:
      inputStream - InputStream for PPM image
      storage - (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 an InputStream.
      Parameters:
      inputStream - InputStream for PGM image
      storage - (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 Planar image. To improve performance when reading many images, the user can provide work space memory in the optional parameters
      Parameters:
      fileName - Location of PPM file
      storage - (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 Planar image. To improve performance when reading many images, the user can provide work space memory in the optional parameters
      Parameters:
      inputStream - InputStream for PPM image
      storage - (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 an InputStream.
      Parameters:
      fileName - InputStream for PGM image
      storage - (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 an InputStream.
      Parameters:
      inputStream - InputStream for PGM image
      storage - (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 image
      fileName - 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

      public static void savePGM(GrayU8 gray, String fileName) throws IOException
      Saves an image in PGM format.
      Parameters:
      gray - Gray scale image
      fileName - Location where the image is to be written to.
      Throws:
      IOException - Thrown if there is a problem reading the image
    • saveLabeledRle

      public static void saveLabeledRle(GrayS32 labeled, String fileName) throws IOException
      Saves a labeled image in a RLE format.
      Parameters:
      labeled - (Input) Labeled image to save
      fileName - (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

      public static boolean isImage(File file)
      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

      public static void videoToImages(String pathVideo, String pathOutput)
      Converts a video into a sequence of png images. If the output does not exist a directory will be created.
      Parameters:
      pathVideo - Path to video
      pathOutput - Path to destination