Today: color-logic examples

> Logic-Color Examples

Grayscale (recall)

(a) Convert Color To Grayscale

# Convert pixel from color to grayscale
# - parenthesis required here
# - using int div //, regular / works too (float)
average = (pixel.red + pixel.green + pixel.blue) // 3
pixel.red = average
pixel.green = average
pixel.blue = average

Color If Logic

alt: red stop sign

b. Red Detect red > 100

c. Red Detect - Average

alt: redish is red value above average per pixel

d. Curb Repair 1

e. Curb Repair 2


Bluescreen

Bluescreen Algorithm Outline

Here is the output we are going for with this bluescreen algorithm:

Before:

alt: red stop sign

After:

alt: red part of stop sign replaced with leaves

Diagram:

alt: replace red pixel with pixel at same x,y from back image

Bluescreen Stop Sign

> Bluescreen Stop Sign

Solution code

def stop_leaves(front_filename, back_filename):
    """Implement stop_leaves as above."""
    image = SimpleImage(front_filename)
    back = SimpleImage(back_filename)
    for y in range(image.height):
        for x in range(image.width):
            pixel = image.get_pixel(x, y)
            average = (pixel.red + pixel.green + pixel.blue) // 3
            if pixel.red >= average * 1.6:
                # the key line:
                back_pixel = back.get_pixel(pixel.x, pixel.y)
                pixel.red = back_pixel.red
                pixel.green = back_pixel.green
                pixel.blue = back_pixel.blue
    return image

Bluescreen Monkey

If Sufficient time, in-class exercise/demo. Observe: the bluescreen algorithm depends on the colors in the main image. BUT it does not depend on the colors of the back image - the back image can have any colors it in. Try the different background-cases for the monkey.

> Bluescreen Monkey