0
Hello,
I need to transform an image into a pixel array.
For example: Given the image "Netuno.jpeg", of 256 x 256 pixels, I need to allocate the value of pixels in that Matrix and print the amount that these pixels appear in another vector:
Matrix[0][0] = 2 (where 2 is the pixel value),
Matrix[0][1] = 12, ... , Matrix[255][255] = 23
Qtd of pixels 0 = 34 (34 being the number of times the pixel of value 0 appeared) ,
Qtd of pixels 1 = 21, ... , Qtd of pixels 255 = 120
So far I have read the image using Bufferedimage, but do not know how to access the image pixels.
import xxx;
public class Histograma {
public static void main(String[] args) throws IOException {
//Atributos
//Métodos
//Leitura da Imagem - Planeta Netuno
BufferedImage img = ImageIO.read(new File("/home/patch/netuno.jpeg"));
int altura = img.getHeight();
int largura = img.getWidth();
int[][] matrix = new int[largura][altura];
for(int i = 0; i < img.getWidth(); i++) {
for(int j = 0; j < img.getHeight(); j++) {
}
}
}
Thank you!