I have used the following code to extract pixel values from a Jpeg image , but it gives me negative values wen i print the pixel values!!
I dont know if I can continue with negative values for further computation like finding the co-variance matrix ...eigen vectors etc... ...
If u know anything please reply.....
Expand|Select|Wrap|Line Numbers
- private byte bytes[]=null;
- private double doubles[] = null;
- private String filename=null;
- private int height = 0;
- private int width = 0;
- private void readImage() throws FileNotFoundException, IOException {
- FileInputStream fIn = new FileInputStream(filename);
- JPEGImageDecoder jpeg_decode = JPEGCodec.createJPEGDecoder(fIn);
- BufferedImage image = jpeg_decode.decodeAsBufferedImage();
- width = image.getWidth();
- height = image.getHeight();
- int[] rgbdata = new int[width * height];
- image.getRGB(0,0,width,height,rgbdata,0,width);
- bytes = new byte[rgbdata.length];
- doubles = new double[rgbdata.length];
- for (int i = 0; i < bytes.length; i++) {
- bytes = (byte) (rgbdata & 0xFF);
- doubles = (double)(rgbdata);
- }