Sunday 15 March 2015

Java/Swing Trouble getting RGB from image -



Java/Swing Trouble getting RGB from image -

i have not seen problem anywhere else coming here help. making simple programme alter contrast of black , white image , have done. have issu getrgb method. first half of image (roughly) returns normal values around 150, 150, 150 or whatever image has. reason cannot explain returns 0, 0, 0 while , 255, 255, 255 couple of 0's mixed in. know why happening ?

private void getrgb(bufferedimage image, int x, int y){ //get pixel rgb image int temp=image.getrgb(x,y); //set value color , each component color color=new color(temp); rgb[0]=color.getred(); rgb[1]=color.getgreen(); rgb[2]=color.getblue(); //debug file data.println(color.getred()+"\t"+color.getgreen()+"\t"+color.getblue()); }

here snippet of file data.txt. there more zeros have shown here.

189 189 189 184 184 184 178 178 178 181 181 181 171 172 171 196 196 195 182 182 182 175 175 175 186 186 186 181 181 181 192 192 191 183 183 183 184 184 184 186 186 186 188 188 188 183 183 183 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255

here function calculate new gray level of each pixel. far aware functioning properly.

private void equalize(int x, int y, int max, int min){ //this calls getrgb calculates old , new gray levels pixel //it assign new gray level pixel getrgb(image1, x, y); int oldgrey = ((rgb[0]+rgb[1]+rgb[2])/3); int newgrey = (int)math.round( (((cdf[oldgrey]*1.0)-mincdfvalue)/ ((x*y)-mincdfvalue))* (newmax-newmin)+newmin); if(oldgrey != 0){ for(int i=0; i<3; i++){ rgb[i] *= ((newgrey*1.0)/(oldgrey*1.0)); } }else{ rgb[0]=rgb[1]=rgb[2]=newgrey; } setrgb(image1, x, y); }

if there info have left out please allow me know.

edit: cdf cumulative distribution function method histogram equalization. believe there article on wikipedia it. using rgb, requirement. values of each same. 0 , 255, yes legal arguments, however, have edited image it's histogram narrow values 80 210. there no true black(0) or true white (255) pixels @ in image.

java swing

No comments:

Post a Comment