Package boofcv.io.image
Class ConvertBufferedImage
java.lang.Object
boofcv.io.image.ConvertBufferedImage
Functions for converting to and from
BufferedImage.-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic BufferedImagecheckCopy(BufferedImage original, @Nullable BufferedImage output) Copies the original image into the output image.static BufferedImagecheckDeclare(int width, int height, @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.static BufferedImagecheckDeclare(BufferedImage template, BufferedImage target) static BufferedImagecheckInputs(ImageBase src, @Nullable BufferedImage dst) If null the dst is declared, otherwise it checks to see if the 'dst' as the same shape as 'src'.static <T extends ImageBase<T>>
TconvertFrom(BufferedImage src, boolean orderRgb, ImageType<T> imageType) Converts a buffered image into an image of the specified type.static <T extends ImageBase<T>>
TconvertFrom(BufferedImage src, boolean orderRgb, T output) static GrayF32convertFrom(BufferedImage src, @Nullable GrayF32 dst) Converts the buffered image into anGrayF32.static GrayU8convertFrom(BufferedImage src, @Nullable GrayU8 dst) Converts the buffered image into anGrayU8.static <T extends ImageBase<T>>
TconvertFrom(BufferedImage src, Class type, boolean orderRgb) static <T extends ImageBase<T>>
voidconvertFrom(BufferedImage src, T dst, boolean orderRgb) Converts a buffered image into an image of the specified type.static <T extends GrayI16<T>>
TconvertFrom(BufferedImage src, T dst, Class<T> type) Converts the buffered image into anGrayI16.static voidconvertFromInterleaved(BufferedImage src, ImageInterleaved dst, boolean orderRgb) convertFromPlanar(BufferedImage src, @Nullable Planar<T> dst, boolean orderRgb, Class<T> type) Converts the buffered image into anPlanarimage of the specified ype.static <T extends ImageGray<T>>
TconvertFromSingle(BufferedImage src, T dst, Class<T> type) Converts a buffered image into an image of the specified type.static BufferedImageconvertTo(GrayF32 src, @Nullable BufferedImage dst) Converts the buffered image into anGrayF32.static BufferedImageconvertTo(GrayI16 src, @Nullable BufferedImage dst) Converts aGrayI16into a BufferedImage.static BufferedImageconvertTo(GrayU8 src, @Nullable BufferedImage dst) Converts aGrayU8into a BufferedImage.static BufferedImageconvertTo(ImageBase src, @Nullable BufferedImage dst, boolean orderRgb) Converts an image into a BufferedImage.static BufferedImageconvertTo(InterleavedF32 src, @Nullable BufferedImage dst, boolean orderRgb) static BufferedImageconvertTo(InterleavedU8 src, @Nullable BufferedImage dst, boolean orderRgb) static BufferedImageconvertTo(JComponent comp, @Nullable BufferedImage storage) Draws the component into a BufferedImage.static BufferedImageconvertTo_F32(Planar<GrayF32> src, @Nullable BufferedImage dst, boolean orderRgb) static BufferedImageconvertTo_U8(Planar<GrayU8> src, @Nullable BufferedImage dst, boolean orderRgb) static BufferedImageextractBuffered(GrayU8 img) Creates a new BufferedImage that internally uses the same data as the provided GrayU8.static BufferedImageCreates a new BufferedImage that internally uses the same data as the providedInterleavedU8.static GrayU8For BufferedImage stored as a byte array internally it extracts an image.static InterleavedU8For BufferedImage stored as a byte array internally it extracts an interleaved image.static booleanisSubImage(BufferedImage img) Checks to see if the input image is a subImage().static intnumChannels(BufferedImage image) Returns the number of bands or channels that the BoofCV image needs to have for this iamge typestatic PlanarorderBandsIntoBuffered(Planar src, BufferedImage dst) Returns a new image with the color bands in the appropriate ordering.static BufferedImagestripAlphaChannel(BufferedImage image) Returns an image which doesn't have an alpha channel.
-
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
-
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 imageoutput- (Optional) Storage for copy.- Returns:
- The copied image. May be a new instance
-
numChannels
Returns the number of bands or channels that the BoofCV image needs to have for this iamge type -
stripAlphaChannel
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
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
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
Creates a new BufferedImage that internally uses the same data as the providedInterleavedU8. 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
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
Converts a buffered image into an image of the specified type.- Parameters:
src- Input BufferedImage which is to be converteddst- The image which it is being converted intoorderRgb- 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 convertedorderRgb- If applicable, should it adjust the ordering of each color band to maintain color consistencyimageType- Type of image it is to be converted into- Returns:
- The image
-
convertFrom
-
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
Converts the buffered image into anGrayU8. 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 anGrayI16. 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
Converts the buffered image into anGrayF32. 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 anPlanarimage 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
Converts aGrayU8into 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
Converts aGrayI16into 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
Converts the buffered image into anGrayF32. 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) - 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) - 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
If null the dst is declared, otherwise it checks to see if the 'dst' as the same shape as 'src'. -
convertTo
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
Returns a new image with the color bands in the appropriate ordering. The returned image will reference the original image's image arrays. -
isSubImage
Checks to see if the input image is a subImage().
-