<< Chapter < Page | Chapter >> Page > |
(Instructions for writing an image explorer sketch were provided in Pr0120-Image Explorer .)
Image 1 shows the raw image being displayed in an image explorer window. Note the red, green, and blue color component values and the coordinates of the pixel to which those colors belong.
Image 2 shows the modified image in an image explorer window. Once again, note the red, green, and blue colorcomponent values and the coordinates of the pixel to which those colors belong.
The algorithm required to transform the image from Image 1 to Image 2 is:
A color value is inverted by subtracting the color value from 255.
By exploring the pixel colors at several different locations, it should be obvious to the student that the blue pixel value has been set to zero forevery pixel in the modified image.
Deducing that the red and green colors in the output pixels are the inverse of the red and green colors in the input image isn't as straightforward.However, color inversion is one of the most common forms of image color manipulation, so a little research on the web should suffice to figure it out. I have also publishedseveral online tutorials that involve color inversion.
The implementation of the algorithm will be explained below.
This sketch consists of two classes, which are provided in Listing 4 and Listing 5 .
I will break the sketch down and explain it in fragments.
The driver class named Pr0130a , which is shown in its entirety in Listing 4 , is almost exactly like the class that I explained in Pr0120-Image Explorer . Therefore, I won't repeat that explanation in this module.
The runner class named Pr0130aRunner is shown in Listing 5 . This class is only slightly different from the class that I explained in Pr0120-Image Explorer . Therefore, I will explain only those portions of the class that are different inthis module.
The first difference begins within the for loop shown in Listing 1 . Recall that in the original version in Pr0120-Image Explorer , the code in the for loop copied pixel colors from the input image to the output image taking the different widths of the images intoaccount.
This version is essentially the same except that in this version, the code inverts the red and green color values and sets the blue color value to zerobefore inserting the pixel color into the output image.
Notification Switch
Would you like to follow the 'The processing programming environment' conversation and receive update notifications?