SepiaToned and Posterized Pictures
Make a Sepia Toned Picture
We have discussed a lot about color changing and altering pictures. Let’s start with bit more sophisticated color swapping. We can look for a range of colors and can replace them with some other colors or computed values of original colors. Results are very interesting.
For example, Older prints sometimes have a yellowish tint to them. We could just do an overall color change, but the end result isn’t aesthetically pleasing. By looking for different kinds of colorhighlights, middle ranges, and shadowsand treating them differently, we can get a better effect.
Steps involved to convert picture are :
- Convert Picture to grey
- Look low, middle and high ranges of the color and change them seperately
- set the manipulated colors to current pixel
public void sepiaTint() { Pixel pixel = null; double r = 0; double g = 0; double b = 0; // first change the current picture to grayscale this.grayscale(); // loop through the pixels for (int x = 0; x < this.getWidth(); x++) { for (int y = 0; y < this.getHeight(); y++) { // get the current pixel and color values pixel = this.getPixel(x,y); r = pixel.getRed(); // tint the shadows darker if (r < 60) { r = r * 0.9; g = pixel.getGreen() * 0.9; b = pixel.getBlue() * 0.9; } // tint the midtones a light brown // by reducing the blue else if (r < 190) b = b * 0.8; // tint the highlights a light yellow // by reducing the blue else b = b * 0.9; // set the colors pixel.setRed((int) r); pixel.setGreen((int) g); pixel.setBlue((int) b); } } }
Posterizing is a procedure of changing over a photo to a littler number of hues. Will do that by searching for particular scopes of shading, then setting the shading to one esteem in that range.
public void posterize(int levels) { Pixel pixel = null; int r = 0; int g = 0; int b = 0; int increment = (int) (256.0 / levels); int bottomValue, topValue, middleValue = 0; // loop through the pixels for (int x = 0; x < this.getWidth(); x++) { for (int y = 0; y < this.getHeight(); y++) { // get the current pixel and colors pixel = this.getPixel(x, y); r = pixel.getRed(); g = pixel.getGreen(); b = pixel.getBlue(); // loop through the number of levels for (int i = 0; i < levels; i++) { // compute the bottom, top, and middle values bottomValue = i * increment; topValue = (i + 1) * increment; middleValue = (int) ((bottomValue + topValue - 1) / 2.0); /* * check if current values are in current range and if so * set them to the middle value */ if (bottomValue <= r && r < topValue) pixel.setRed(middleValue); if (bottomValue <= g && g < topValue) pixel.setGreen(middleValue); if (bottomValue <= b && b < topValue) pixel.setBlue(middleValue); } } } }