I want to analysis the pixel of lena.bmp (matlab) but I don't know how to do it in java and store it to byte[]
I have read this aritle:
how to convert image to byte array in java?
But when I implement, I find some pixel value that did't exist
.
For example , the pixel range is 0~255,
but I can not find '120' on pixel of this photo(lena.bmp).
There is my code
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package Image_IO;
import java.awt.image.BufferedImage;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
/**
*
* @author user
*/
public class ReadImage {
public static void main (String []args){
byte[] imageInByte;
int [] kindOfPixel = new int [256];
try{
BufferedImage originalImage = ImageIO.read(new File("C:\\Users\\user\\Desktop\\Project\\LSB_implement\\Lena.bmp"));
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ImageIO.write( originalImage, "bmp", baos );
baos.flush();
imageInByte = baos.toByteArray();
System.out.println(imageInByte.length);
baos.close();
for(int i=0;i<imageInByte.length;i++){
kindOfPixel[imageInByte[i]+128]++; //java byte defined -128~127 (+128)==> 0~256
}
for(int i=0;i<kindOfPixel.length;i++){ //show the pixel color value
System.out.println(i+" , "+kindOfPixel[i]);
}
}catch(IOException e){
System.out.println(e.getMessage());
}
}
}
I compare this information with the histogram of lena.bmp , but it seems have some different...