Image-6 Exercises

< CS101


Red Golden Gate - the image golden-gate-red.jpg shows the golden gate bridge, but all of the data is in the red values.
golden gate bridge, shown in red

Write code that for each pixel copies the red value over to be the green and blue value. The result will be to change the image to grayscale which will look better.




Grayscale Banana
a yellow banana

Write code to change the banana.jpg image to be grayscale. Reminder: here is the line used in the loop to compute the average of the red/green/blue values and store that value in a variable named "avg".

  avg = (pixel.getRed() + pixel.getGreen() + pixel.getBlue())/3;




a california poppy

Write code to change the "poppy.jpg" image like this: compute the average value for each pixel. Then set the red and blue values to be that average. Set the green value to 0. Instead of a grayscale image, this results in a purple-scale image. The light and dark pixels of the image become light and dark purple instead of light and dark gray.



Each click of a Run button saves that code on the computer running the browser. The button below retrieves the all code exercises listed to the right of the button.

count 3 : image-6-ex1 image-6-ex2 image-6-ex3

(code appears here)