How to get an image of an rgb matrix separately?

I have an image database and I want to store this RGB image matrix in mysql db separately (Forexample: redMatrix_column, greenMatrix_column, blueMatrix_column). In Matlab, I can get the RBG matrix separately using the imread () function. How to do this in java? Thank you for your help.

+4
source share
1 answer

Here's how you get the color components:

public class GetImageColorComponents { public static void main(String... args) throws Exception { BufferedImage img = ImageIO.read(GetImageColorComponents.class .getResourceAsStream("/image.png")); int[] colors = new int[img.getWidth() * img.getHeight()]; img.getRGB(0, 0, img.getWidth(), img.getHeight(), colors, 0, img.getWidth()); int[] red = new int[colors.length]; int[] green = new int[colors.length]; int[] blue = new int[colors.length]; for (int i = 0; i < colors.length; i++) { Color color = new Color(colors[i]); red[i] = color.getRed(); green[i] = color.getGreen(); blue[i] = color.getBlue(); } } } 

See this method for a complete example involving storing and retrieving bytes in a MySQL database.

+6
source

All Articles