Ejemplo n.º 1
0
def create_ghost(image1, image2, image3):
    """
    Given three image objects, this function creates and returns a Ghost
    solution image based on the images passed in. All the images passed
    in will be the same size.

    Input:
        three images to be processed
    Returns:
        a new Ghost solution image
    """
    # Your code goes here
    ghost = SimpleImage.blank(image1.width, image1.height)
    for x in range(ghost.width):
        for y in range(ghost.height):
            pixel1 = image1.get_pixel(x, y)
            pixel2 = image2.get_pixel(x, y)
            pixel3 = image3.get_pixel(x, y)
            ghost.set_pixel(x, y, get_best_pixel(pixel1, pixel2, pixel3))
    return ghost
Ejemplo n.º 2
0
def find_flames(filename):
    """
    This function should highlight the "sufficiently red" pixels
    in the image and grayscale all other pixels in the image
    in order to highlight areas of wildfires.
    """
    image = SimpleImage(filename)

    for pixel in image:
        avg = (pixel.red + pixel.green + pixel.blue) / 3
        if avg < pixel.red:
            pixel.red = 255
            pixel.green = 0
            pixel.blue = 0
        else:
            pixel.red = avg
            pixel.green = avg
            pixel.blue = avg

    return image
Ejemplo n.º 3
0
def make_warhol():
    image = SimpleImage.blank(1302, 860)
    first_line = [
        green_scale(),
        orange_scale(),
        purple_scale(),
        red_scale(),
        yellow_scale(),
        brown_scale()
    ]

    # return fill_background(first_line, secound_line, image)

    for index, doimage in enumerate(first_line):

        for pixel in doimage:
            image.set_pixel(pixel.x + place_element(index).x,
                            pixel.y + place_element(index).y, pixel)
        index = index + 1
        return image
Ejemplo n.º 4
0
def find_flames(filename):
    """
    This function should highlight the "sufficiently red" pixels
    in the image and grayscale all other pixels in the image
    in order to highlight areas of wildfires.
    """
    image = SimpleImage(filename)
    for pixel in image:
        average = (pixel.red + pixel.blue + pixel.green) // 3
        # Here I will apply this avera to the image | I am not sure, helpp!!! Lets see
        if pixel.red >= average * INTENSITY_THRESHOLD:
            pixel.red = 255
            pixel.blue = 0
            pixel.green = 0
        else:
            # convert to grayscale = average
            pixel.red = average
            pixel.blue = average
            pixel.green = average
    return image
Ejemplo n.º 5
0
def find_flames(filename):
    """
    This function should highlight the "sufficiently red" pixels
    in the image and grayscale all other pixels in the image
    in order to highlight areas of wildfires.
    """
    image = SimpleImage(filename)
    # TODO: your code here
    for pixel in image:
        avg = find_average(pixel.red, pixel.green, pixel.blue)
        if (pixel.red >= avg):
            pixel.red = 255
            pixel.green = 0
            pixel.blue = 0
        else:
            pixel.red = avg
            pixel.green = avg
            pixel.blue = avg

    return image
Ejemplo n.º 6
0
def main():
    # DO NOT MODIFY
    # args = sys.argv[1:]
    #
    # if len(args) != 1:
    #     print('Please specify directory of images on command line')
    #     return
    #
    # # We just take 1 argument, the folder containing all the images.
    # # The load_images() capability is provided above.
    # images = load_images(args[0])
    # result = create_ghost(images)
    # if result:
    #     print("Displaying image!")
    #     result.show()
    # else:
    #     print("No image to display!")
    green_im = SimpleImage.blank(20, 20, 'green')
    green_pixel = green_im.get_pixel(0, 0)
    return get_pixel_dist(green_pixel, 0, 255, 255)
Ejemplo n.º 7
0
def solve(images):
    """
    Given a list of image objects, compute and display a Ghost solution image
    based on these images. There will be at least 3 images and they will all
    be the same size.

    Input:
        images (List[SimpleImage]): list of images to be processed
    """
    width = images[0].width
    height = images[0].height
    result = SimpleImage.blank(width, height)
    ######## YOUR CODE STARTS HERE #########
    # Write code to populate image and create the 'ghost' effect
    # green_im = SimpleImage.blank(20, 20, 'green')
    # green_pixel = green_im.get_pixel(0, 0)
    # print(get_pixel_dist(green_pixel, 5, 255, 10))

    # green_pixel = SimpleImage.blank(20, 20, 'green').get_pixel(0, 0)
    # red_pixel = SimpleImage.blank(20, 20, 'red').get_pixel(0, 0)
    # blue_pixel = SimpleImage.blank(20, 20, 'blue').get_pixel(0, 0)
    # # print(get_average([green_pixel, green_pixel, green_pixel, blue_pixel]))
    # best1 = get_best_pixel([green_pixel, blue_pixel, blue_pixel])
    # print(best1.red, best1.green, best1.blue)

    ######## YOUR CODE ENDS HERE ###########

    for x in range(width):
        for y in range(height):
            pixels = []  # 選定座標後,打開每張圖取他的特定座標x,y
            for image in images:  # 打開每個image
                pixel = image.get_pixel(x, y)
                result_pixel = result.get_pixel(x, y)
                pixels.append(pixel)  # 把pixel放到list裡面
                best = get_best_pixel(pixels)  # 得到最好的pixel
                result_pixel.red = best.red  # 把最好的pixel送給result
                result_pixel.green = best.green
                result_pixel.blue = best.blue

    print("Displaying image!")
    result.show()
def main():
    # Get file and load image
    filename = get_file()
    image = SimpleImage(filename)

    # Show the image before the transform
    image.show()

    for pixel in image:
        pixel.red *= 1.5
        pixel.green *= 0.7
        pixel.blue *= 1.5

    # Show the image after the transform
    image.show()
Ejemplo n.º 9
0
def main():
    # Get file and load image
    filename = get_file()
    image = SimpleImage(filename)

    # Show the image before the transform
    image.show()

    # Apply the filter
    #convert the file
    for pixel in image:
        cool_filter(pixel)

    # Show the image after the transform
    image.show()
Ejemplo n.º 10
0
def main():
    # Get file and load image
    filename = get_file()
    image = SimpleImage(filename)

    # Show the image before the transform
    image.show()

    # Apply the filter
    # TODO: your code here!
    for pixel in image:
        pixel.red = random.randint(0, 255)

    # Show the image after the transform
    image.show()
Ejemplo n.º 11
0
def blur(img):
    """
    First, this function create the blank image.
    Second, it will get the blur color in each point from old image.
    Third, it will assign the blur color to the blank image.
    --------------------------------------------------
    :param img: SimpleImage, the original image.
    :return: new_img: SimpleImage, blur image.
    """

    new_img = SimpleImage.blank(img.width, img.height)

    for r in range(img.height):
        for c in range(img.width):
            pixel = img.get_pixel(c, r)
            pixel_blur = new_img.get_pixel(c, r)
            new_pixel = get_blur_color(c, r)
            pixel_blur.red = new_pixel.red
            pixel_blur.green = new_pixel.green
            pixel_blur.blue = new_pixel.blue
    return new_img
Ejemplo n.º 12
0
def find_flames(filename):
    """
    This function should highlight the "sufficiently red" pixels
    in the image and grayscale all other pixels in the image
    in order to highlight areas of wildfires.
    """
    image = SimpleImage(filename)

    for pixel in image:
        average = (pixel.red + pixel.green + pixel.blue) // 3
        # See if this pixel is "sufficiently" red
        if pixel.red >= average * INTENSITY_THRESHOLD:
            pixel.red = 255
            pixel.green = 0
            pixel.blue = 0
        else:
            pixel.red = average
            pixel.green = average
            pixel.blue = average

    return image
Ejemplo n.º 13
0
def highlight_fires(filename):
    """
    :param img: The image of the greenland, to be detected whether on fire.
    :return: str, 'img', (the modified image),
             mark the fire area as red;
             turn the rest of area into grayscale.
    """
    img = SimpleImage(filename)
    for pixel in img:
        avg = (pixel.red + pixel.green + pixel.blue) / 3
        if pixel.red > avg * HURDLE_FACTOR:
            # If pixel.red over the hurdle, then turn pixel.red into red to alert!
            pixel.red = 255
            pixel.green = 0
            pixel.blue = 0
        else:
            # Grayscale
            pixel.red = avg
            pixel.green = avg
            pixel.blue = avg
    return img
Ejemplo n.º 14
0
def main():  # {by: Charlie}
    # (1) load image–part of main
    image = SimpleImage(DEFAULT_FILE)

    # (2) get user’s choice of kernel
    choice = user_choice()

    # (3) get the kernel array
    kernel = create_kernel(choice)

    # (4) change image to grayscale
    make_grayscale(image)

    # (5) add 1px border to image
    image = add_border(image, 1)

    # (6) process the bordered image using the kernel
    final_image = process_image(image, kernel)

    # (7) show results
    final_image.show()
def find_flames(filename):
    """
    This function should highlight the "sufficiently red" pixels
    in the image and grayscale all other pixels in the image
    in order to highlight areas of wildfires.
    """
    image = SimpleImage(filename)
    # TODO: your code here
    for pixel in image:
        if pixel.red > ((pixel.red + pixel.green + pixel.blue) / 3):
            pixel.red = 255
            pixel.blue = 0
            pixel.green = 0
        average = ((pixel.red + pixel.green + pixel.blue) / 3)
        # r = pixel.red
        # b = pixel.blue
        # g = pixel.green
        #pixel.red = average
        pixel.blue = average
        pixel.green = average
    return image
Ejemplo n.º 16
0
def highlight_fires(filename):
    """
    Remove all the green and blue color from the photo and
    assign 255 to pixel.red in order to enhance the big fire spot.
    -----------------------------------------------------------------
    :param filename: str, the file path of the image
    :return: img : SimpleImage, the image of red spot with big fire and the gray scale with no fire
    """
    img = SimpleImage('images/greenland-fire.png')
    for pixel in img:
        avg = (pixel.red + pixel.green + pixel.blue) // 3
        if pixel.red > avg * HURDLE_FACTOR:
            pixel.red = 255
            pixel.green = 0
            pixel.blue = 0
        else:
            pixel.red = avg
            pixel.green = avg
            pixel.blue = avg

    return img
Ejemplo n.º 17
0
def highlight_fires(filename):
    """
    This function will scan through every pixel of the image and detects the pixels that are recognized as fire.
    Finally, the function will label them in red.
    :param filename: The directory of an image you want to process.
    :return: SimpleImage, parts of the image are labeled by red and other parts are in gray scale.
    """
    img = SimpleImage(filename)
    for pixel in img:
        avg = (pixel.red + pixel.green + pixel.blue) // 3
        # Highlight places that are on fire.
        if pixel.red > avg * HURDLE_FACTOR:
            pixel.red = 255
            pixel.green = 0
            pixel.blue = 0
        # Gray scale for other parts.
        else:
            pixel.red = avg
            pixel.green = avg
            pixel.blue = avg
    return img
Ejemplo n.º 18
0
def highlight_fires(filename):
    """
    :param filename: str, picture filename
    :return: SimpleImage

    loop through every pixel in the picture
    find out the average of value of RGB in each pixel.
    use a if/ else statement to determine which pixel will turn full red and gray scale.
    """
    img = SimpleImage(filename)
    for pixel in img:
        avg = (pixel.red + pixel.green + pixel.blue) // 3
        if pixel.red > avg * HURDLE_FACTOR:
            pixel.red = 255
            pixel.green = 0
            pixel.blue = 0
        else:
            pixel.red = avg
            pixel.green = avg
            pixel.blue = avg
    return img
Ejemplo n.º 19
0
def highlight_fires(filename):
    """
    This function will highlight the fire in the image with red
    and turn the rest of it into gray
    -----------------------------------------------------------
    :param filename: str, the name of the file
    :return: SimpleImage, the image of highlighted fires
    """
    highlighted_img = SimpleImage(filename)
    for pixel in highlighted_img:
        avg = (pixel.red + pixel.green + pixel.blue) // 3
        if pixel.red > avg * HURDLE_FACTOR:
            pixel.red = 255
            pixel.green = 0
            pixel.blue = 0
        else:
            pixel.red = avg
            pixel.green = avg
            pixel.blue = avg
            # The pixel will become gray
    return highlighted_img
Ejemplo n.º 20
0
def find_flames(filename):
    """
    This function should highlight the "sufficiently red" pixels
    in the image and grayscale all other pixels in the image
    in order to highlight areas of wildfires.
    """
    image = SimpleImage(filename)
    # precondition: regular image, no fires highlighted
    # postcondition: grayscale image with red where fires are
    # first - check for red enough pixels that could indicate fires
    for pixel in image:
        avg = get_average(pixel) # See if this pixel is "sufficiently" red
        if pixel.red >= avg: # If so,set the red enough pixels to red = 255, then green and blue to 0
            pixel.red = 255
            pixel.green = 0
            pixel.blue = 0
        else: # all over pixel set to grayscale
            pixel.red = avg
            pixel.green = avg
            pixel.blue = avg
    return image
Ejemplo n.º 21
0
def redscreen(mainfile, background):
    # takes out image
    image = SimpleImage(mainfile)
    # takes out background image to be put into the main image above
    back = SimpleImage(background)
    # for seeing each pixel in the image
    for pixel in image:
        # taking out the average of all the pixels
        average = (pixel.red + pixel.green + pixel.blue) // 3
        # is your green pixel more greener than the avg intensity
        if pixel.red >= average * INTENSITY_THRESHOLD:
            # if so then overwrite the pixel in the original image
            # corresponding pixel from the background image
            x = pixel.x
            y = pixel.y
            # set background image in those specific pixels which
            # are greener than average and replace them
            image.set_pixel(x, y, back.get_pixel(x, y))
    return image
Ejemplo n.º 22
0
def main():
    """
    Run your desired photoshop functions here.
    You should save the return value of the image and then
    call .show() to visualize the output of your program.
    """
    # original_poppy = SimpleImage('images/poppy.png')
    # original_poppy.show()
    #
    # red_poppy = red_channel('images/poppy.png')
    # red_poppy.show()
    #
    # dark_poppy = darker('images/poppy.png')
    # dark_poppy.show()
    #
    # original_dandelion = SimpleImage('images/dandelion.png')
    # original_dandelion.show()
    #
    # dark_half_dandelion = right_half('images/dandelion.png')
    # dark_half_dandelion.show()
    #
    # dark_quarter_dandelion = right_quarter('images/dandelion.png')
    # dark_quarter_dandelion.show()
    #
    # gray_dandelion = grayscale('images/dandelion.png')
    # gray_dandelion.show()
    #
    # original_curb = SimpleImage('images/curb.png')
    # original_curb.show()
    #
    # new_curb = curb_repair('images/curb.png')
    # new_curb.show()
    #
    original_stop = SimpleImage('images/stop.png')
    original_stop.show()

    original_leaves = SimpleImage('images/leaves.png')
    original_leaves.show()
Ejemplo n.º 23
0
def solve_mystery(filename):
    """Solve the mystery as described in the handout."""

    # SimpleImage boilerplate provided as a starting point
    nums_in_list = parse_file(filename)
    width = nums_in_list[0]  # correct values needed here
    height = nums_in_list[1]

    image = SimpleImage.blank(width, height)
    num_pixel = 0
    for y in range(image.height):
        for x in range(image.width):
            pixel = image.get_pixel(x, y)
            # manipulate pixel in here
            pixel.red = nums_in_list[num_pixel + 2]
            pixel.blue = nums_in_list[num_pixel + 2]
            pixel.green = nums_in_list[num_pixel + 2]
            num_pixel += 1

    # This displays image on screen
    image.show()
Ejemplo n.º 24
0
def find_flames(filename):
    """
    This function should highlight the "sufficiently red" pixels
    in the image and grayscale all other pixels in the image
    in order to highlight areas of wildfires.
    """
    image = SimpleImage(filename)
    for pixel in image:
        red = pixel.red
        blue = pixel.blue
        green = pixel.green
        average = (red + blue + green) / 3
        if average > red:
            pixel.blue = average
            pixel.green = average
            pixel.red = average
        else:
            pixel.red = RED_ADJUST
            pixel.blue = BLUE_ADJUST
            pixel.green = GREEN_ADJUST
    return image
Ejemplo n.º 25
0
def solve(images):
    """
    Given a list of image objects, compute and display a Ghost solution image
    based on these images. There will be at least 3 images and they will all
    be the same size.

    Input:
        images (List[SimpleImage]): list of images to be processed
    """
    start = time.time()
    width = images[0].width
    height = images[0].height
    result = SimpleImage.blank(width, height)
    # Scan through all pixels.
    for x in range(width):
        for y in range(height):
            # Create a list of pixels for the function 'get_best_pixel'.
            pixels = []
            for image in images:
                pixels.append(image.get_pixel(x, y))
            # Best pixel of a certain pixel in the image.
            best = get_best_pixel(pixels)
            # Each pixel of the result image is set as best
            result.set_pixel(x, y, best)
    end = time.time()
    print(end - start)
    # Method 2 #
    # for x in range(width):
    #     for y in range(height):
    #         pixels = []
    #         result_pix = result.get_pixel(x, y)
    #         for image in images:
    #             pixels.append(image.get_pixel(x, y))
    #         best = get_best_pixel(pixels)
    #         result_pix.red = best.red
    #         result_pix.green = best.green
    #         result_pix.blue = best.blue
    # End Method 2 #
    print("Displaying image!")
    result.show()
def main():
    # Get file and load image
    filename = get_file()
    image = SimpleImage(filename)
    new_image = SimpleImage.blank(900, 559)

    # Show the image before the transform
    image.show()
    for y in range(image.height):
        for x in range(image.width):
            pixel = image.get_pixel(x, y)
            pixel.red = pixel.red * 1.5
            pixel.green = pixel.green * 0.7
            pixel.blue = pixel.blue * 1.5
            new_image.set_pixel(x, y, pixel)
    new_image.show()
Ejemplo n.º 27
0
def main():
    # Get file and load image
    filename = get_file()
    image = SimpleImage(filename)

    # Show the image before the transform
    image.show()

    # Apply the filter
    for px in image:
        px.red *= 1.5
        px.green *= 0.7
        px.blue *= 1.5

    # Show the image after the transform
    image.show()
Ejemplo n.º 28
0
def solve(images):
    """
    Given a list of image objects, compute and display a Ghost solution image
    based on these images. There will be at least 3 images and they will all
    be the same size.

    Input:
        images (List[SimpleImage]): list of images to be processed
    """
    width = images[0].width
    height = images[0].height
    result = SimpleImage.blank(width, height)
    ######## YOUR CODE STARTS HERE #########
    # Write code to populate image and create the 'ghost' effect
    for x in range(result.width):
        for y in range(result.height):
            pixel = get_best_pixel([
                images[0].get_pixel(x, y), images[1].get_pixel(x, y),
                images[2].get_pixel(x, y), images[3].get_pixel(x, y)
            ])
            result.set_pixel(x, y, pixel)
    # use nested for loop to get and run through all pixels in all four images
    # use get_best_pixel to get the best pixel in each (x, y)
    # set that best pixel on the result
    """
    green_pixel = SimpleImage.blank(20, 20, 'green').get_pixel(0, 0)
    red_pixel = SimpleImage.blank(20, 20, 'red').get_pixel(0, 0)
    blue_pixel = SimpleImage.blank(20, 20, 'blue').get_pixel(0, 0)
    best1 = get_best_pixel([green_pixel, green_pixel, green_pixel, blue_pixel])
    print(best1.red, best1.green, best1.blue)
    
    print(get_average([green_pixel, green_pixel, green_pixel, blue_pixel]))
    
    green_im = SimpleImage.blank(20, 20, 'green')
    green_pixel = green_im.get_pixel(0 ,0)
    print(get_pixel_dist(green_pixel, 5, 255, 10))
    """
    ######## YOUR CODE ENDS HERE ###########
    print("Displaying image!")
    result.show()
def main():
    # Get file and load image
    filename = get_file()
    image = SimpleImage(filename)

    # Show the image before the transform
    image.show()

    # Apply the filter
    for pixel in image:
        pixel.red = pixel.red * 1.5
        pixel.green = pixel.green * .07
        pixel.blue = pixel.blue * 1.5

    # Show the image after the transform
    image.show()
Ejemplo n.º 30
0
def add_border(original_img, border_sz):
    """
    This function returns a new SimpleImage which is the same as
    original image except with a black border added around it. The
    border should be border_sz many pixels thick.

    Inputs:
        - original_img: The original image to process
        - border_sz: The thickness of the border to add around the image

    Returns:
        A new SimpleImage with the border added around original image

    - Create a new image
    - for each in pixel (nested loop version)
        - if pixel is a border pixel
            - set it to black
        - else
            - set it to orginal image pixel
    """
    new_image_height = original_img.height + 2 * border_sz
    new_image_width = original_img.width + 2 * border_sz
    new_image = SimpleImage.blank(new_image_width, new_image_height)

    for x in range(new_image_width):
        for y in range(new_image_height):
            new_pixel = new_image.get_pixel(x, y)
            if is_border_pixel(x, y, border_sz, new_image_width,
                               new_image_height):
                new_pixel.red = 0
                new_pixel.green = 0
                new_pixel.blue = 0
            else:
                old_x = x - border_sz
                old_y = y - border_sz
                new_pixel = original_img.get_pixel(old_x, old_y)
                new_image.set_pixel(x, y, new_pixel)

    return new_image