VOOZH about

URL: https://www.geeksforgeeks.org/java/image-processing-in-java-colored-image-to-sepia-image-conversion/

⇱ Image Processing in Java - Colored Image to Sepia Image Conversion - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Image Processing in Java - Colored Image to Sepia Image Conversion

Last Updated : 23 Jul, 2025

Prerequisites: 

In this set, we will be converting a colored image to a sepia image. In a sepia image, the Alpha component of the image will be the same as the original image(since the alpha component denotes the transparency). Still, the RGB will be changed, which will be calculated by the following formula. 

newRed = 0.393*R + 0.769*G + 0.189*B
newGreen = 0.349*R + 0.686*G + 0.168*B
newBlue = 0.272*R + 0.534*G + 0.131*B

If any of these output values is greater than 255, simply set it to 255. These specific values are the values for a sepia tone that are recommended by Microsoft.

Algorithm: 

  1. Get the RGB value of the pixel.
  2. Calculate newRed, new green, newBlue using the above formula (Take the integer value)
  3. Set the new RGB value of the pixel as per the following condition: 
    • If newRed > 255 then R = 255 else R = newRed
    • If newGreen > 255 then G = 255 else G = newGreen
    • If newBlue > 255 then B = 255 else B = newBlue
  4. Replace the value of R, G, and B with the new value that we calculated for the pixel.
  5. Repeat Step 1 to Step 4 for each pixel of the image.

Implementation:

Output:

Note: This code will not run on an online IDE as it needs an image on a disk.

Comment
Article Tags: