Similarly, the expression for
blueScale is the equation for
a straight line that goes through 0.0 on the left and 1.0 on the right.
Compute a new color
Listing 5 computes a new color based on scaled
versions of the green and blue input color values. The red color value is notmodified.
If you enable the last statement in
Listing 5 ,
the new output color will be identical to the old input color. This isuseful when you need to produce an output image showing the unmodified input
image as in
Image 1 .
Store
modified pixel color in the output pixel array
The second major difference between this and previous versions of the
run method is the delegation of the code that stores the modified pixel color in theoutput pixel array to a separate method named
setOutputPixelColor .
This was done because it is unlikely that the code needed to perform this
operation will need to change from one algorithm to the next. As a result, mostof the code that is likely to change from one algorithm to the next is confined
to the method named
processPixels .
The method named
setOutputPixelColor is called in
Listing 6 ,
which also signals the end of the
processPixels method
The setOutputPixelColor method
The
setOutputPixelColor method is shown in
Listing 8 . The code in that method is the same as
code that I have explained in earlier modules, so I won't repeat thatexplanation here.
The remainder of the
Pr0140aRunnerclass
The remainder of the
Pr0140aRunner class shown in
Listing 8 is the same as code
that I have explained in earlier modules. Therefore, there is nothing more toexplain in this module.
Run the sketch
I encourage you to copy the code from
Listing 7 and
Listing 8 and paste it into your PDE. Be sure to
put the code from
Listing 7 in the leftmost tab.
Don't forget to put an image file of your choice in a folder named
data that is a child of the folder that contains the files with the
.pde extension. You will need to edit the code to change the name of the image file in
two different places .
Run the sketch
and observe the results. Experiment with the code. Make changes, run the sketch again, and observe the results of your changes. Make certain that youcan explain why your changes behave as they do.
Don't forget to also create and run the JavaScript version of your sketch in
your HTML 5 compatible browser.
Click
here to view the JavaScript version of the
sketch discussed in this module in your HTML 5 compatible browser.
If you have a programmable Android device
, try creating and running the Android version of your sketch in your
Android device.
Also try creating and running the stand-alone version of the sketch by
selecting
Export Application from the
File menu while in
Java mode.
Summary
In this module, you learned:
How to develop a template sketch for implementing pixel modification
algorithms, and
How to implement a space-wise linear pixel modification algorithm.
Click
here to view the JavaScript version of the
sketch discussed in this module in your HTML 5 compatible browser.
Miscellaneous
This section contains a variety of miscellaneous information.
Housekeeping material
Module name: Pr0140-A space-wise linear
pixel-modification algorithm
File: Pr0140.htm
Published: 02/26/13
Disclaimers:
Financial : Although the Connexions
site makes it possible for you to download a PDF file for thismodule at no charge, and also makes it possible for you to
purchase a pre-printed version of the PDF file, you should beaware that some of the HTML elements in this module may not translate well into
PDF.
I also want you to know that, I receive no financial compensation from the Connexions website even if you purchase
the PDF version of the module.
In the past, unknown individuals have copied my modules from cnx.org, converted them to Kindle books, and
placed them for sale on Amazon.com showing me as the author. Ineither receive compensation for those sales nor do I know who does
receive compensation. If you purchase such a book, please beaware that it is a copy of a module that is freely
available on cnx.org and that it was made and published withoutmy prior knowledge.
Affiliation : I am a professor of Computer Information
Technology at Austin Community College in Austin, TX.
Complete program listing
Complete listings of the classes discussed in this module are provided in
Listing 7 and
Listing 8 .