gray image log transformation in java -
i trying log transformation gray image. whatever c value black image. idea?
that method:
///---------------------------------------------------
public static bufferedimage log_trans (int[][] imagedata , int c){
bufferedimage logimage = new bufferedimage(imagedata.length, imagedata[0].length, bufferedimage.type_byte_gray); double temp; (int =0 ; i<imagedata.length ; ++){ (int j=0 ; j<imagedata[0].length ; j++){ int rgb = imagedata[i][j]; rgb = (rgb<<16)|(rgb<<8)|(rgb); temp = math.log10(rgb+1); rgb = (int) (c * temp); logimage.setrgb(i, j, rgb); }} return logimage; } -------------------------------------------------------------- public static int[][] readimage(file filename){ bufferedimage img; try { img = imageio.read(filename); // gray_scaled image output int width = img.getwidth(); int height = img.getheight(); imagepro.fw=width; imagepro.fh = height; int [][] readimageval = new int [width][height]; (int = 0; i<height ; i++){ (int j =0 ; j<width ; j++){ color c = new color(img.getrgb(j, i)); int r= (int)(c.getred() * 0.299)&0xff; int g = (int)(c.getgreen() * 0.587)&0xff; int b = (int)(c.getblue() *0.114)&0xff; int avg = ((r+b+g)); readimageval[j][i] = avg; } } return readimageval; } catch (ioexception e) { // todo auto-generated catch block e.printstacktrace(); } return null; }
it seems "rgb" negative, temp nan, in end "rgb" after:
rgb = (int) (c * temp);
is 0 , why black picture.
after changing 8th line to:
rgb = (((byte)rgb & 0xff)<<16)|(((byte)rgb & 0xff)<<8)|(((byte)rgb & 0xff));
i dark output, it's not nice. tested value of "c" being 1, 18000, 180000 , 0x00ffffff.
Comments
Post a Comment