Class ImageUtil


  • public class ImageUtil
    extends Object
    Image utilities
    • Field Detail

      • DEFAULT_IMAGE_TYPE

        public static String DEFAULT_IMAGE_TYPE
        Default image type in case not provided
    • Method Detail

      • generateRandomImage

        public static ImageHolder generateRandomImage​(int numOfPixels)
                                               throws OpenStegoException
        Method to generate a random image filled with noise.
        Parameters:
        numOfPixels - Number of pixels required in the image
        Returns:
        Random image filled with noise
        Throws:
        OpenStegoException
      • imageToByteArray

        public static byte[] imageToByteArray​(ImageHolder image,
                                              String imageFileName,
                                              OpenStegoPlugin plugin)
                                       throws OpenStegoException
        Method to convert BufferedImage to byte array
        Parameters:
        image - Image data
        imageFileName - Name of the image file
        plugin - Reference to the plugin
        Returns:
        Image data as byte array
        Throws:
        OpenStegoException
      • byteArrayToImage

        public static ImageHolder byteArrayToImage​(byte[] imageData,
                                                   String imgFileName)
                                            throws OpenStegoException
        Method to convert byte array to image
        Parameters:
        imageData - Image data as byte array
        imgFileName - Name of the image file
        Returns:
        Buffered image
        Throws:
        OpenStegoException
      • getRgbFromImage

        public static List<int[][]> getRgbFromImage​(BufferedImage image)
        Get RGB data array from given image
        Parameters:
        image - Image
        Returns:
        List with three elements of two-dimensional int's - R, G and B
      • getYuvFromImage

        public static List<int[][]> getYuvFromImage​(BufferedImage image)
        Get YUV data from given image's RGB data
        Parameters:
        image - Image
        Returns:
        List with three elements of two-dimensional int's - Y, U and V
      • getImageFromRgb

        public static BufferedImage getImageFromRgb​(List<int[][]> rgb)
        Get image from given RGB data
        Parameters:
        rgb - List with three elements of two-dimensional int's - R, G and B
        Returns:
        Image
      • getImageFromYuv

        public static BufferedImage getImageFromYuv​(List<int[][]> yuv,
                                                    int imgType)
        Get image (with RGB data) from given YUV data
        Parameters:
        yuv - List with three elements of two-dimensional int's - Y, U and V
        imgType - Type of image (e.g. BufferedImage.TYPE_INT_RGB)
        Returns:
        Image
      • pixelRange

        public static int pixelRange​(int p)
        Utility method to limit the value within [0,255] range
        Parameters:
        p - Input value
        Returns:
        Limited value
      • pixelRange

        public static int pixelRange​(double p)
        Utility method to limit the value within [0,255] range
        Parameters:
        p - Input value
        Returns:
        Limited value
      • makeImageSquare

        public static void makeImageSquare​(ImageHolder image)
        Method to pad an image such that it becomes perfect square. The padding uses black color
        Parameters:
        image - Input image
      • cropImage

        public static void cropImage​(ImageHolder image,
                                     int cropWidth,
                                     int cropHeight)
        Method crop an image to the given dimensions. If dimensions are more than the input image size, then the image gets padded with black color
        Parameters:
        image - Input image
        cropWidth - Width required for cropped image
        cropHeight - Height required for cropped image