Reading a grayscale image in java -


as read rgb image , shifting operations r, g , b matrices separately ...is possible read gray scale image(jpeg) , directly manipulate pixel values.and rewrite image ?

ultimately have dct operation on gray scale image.

the code below read grayscale image simple 2 dimensional array:

    file file = new file("path/to/file");     bufferedimage img = imageio.read(file);     int width = img.getwidth();     int height = img.getheight();     int[][] imgarr = new int[width][height];     raster raster = img.getdata();     (int = 0; < width; i++) {         (int j = 0; j < height; j++) {             imgarr[i][j] = raster.getsample(i, j, 0);         }     } 

note: raster.getsample(...) method takes 3 arguments: x - x coordinate of pixel location, y - y coordinate of pixel location, b - band return. in case of grayscale images should/may 0 band.


Comments

Popular posts from this blog

twig - Using Twigbridge in a Laravel 5.1 Package -

jdbc - Not able to establish database connection in eclipse -

Kivy: Swiping (Carousel & ScreenManager) -