Package org.aoju.bus.image.nimble.opencv
Class ImageConversion
java.lang.Object
org.aoju.bus.image.nimble.opencv.ImageConversion
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic BufferedImagestatic BufferedImageconvertTo(RenderedImage src, int imageType) static intconvertToDataType(int cvType) static RenderedImageBug fix: CLibImageReader and J2KImageReaderCodecLib (imageio libs) do not handle negative values for short data.static RectanglegetBounds(PlanarImage img) static byte[]getPackedBinaryData(Raster raster, Rectangle rect) For the case of binary data (isBinary()returnstrue), return the binary data as a packed byte array.static byte[]getUnpackedBinaryData(Raster raster, Rectangle rect) Returns the binary data unpacked into an array of bytes.static booleanisBinary(SampleModel sm) static voidreleaseMat(org.opencv.core.Mat mat) static voidstatic voidsetPackedBinaryData(byte[] binaryDataArray, WritableRaster raster, Rectangle rect) Sets the suppliedRaster's data from an array of packed binary data of the form returned bygetPackedBinaryData().static voidsetUnpackedBinaryData(byte[] bdata, WritableRaster raster, Rectangle rect) Copies data into the packed array of theRasterfrom an array of unpacked data of the form returned bygetUnpackedBinaryData().static BufferedImagetoBufferedImage(PlanarImage matrix) static BufferedImagetoBufferedImage(org.opencv.core.Mat matrix) Converts/writes a Mat into a BufferedImage.static ImageCVtoMat(RenderedImage img) static ImageCVtoMat(RenderedImage img, Rectangle region) static ImageCVtoMat(RenderedImage img, Rectangle region, boolean toBGR)
-
Constructor Details
-
ImageConversion
public ImageConversion()
-
-
Method Details
-
toBufferedImage
Converts/writes a Mat into a BufferedImage.- Parameters:
matrix- the mat- Returns:
- BufferedImage
-
toBufferedImage
-
releaseMat
public static void releaseMat(org.opencv.core.Mat mat) -
releasePlanarImage
-
convertToDataType
public static int convertToDataType(int cvType) -
toMat
-
toMat
-
toMat
-
getBounds
-
convertTo
-
isBinary
-
getPackedBinaryData
For the case of binary data (isBinary()returnstrue), 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 bygetHeight()- Parameters:
raster- the Rasterrect- the Rectangle- Returns:
- the binary data as a packed array of bytes with zero offset of
nullif the data are not binary. - Throws:
IllegalArgumentException- ifisBinary()returnsfalsewith theSampleModelof the suppliedRasteras argument.
-
getUnpackedBinaryData
Returns the binary data unpacked into an array of bytes. The line stride will be the width of theRaster.- Parameters:
raster- the Rasterrect- the Rectangle- Returns:
- the binary data as a packed array of bytes with zero offset of
nullif the data are not binary. - Throws:
IllegalArgumentException- ifisBinary()returnsfalsewith theSampleModelof the suppliedRasteras argument.
-
setPackedBinaryData
public static void setPackedBinaryData(byte[] binaryDataArray, WritableRaster raster, Rectangle rect) Sets the suppliedRaster's data from an array of packed binary data of the form returned bygetPackedBinaryData().- Parameters:
binaryDataArray- the byteraster- the WritableRasterrect- the Rectangle- Throws:
IllegalArgumentException- ifisBinary()returnsfalsewith theSampleModelof the suppliedRasteras argument.
-
setUnpackedBinaryData
Copies data into the packed array of theRasterfrom an array of unpacked data of the form returned bygetUnpackedBinaryData().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 byteraster- the WritableRasterrect- the Rectangle- Throws:
IllegalArgumentException- ifisBinary()returnsfalsewith theSampleModelof the suppliedRasteras argument.
-
fixSignedShortDataBuffer
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
-