Peanutcalota February 2016

How can I make this ImageBrightener method function properly?

This ImageBrightener method is supposed to brighten the image by increasing the color values. Each value should increase half the distance between it and 255. Thus, 155 would go to 205 while 205 would go to 230 and so on. Can anyone help figure out the issue with 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 is the code to brighten the image and is not functioning properly
    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];
            for (int x = 0; x < columns; x++) {
                for (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 is the properly functioning code for darkening my image.
    private static int[][] DarkenImageSingleChannel(int[][] pixelArray) {
        int columns = pixelArray.length;
        int rows = pixelArray[0].length;
        int[][] answer = new int[columns][rows];
        for (int x = 0; x < columns; x++) {
            for (int y = 0; y < rows; y++) {
                answer[x][y] = (255 * 2) / 3 - pixelArray[x][y];
            }
        }
               

Answers


Guy February 2016

The problem is here

answer[x][y] = 255 - pixelArray[x][y] ;
answer[x][y] = answer[x][y] + pixelArray[x][y] ;

answer[x][y] will always be 255.

Try this

answer[x][y] = (pixelArray[x][y] + 255) / 2; 

Post Status

Asked in February 2016
Viewed 2,104 times
Voted 5
Answered 1 times

Search




Leave an answer