Class ConvertBufferedImage

java.lang.Object
boofcv.io.image.ConvertBufferedImage

public class ConvertBufferedImage extends Object
Functions for converting to and from BufferedImage.
  • Constructor Details

    • ConvertBufferedImage

      public ConvertBufferedImage()
  • Method Details

    • checkDeclare

      public static BufferedImage checkDeclare(int width, int height, @Nullable @Nullable BufferedImage image, int type)
      If the provided image does not have the same shape and same type a new one is declared and returned.
    • checkDeclare

      public static BufferedImage checkDeclare(BufferedImage template, BufferedImage target)
    • checkCopy

      public static BufferedImage checkCopy(BufferedImage original, @Nullable @Nullable BufferedImage output)
      Copies the original image into the output image. If it can't do a copy a new image is created and returned
      Parameters:
      original - Original image
      output - (Optional) Storage for copy.
      Returns:
      The copied image. May be a new instance
    • numChannels

      public static int numChannels(BufferedImage image)
      Returns the number of bands or channels that the BoofCV image needs to have for this iamge type
    • stripAlphaChannel

      public static BufferedImage stripAlphaChannel(BufferedImage image)
      Returns an image which doesn't have an alpha channel. If the input image doesn't have an alpha channel to start then its returned as is. Otherwise a new image is created and the RGB channels are copied and the new image returned.
      Parameters:
      image - Input image
      Returns:
      Image without an alpha channel
    • extractInterleavedU8

      public static InterleavedU8 extractInterleavedU8(BufferedImage img)
      For BufferedImage stored as a byte array internally it extracts an interleaved image. The input image and the returned image will both share the same internal data array. Using this function allows unnecessary memory copying to be avoided.
      Parameters:
      img - Image whose internal data is extracted and wrapped.
      Returns:
      An image whose internal data is the same as the input image.
    • extractGrayU8

      public static GrayU8 extractGrayU8(BufferedImage img)
      For BufferedImage stored as a byte array internally it extracts an image. The input image and the returned image will both share the same internal data array. Using this function allows unnecessary memory copying to be avoided.
      Parameters:
      img - Image whose internal data is extracted and wrapped.
      Returns:
      An image whose internal data is the same as the input image.
    • extractBuffered

      public static BufferedImage extractBuffered(InterleavedU8 img)
      Creates a new BufferedImage that internally uses the same data as the provided InterleavedU8. If 3 bands then the image will be of type TYPE_3BYTE_BGR or if 1 band TYPE_BYTE_GRAY.
      Parameters:
      img - Input image who's data will be wrapped by the returned BufferedImage.
      Returns:
      BufferedImage which shared data with the input image.
    • extractBuffered

      public static BufferedImage extractBuffered(GrayU8 img)

      Creates a new BufferedImage that internally uses the same data as the provided GrayU8. The returned BufferedImage will be of type TYPE_BYTE_GRAY.

      NOTE: This only works on images which are not subimages!

      Parameters:
      img - Input image who's data will be wrapped by the returned BufferedImage.
      Returns:
      BufferedImage which shared data with the input image.
    • convertFrom

      public static <T extends ImageBase<T>> void convertFrom(BufferedImage src, T dst, boolean orderRgb)
      Converts a buffered image into an image of the specified type.
      Parameters:
      src - Input BufferedImage which is to be converted
      dst - The image which it is being converted into
      orderRgb - If applicable, should it adjust the ordering of each color band to maintain color consistency
    • convertFrom

      public static <T extends ImageBase<T>> T convertFrom(BufferedImage src, boolean orderRgb, ImageType<T> imageType)
      Converts a buffered image into an image of the specified type.
      Parameters:
      src - Input BufferedImage which is to be converted
      orderRgb - If applicable, should it adjust the ordering of each color band to maintain color consistency
      imageType - Type of image it is to be converted into
      Returns:
      The image
    • convertFrom

      public static <T extends ImageBase<T>> T convertFrom(BufferedImage src, boolean orderRgb, T output)
    • convertFromSingle

      public static <T extends ImageGray<T>> T convertFromSingle(BufferedImage src, @Nullable T dst, Class<T> type)
      Converts a buffered image into an image of the specified type. In a 'dst' image is provided it will be used for output, otherwise a new image will be created.
    • convertFrom

      public static GrayU8 convertFrom(BufferedImage src, @Nullable @Nullable GrayU8 dst)
      Converts the buffered image into an GrayU8. If the buffered image has multiple channels the intensities of each channel are averaged together.
      Parameters:
      src - Input image.
      dst - Where the converted image is written to. If null a new unsigned image is created.
      Returns:
      Converted image.
    • convertFrom

      public static <T extends GrayI16<T>> T convertFrom(BufferedImage src, @Nullable T dst, Class<T> type)
      Converts the buffered image into an GrayI16. If the buffered image has multiple channels the intensities of each channel are averaged together.
      Parameters:
      src - Input image.
      dst - Where the converted image is written to. If null a new unsigned image is created.
      Returns:
      Converted image.
    • convertFrom

      public static GrayF32 convertFrom(BufferedImage src, @Nullable @Nullable GrayF32 dst)
      Converts the buffered image into an GrayF32. If the buffered image has multiple channels the intensities of each channel are averaged together.
      Parameters:
      src - Input image.
      dst - Where the converted image is written to. If null a new unsigned image is created.
      Returns:
      Converted image.
    • convertFromPlanar

      public static <T extends ImageGray<T>> Planar<T> convertFromPlanar(BufferedImage src, @Nullable @Nullable Planar<T> dst, boolean orderRgb, Class<T> type)
      Converts the buffered image into an Planar image of the specified ype.
      Parameters:
      src - Input image. Not modified.
      dst - Output. The converted image is written to. If null a new unsigned image is created.
      orderRgb - If applicable, should it adjust the ordering of each color band to maintain color consistency. Most of the time you want this to be true.
      type - Which type of data structure is each band. (GrayU8 or GrayF32)
      Returns:
      Converted image.
    • convertFrom

      public static <T extends ImageBase<T>> T convertFrom(BufferedImage src, Class type, boolean orderRgb)
    • convertFromInterleaved

      public static void convertFromInterleaved(BufferedImage src, ImageInterleaved dst, boolean orderRgb)
    • convertTo

      public static BufferedImage convertTo(ImageBase src, @Nullable @Nullable BufferedImage dst, boolean orderRgb)

      Converts an image into a BufferedImage. The best way to think of this function is that it's a mindless typecast. If you don't provide an output image then it will create one. However there isn't always a direct equivalent between a BoofCV image and BufferedImage internal type. A "reasonable" choice will be made, but for your application it might not be a good choice.

      Parameters:
      src - Input image. Pixels must have a value from 0 to 255.
      dst - Where the converted image is written to. If null a new image is created. See comment above about type.
      orderRgb - If applicable, should it change the order of the color bands (assumed RGB or ARGB) into the order based on BufferedImage.TYPE. Most of the time you want this to be true.
      Returns:
      Converted image.
    • convertTo

      public static BufferedImage convertTo(GrayU8 src, @Nullable @Nullable BufferedImage dst)
      Converts a GrayU8 into a BufferedImage. If the buffered image has multiple channels then the input image is copied into each channel.
      Parameters:
      src - Input image.
      dst - Where the converted image is written to. If null a new image is created.
      Returns:
      Converted image.
    • convertTo

      public static BufferedImage convertTo(GrayI16 src, @Nullable @Nullable BufferedImage dst)
      Converts a GrayI16 into a BufferedImage. If the buffered image has multiple channels then the input image is copied into each channel.
      Parameters:
      src - Input image.
      dst - Where the converted image is written to. If null a new image is created.
      Returns:
      Converted image.
    • convertTo

      public static BufferedImage convertTo(GrayF32 src, @Nullable @Nullable BufferedImage dst)
      Converts the buffered image into an GrayF32. If the buffered image has multiple channels then the input image is copied into each channel. The floating point image is assumed to be between 0 and 255.
      Parameters:
      src - Input image.
      dst - Where the converted image is written to. If null a new image is created.
      Returns:
      Converted image.
    • convertTo_U8

      public static BufferedImage convertTo_U8(Planar<GrayU8> src, @Nullable @Nullable BufferedImage dst, boolean orderRgb)
      Converts a Planar GrayU8 into a BufferedImage.
      Parameters:
      src - Input image.
      dst - Where the converted image is written to. If null a new image is created.
      orderRgb - If applicable, should it change the order of the color bands (assumed RGB or ARGB) into the order based on BufferedImage.TYPE. Most of the time you want this to be true.
      Returns:
      Converted image.
    • convertTo_F32

      public static BufferedImage convertTo_F32(Planar<GrayF32> src, @Nullable @Nullable BufferedImage dst, boolean orderRgb)
      Converts a Planar GrayF32 into a BufferedImage.
      Parameters:
      src - Input image.
      dst - Where the converted image is written to. If null a new image is created.
      orderRgb - If applicable, should it change the order of the color bands (assumed RGB or ARGB) into the order based on BufferedImage.TYPE. Most of the time you want this to be true.
      Returns:
      Converted image.
    • convertTo

      public static BufferedImage convertTo(InterleavedU8 src, @Nullable @Nullable BufferedImage dst, boolean orderRgb)
    • convertTo

      public static BufferedImage convertTo(InterleavedF32 src, @Nullable @Nullable BufferedImage dst, boolean orderRgb)
    • checkInputs

      public static BufferedImage checkInputs(ImageBase src, @Nullable @Nullable BufferedImage dst)
      If null the dst is declared, otherwise it checks to see if the 'dst' as the same shape as 'src'.
    • convertTo

      public static BufferedImage convertTo(JComponent comp, @Nullable @Nullable BufferedImage storage)
      Draws the component into a BufferedImage.
      Parameters:
      comp - The component being drawn into an image.
      storage - if not null the component is drawn into it, if null a new BufferedImage is created.
      Returns:
      image of the component
    • orderBandsIntoBuffered

      public static Planar orderBandsIntoBuffered(Planar src, BufferedImage dst)
      Returns a new image with the color bands in the appropriate ordering. The returned image will reference the original image's image arrays.
    • isSubImage

      public static boolean isSubImage(BufferedImage img)
      Checks to see if the input image is a subImage().