java - How can I make this ImageBrightener method function properly? -
this imagebrightener method supposed brighten image increasing color values. each value should increase half distance between , 255. thus, 155 go 205 while 205 go 230 , on. can figure out issue imagebrightener! thanks
import squint.simage; public class imagebrightener implements imagetransformer { @override public simage transform(simage picture) { return brightenimage(picture); } private static simage brightenimage(simage si) { int[][] newreds = brightenimagesinglechannel(si.getredpixelarray()); int[][] newgreens = brightenimagesinglechannel(si.getgreenpixelarray()); int[][] newblues = brightenimagesinglechannel(si.getbluepixelarray()); return new simage(newreds, newgreens, newblues); } // here code brighten image , not functioning private static int[][] brightenimagesinglechannel(int[][] pixelarray) { private static int[][] brightenimagesinglechannel(int[][] pixelarray) { int columns = pixelarray.length; int rows = pixelarray[0].length; int[][] answer = new int[columns][rows]; (int x = 0; x < columns; x++) { (int y = 0; y < rows; y++) { answer[x][y] = 255 - pixelarray[x][y] ; answer[x][y] = answer[x][y] + pixelarray[x][y] ; } } return answer; } } // here functioning code darkening image. private static int[][] darkenimagesinglechannel(int[][] pixelarray) { int columns = pixelarray.length; int rows = pixelarray[0].length; int[][] answer = new int[columns][rows]; (int x = 0; x < columns; x++) { (int y = 0; y < rows; y++) { answer[x][y] = (255 * 2) / 3 - pixelarray[x][y]; } } return answer; } }
the problem here
answer[x][y] = 255 - pixelarray[x][y] ; answer[x][y] = answer[x][y] + pixelarray[x][y] ;
answer[x][y]
255.
try this
answer[x][y] = (pixelarray[x][y] + 255) / 2;
Comments
Post a Comment