Brightness Changing Algorithm - Image Processing Basic

Posted by Unknown Selasa, 22 Mei 2012 0 komentar
There are many libraries which are used to Image processing applications. But the algorithms behind these libraries use basic mathematical operation. I hope to bring you series of blog posts which describe the fundamental image processing algorithms implemented in mathematical operation without using any library. Following java class change the brightness of an image.
We should input our image to the method changeBrightness as a BufferedImage. increasingFactor is an integer which determine the brightness level of the image. Positive values will increase the brightness while negative values decrees. Range of the increasingFactor should be between -255 to 255.

Original Image
Brightness Increased
Brightness Decreased

package lakj.comspace.imageprocessor;

import java.awt.Color;
import java.awt.image.BufferedImage;

/**
*Brightness Changing Class
*by
*Lak J Comspace
*
*/
public class Brightness {

public BufferedImage changeBrightness(BufferedImage inImage, int increasingFactor) {

//size of input image
int w = inImage.getWidth();
int h = inImage.getHeight();

BufferedImage outImage = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);

//Pixel by pixel navigation loop
for (int i = 0; i < w; i++) {
for (int j = 0; j < h; j++) {


//get the RGB component of input imge pixel
Color color = new Color(inImage.getRGB(i, j));

int r, g, b;

//change the value of each component
r = color.getRed() + increasingFactor;
g = color.getGreen() + increasingFactor;
b = color.getBlue() + increasingFactor;


//r,g,b values which are out of the range 0 to 255 should set to 0 or 255
if (r >= 256) {
r = 255;
} else if (r < 0) {
r = 0;
}

if (g >= 256) {
g = 255;
} else if (g < 0) {
g = 0;
}

if (b >= 256) {
b = 255;
} else if (b < 0) {
b = 0;
}

//set output image pixel component
outImage.setRGB(i, j, new Color(r, g, b).getRGB());

}
}

return outImage;
}
}
TERIMA KASIH ATAS KUNJUNGAN SAUDARA
Judul: Brightness Changing Algorithm - Image Processing Basic
Ditulis oleh Unknown
Rating Blog 5 dari 5
Semoga artikel ini bermanfaat bagi saudara. Jika ingin mengutip, baik itu sebagian atau keseluruhan dari isi artikel ini harap menyertakan link dofollow ke http://androidphotography4.blogspot.com/2012/05/brightness-changing-algorithm-image.html. Terima kasih sudah singgah membaca artikel ini.

0 komentar:

Posting Komentar

Trik SEO Terbaru support Online Shop Baju Wanita - Original design by Bamz | Copyright of android photography.