Today: color-logic examples, bluescreen algorithm

> Logic-Stop Examples

Color If Logic

alt: red stop sign

Red Detect red >= 100

Red Detect - Average

alt: redish is red value above average per pixel


Bluescreen Algorithm

Bluescreen Algorithm Outline

Diagram:

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

Bluescreen Stop Sign Example

This code is complete, look at the code then run it to see.

> 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.4:
                # the key line:
                back_pixel = back.get_pixel(x, y)
                pixel.red = back_pixel.red
                pixel.green = back_pixel.green
                pixel.blue = back_pixel.blue
    return image

Before - the red stop sign before the bluescreen algorithm:

alt: red stop sign

After:

alt: red part of stop sign replaced with leaves

Bluescreen Monkey

> Bluescreen Monkey

A favorite old example of Nick's.

Have monkey.jpg with blue background

alt: monkey with blue background

The famous Apollo 8 moon image. At one time the most famous image in the world. Taken as the capsule came around the moon, facing again the earth. Use this as the background.

alt: moon image

The bluescreen code is the same as before basically. Adjust the hurdle factor to look good. 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 stanford.jpg etc. background-cases for the monkey.

The code is complete but has a 1.5 factor to start. Adjust it, so more blue gets replaced, figuring out the right hurdle value.