Class Matrix2BufferedImage


  • public abstract class Matrix2BufferedImage
    extends Object
    This is an abstract class which is designed to convert a given matrix into a BufferedImage.
    The methods below are inspired from Tom Gibara's implementation of Canny Edge Detection > readLuminance().
    See his code here.
    Note: This class follows the convention of reading/writing matrices in a row-by-row fashion.
    Author:
    Azim Ahmadzadeh, Data Mining Lab, Georgia State University
    • Constructor Detail

      • Matrix2BufferedImage

        public Matrix2BufferedImage()
    • Method Detail

      • getBufferedImage

        public static BufferedImage getBufferedImage​(double[][] matrix)
                                              throws org.apache.commons.math3.exception.NullArgumentException
        This method converts a matrix of double values to a bufferedImage, using setRGB method. If the give values are outside of the acceptable range (i.e., [0,255]), it throws an exception and returns null.
        The BufferedImage will be created with the default image type TYPE_BYTE_GRAY. If the image type needs to be specified, use getBufferedImage(double[][]).
        Parameters:
        matrix - to be converted to a BufferedImage object.
        Returns:
        The BufferedImage constructed based on the given matrix.
        Throws:
        org.apache.commons.math3.exception.NullArgumentException
      • getBufferedImage

        public static BufferedImage getBufferedImage​(double[][] matrix,
                                                     int imageType)
                                              throws org.apache.commons.math3.exception.NullArgumentException
        This method converts a matrix of double values to a BufferedImage, using setRGB method. If the give values are outside of the acceptable range (i.e., [0,255]), it throws an exception and returns.
        Parameters:
        matrix - to be converted to a BufferedImage object.
        imageType - type of the bufferedImage. Acceptable choices are: BufferedImage.TYPE_INT_ARGB, BufferedImage.TYPE_INT_RGB, BufferedImage.TYPE_BYTE_GRAY .
        Returns:
        The BufferedImage constructed based on the given matrix.
        Throws:
        org.apache.commons.math3.exception.NullArgumentException -
        Note: It is recommended to use "TYPE_INT_RGB" in case of jp2 format, and "TYPE_3BYTE_BGR" in case of jpg format.