Class ImageConversion

java.lang.Object
org.aoju.bus.image.nimble.opencv.ImageConversion

public class ImageConversion extends Object
Since:
Java 17+
Author:
Kimi Liu
  • Constructor Details

    • ImageConversion

      public ImageConversion()
  • Method Details

    • toBufferedImage

      public static BufferedImage toBufferedImage(org.opencv.core.Mat matrix)
      Converts/writes a Mat into a BufferedImage.
      Parameters:
      matrix - the mat
      Returns:
      BufferedImage
    • toBufferedImage

      public static BufferedImage toBufferedImage(PlanarImage matrix)
    • releaseMat

      public static void releaseMat(org.opencv.core.Mat mat)
    • releasePlanarImage

      public static void releasePlanarImage(PlanarImage img)
    • convertToDataType

      public static int convertToDataType(int cvType)
    • toMat

      public static ImageCV toMat(RenderedImage img)
    • toMat

      public static ImageCV toMat(RenderedImage img, Rectangle region)
    • toMat

      public static ImageCV toMat(RenderedImage img, Rectangle region, boolean toBGR)
    • getBounds

      public static Rectangle getBounds(PlanarImage img)
    • convertTo

      public static BufferedImage convertTo(RenderedImage src, int imageType)
    • isBinary

      public static boolean isBinary(SampleModel sm)
    • getPackedBinaryData

      public static byte[] getPackedBinaryData(Raster raster, Rectangle rect)
      For the case of binary data (isBinary() returns true), return the binary data as a packed byte array. The data will be packed as eight bits per byte with no bit offset, i.e., the first bit in each image line will be the left-most of the first byte of the line. The line stride in bytes will be (int)((getWidth()+7)/8). The length of the returned array will be the line stride multiplied by getHeight()
      Parameters:
      raster - the Raster
      rect - the Rectangle
      Returns:
      the binary data as a packed array of bytes with zero offset of null if the data are not binary.
      Throws:
      IllegalArgumentException - if isBinary() returns false with the SampleModel of the supplied Raster as argument.
    • getUnpackedBinaryData

      public static byte[] getUnpackedBinaryData(Raster raster, Rectangle rect)
      Returns the binary data unpacked into an array of bytes. The line stride will be the width of the Raster.
      Parameters:
      raster - the Raster
      rect - the Rectangle
      Returns:
      the binary data as a packed array of bytes with zero offset of null if the data are not binary.
      Throws:
      IllegalArgumentException - if isBinary() returns false with the SampleModel of the supplied Raster as argument.
    • setPackedBinaryData

      public static void setPackedBinaryData(byte[] binaryDataArray, WritableRaster raster, Rectangle rect)
      Sets the supplied Raster's data from an array of packed binary data of the form returned by getPackedBinaryData().
      Parameters:
      binaryDataArray - the byte
      raster - the WritableRaster
      rect - the Rectangle
      Throws:
      IllegalArgumentException - if isBinary() returns false with the SampleModel of the supplied Raster as argument.
    • setUnpackedBinaryData

      public static void setUnpackedBinaryData(byte[] bdata, WritableRaster raster, Rectangle rect)
      Copies data into the packed array of the Raster from an array of unpacked data of the form returned by getUnpackedBinaryData().

      If the data are binary, then the target bit will be set if and only if the corresponding byte is non-zero.

      Parameters:
      bdata - the byte
      raster - the WritableRaster
      rect - the Rectangle
      Throws:
      IllegalArgumentException - if isBinary() returns false with the SampleModel of the supplied Raster as argument.
    • fixSignedShortDataBuffer

      public static RenderedImage fixSignedShortDataBuffer(RenderedImage source)
      Bug fix: CLibImageReader and J2KImageReaderCodecLib (imageio libs) do not handle negative values for short data. They convert signed short to unsigned short.
      Parameters:
      source - the RenderedImage
      Returns:
      the RenderedImage
    • convertRenderedImage

      public static BufferedImage convertRenderedImage(RenderedImage img)