Skip to content

Jorge36/ImageProcessing

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ImageProcessing

Program to recolor the flowers of a image. Intellij IDE was used to code the program. ImageProcessing is a coding exercise taken from Java Multithreading, Concurrency & Performance Optimization course on Udemy.

Several threads are created to recolor the image faster. Also there is an option to recolor the image with one thread. Then, in the program times are taken to compare both solutions.

I create a thread by implementing the Runnable interface using lamda expression. While using the lambda expressions, we can skip the new Runnable() and run() method because the compiler knows that Thread object takes a Runnable object and that contains only one method run() that takes no argument.

Thread thread = new Thread(() -> {
  int xOrigin = 0 ;
  int yOrigin = height * threadMultiplier;

  recolorImage(originalImage, resultImage, xOrigin, yOrigin, width, height);
});

I use RGB (32/bit integer) to represent colors which each color component is allocated in 8 bits. The highest 8 bits are often used for the alpha channel (representing transparency), followed by red, green, and blue. The structure looks like this:

a. Bits 24-31: Alpha (A)
b. Bits 16-23: Red (R)
c. Bits 8-15: Green (G)
d. Bits 0-7: Blue (B)

&, |, << and >> are used to create RGB colors.

  1. & and | are bit-wise AND and OR operators
  2. << and >> are the bit-wise left and right shift operators.

0x00FF0000 is the hexadecimal representation of red color, 0x0000FF00 is the hex of green and 0x000000FF the blue one. They are used to get the red, greeen and blue colors of each RGB along with >> right shift operator.

Then, I have a function to check if a pixel is gray using the method abs from Math. Lastly, we use the class BufferedImage and WritableRaster to set the RGB of a single pixel.

  • Image before processing:

alt_text

  • Image after processing:

alt_text

More information:

  1. https://docs.oracle.com/javase/8/docs/api/java/awt/image/WritableRaster.html
  2. https://redketchup.io/color-picker
  3. https://www.baeldung.com/java-rgb-color-representation

About

Program to recolor the flowers of a image

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages