# Image 7 Exercises

## 1.

Write code to set a vertical stripe 100 pixels wide at the right edge of the flowers image to dark gray (red green blue all set to 100). The flowers image is 457 pixels wide.

 image = new SimpleImage("flowers.jpg"); for (pixel: image) { // your code here } print(image); image-7-ex1

## 2.

Here is the fence-ivy.jpg image.

Write code that picks out the pixels of the green leaves in the image (using the > avg * factor technique, as in lecture). For each green pixel identified, set its green value to 0. The result is that the green leaves are changed to a sort of weird purple color, since setting green to 0, we just have red and blue contributing.

 image = new SimpleImage("fence-ivy.jpg"); for (pixel: image) { // your code here } print(image); image-7-ex2

## 3.

Here is the stop.jpg image.

Write code that picks out the blue sky (using the > avg * factor technique, as in lecture). Change the blue pixels to be red=20 green=20 blue=20 .. so it looks like nighttime. Adjust your code so it changes the sky, but not the white letters in the sign (which are technically a little blue).

 image = new SimpleImage("stop.jpg"); for (pixel: image) { // your code here } print(image); image-7-ex3

## 4.

Here is the curb.jpg image.

The goal for this problem is to change the curb to look blue so we can get a much more expensive parking ticket. Detect the red pixels of the curb using the avg technique as usual. For each pixel, change its red and green values to be half the average value, and change its blue value to 1.2 times the average value. In effect, this sets red and green low and blue high, making it look kind of blue. Note that the blue effect will also apply to the reddish plants off to the right as well -- now they are blueish plants.

 image = new SimpleImage("curb.jpg"); for (pixel: image) { // your code here } print(image); image-7-ex4

## 5.

This is basically the flip of the previous problem. Instead of detecting and changing the red pixels, detect the pixels which are not red. Change the not-red pixels to be grayscale. The result will be that the reddish parts of the image are unchanged, but the green plants and little blue flowers and all the rest are now a dead gray color.

 image = new SimpleImage("curb.jpg"); for (pixel: image) { // your code here } print(image); image-7-ex5

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

count 5 : image-7-ex1 image-7-ex2 image-7-ex3 image-7-ex4 image-7-ex5

```(code appears here)

```