Ejemplo n.º 1
0
def combine (image1: Image, image2: Image, image3: Image) -> Image: 
    """ Author: Bardia Parmoun 
    Type Annotations: Cimpl.Image, Cimpl.Image, Cimpl.Image -> Cimpl.Image
   
    This functions three filtered images (red, green, blue) and creates a new 
    image by combining the rgb's of these three images. 
   
    Note that in order for this function to work properly the three input images
    must be in .png format and should be properly filtered (for example the red
    image must only have a red component in its rgb).
   
    >>> combined_image= combine (red_image,green_image, blue_image)
    >>> show (combined_image)
    (This will display the combined image made from the three input images)
    """
    
    new_image = copy(image1)
    width = get_width(image1)
    height = get_height(image1)
    
    for x in range(width):
        for y in range(height):
            r1,g1,b1= get_color(image1, x, y)
            r2,g2,b2= get_color(image2, x, y)
            r3,g3,b3= get_color(image3, x, y)  
            
            # Combining the there pictures by adding their rgb values
            new_colour = create_color(r1+r2+r3, g1+g2+g3, b1+b2+b3)
            set_color (new_image, x,y, new_colour)   
    return new_image
Ejemplo n.º 2
0
def detect_edges(original_image: Image, threshold: int) -> Image:
    """ Developed by Karandev Andotra, 101141882
        Reviewed by Hussein Rashid, 101141962
    
    Return an edge detection modified copy of an image from a user-selected 
    original image and an input threshold value.
    
    >>> original_image = load_image(choose_file())
    >>> detect_edges_image = detect_edges(original_image, 10)
    """
    new_image = copy(original_image)
    width = get_width(original_image)
    height = get_height(original_image)

    for x in range(width):
        for y in range(height):
            if not y == height - 1:
                r, g, b = get_color(new_image, x, y)
                r_down, g_down, b_down = get_color(new_image, x, y + 1)

                brightness = (r + g + b) // 3
                brightness_down = (r_down + g_down + b_down) // 3

                if abs(brightness - brightness_down) > threshold:
                    new_color = create_color(0, 0, 0)
                else:
                    new_color = create_color(255, 255, 255)
                set_color(new_image, x, y, new_color)
            else:
                new_color = create_color(255, 255, 255)
                set_color(new_image, x, y, new_color)
    return new_image
Ejemplo n.º 3
0
def combine_test(red_image,green_image,blue_image,combined_image):
   
    print("Testing Combined Image...")
    failed_pixels = []
    passed = False
    for pixel in combined_image:
        x, y, (r, g, b) = pixel
        comb_pix = r,g,b
        r1,g,b = get_color(red_image,x,y)
        r,g1,b = get_color(green_image,x,y)
        r,g,b1 = get_color(blue_image,x,y)
        acc_pix = (r1,g1,b1)
        #print ("Testing Pixels:",x,y,"RGB:",comb_pix,"with RGB:", acc_pix) 
        if (acc_pix) == (comb_pix):
            passed = True
            #print("PASSED")
        else:
            #print("FAILED")
            pix = x,y
            failed_pixels.append(pix)
            
    if len(failed_pixels) > 0:
        print("Test Failed...Failed Pixels:")
        print(failed_pixels)        
    else:
        print("Test Passed")
Ejemplo n.º 4
0
def flip_horizontal (image: Image) -> Image:
    """ Author: Bardia Parmoun 
    Type Annotations: Cimpl.Image -> Cimpl.Image

    This function takes an image, makes a copy of it and then it flips it along
    the horizontal axis. It does that by swapping the colours of the pixels that
    are the same distance from the top and bottom of the image. 
    
    >>> new=flip_horizontal (original_image)
    >>> show(new)
    (It will display a version of the image that has been flipped along the 
    horizontal axis)
    """    
    
    new_image = copy(image)
    WIDTH = new_image.get_width()
    HEIGHT = new_image.get_height()
    
    for x in range (WIDTH):
        for y in range (HEIGHT//2): # Only half of the height is needed
            # Replaces the colour of the pixel with a pixel that is equally
            # Distant from the bottom of the image (Same x value but the y value
            # Becomes HEIGHT - y -1
            col1 = get_color(new_image,x,y)
            col2 = get_color(new_image,x,HEIGHT-y-1)
            set_color(new_image, x,y, col2)
            set_color(new_image, x,HEIGHT-y-1, col1)
    return new_image
def detect_edges(image: Image, threshold: float) -> Image:
    """Returns a copy of an image with the pixels changed to either black 
    or white based on the contrast of the pixel above or below based on 
    inputed threshold.
    
    *Written by Sam Hurd*
    
    >>>detect_edges(image, 5)
    """

    image = copy(image)
    height = get_height(image)
    width = get_width(image)
    black = create_color(0, 0, 0)
    white = create_color(255, 255, 255)

    for x in range(0, width):
        set_color(image, x, height - 1, white)

    for y in range(0, height - 1):
        for x in range(0, width):
            r, g, b = get_color(image, x, y)
            brightness1 = (r + g + b) // 3
            r2, g2, b2 = get_color(image, x, y + 1)
            brightness2 = (r2 + g2 + b2) // 3
            contrast = abs(brightness1 - brightness2)

            if contrast >= threshold:
                set_color(image, x, y, black)
            else:
                set_color(image, x, y, white)

    return image
Ejemplo n.º 6
0
def combine_test(red_image,green_image,blue_image,combined_image):
    '''
    Takes in the three images being combined and checks if their combination 
    is equal to that of the combined image. Prints out the pixel being tested
    and the RGB values. 
    >>>combine_test(r_image, g_image, b_image, combined_image)
    Testing Combined Image...
    Testing Pixels: 225 473 RGB: (151, 144, 90) with RGB: (151, 144, 90)
    ...
    ...
    ...
    '''
   
    print("Testing Combined Image...")
    for pixel in combined_image:
        x, y, (r, g, b) = pixel
        comb_pix = r,g,b
        r1,g,b = get_color(red_image,x,y)
        r,g1,b = get_color(green_image,x,y)
        r,g,b1 = get_color(blue_image,x,y)
        acc_pix = (r1,g1,b1)
        print ("Testing Pixels:",x,y,"RGB:",comb_pix,"with RGB:", acc_pix) 
        if (acc_pix) != (comb_pix):
            print("FAILED")
        else:
            print("PASSED")
Ejemplo n.º 7
0
def detect_edges(original_image: Image, threshold: float) -> Image:
    """Takes an image, makes a copy of it and changes the color of the pixels
    to black or white, depending on their contrast.

    - Function written by Malak Abdou - 101139692

    >>> original_image = load_image(choose_file())
    >>> show(detect_edges(original_image, 15))
    # Returns image with detect_edges filter applied with a threshold of 15
    without modifying original.
    """

    original2 = copy(original_image)

    black = create_color(0, 0, 0)
    white = create_color(255, 255, 255)

    for x in range(get_width(original2)):

        for y in range(get_height(original2) - 1):

            r, g, b = get_color(original2, x, y)
            r1, g1, b1 = get_color(original2, x, (y + 1))

            brightness = (r + g + b) / 3
            brightness1 = (r1 + g1 + b1) / 3

            if abs(brightness - brightness1) > threshold:
                set_color(original2, x, y, black)
            else:
                set_color(original2, x, y, white)

    return original2
def combine(red_image: Image, green_image: Image, blue_image: Image) -> Image:
    """
    Returns a single image that is a combination
    of the three r, g, b values of the inputed images.
    
    written by: Anita Ntomchukwu
    
    >>>combine(red_image, green_image, blue_image)
    image that looks exactly like the image before being passed through the red,
    green and blue channel filters.
    """

    original_image1 = red_image
    original_image2 = green_image
    original_image3 = blue_image

    comb = copy(original_image1)

    for x, y, (r, g, b) in comb:

        red = get_color(original_image1, x, y)[0]
        green = get_color(original_image2, x, y)[1]
        blue = get_color(original_image3, x, y)[2]

        new_color = create_color(red, green, blue)
        set_color(comb, x, y, new_color)

    return comb
def test_adjust_component() -> None:
    """Function tests the helper function "_adjust_component."
    -Written by Nathan Gomes, 101143780
    
    >>> test_adjust_component()
    (0, 0) PASSED
    ------
    >>> test_adjust_component()
    (0, 0) FAILED: expected Color(red=31, green=95, blue=158), got Color(red=31, green=95, blue=159)
    ------

    """

    original_image = create_image(1, 1)
    set_color(original_image, 0, 0, create_color(50, 90, 155))

    expected_image = create_image(1, 1)
    set_color(expected_image, 0, 0, create_color(31, 95, 159))

    r, g, b = get_color(original_image, 0, 0)
    adjusted_image = create_image(1, 1)
    set_color(
        adjusted_image, 0, 0,
        create_color(_adjust_component(r), _adjust_component(g),
                     _adjust_component(b)))

    for x, y, col in adjusted_image:
        check_equal("(" + str(x) + ", " + str(y) + ")", col,
                    get_color(expected_image, x, y))
Ejemplo n.º 10
0
def flip_vertical(image: Image) -> Image:
    """Author: Ian Holmes 
    Type Annotations: Cimpl.Image -> Cimpl.Image

    Return a copy of the inputted image, with the pixels flipped along the
    y axis. 
    
    >>> new = flip_horizontal(image)
    >>> show(new)
    """
    
    new_image = copy(image)
    
    width = get_width(image)
    height = get_height(image)
    
    for y in range(height):
        for x in range(width//2):
            # Replaces the colour of the pixel with a pixel that is equally
            # Distant from the right of the image (Same y value but the x value
            # Becomes WIDTH - x -1            
            col1 = get_color(new_image, x, y)
            col2 = get_color(new_image, width-x-1, y)
            set_color(new_image, x, y, col2)
            set_color(new_image, width-x-1,y, col1)
            
    return new_image
Ejemplo n.º 11
0
def detect_edges_better(original_image: Image, threshold: float) -> Image:
    """Returns an image that looks like a pencil sketch of the original image,
    changing the pixels' colors to black or white.
    - Function written by Leanne Matamoros - 101147405

    >>> imp_edge(original_image, 15)
    <Cimpl.Image object at 0x000002096DEEA148>
    """
    edges_copy = copy(original_image)

    width = get_width(edges_copy)
    height = get_height(edges_copy)

    for x in range(width):
        for y in range(height):

            r, g, b = get_color(edges_copy, x, y)
            brightness = (r + g + b) / 3

            if y != (height - 1):
                r1, g1, b1 = get_color(edges_copy, x, (y + 1))
                brightness1 = (r1 + g1 + b1) / 3

            if x != (width - 1):
                r2, g2, b2 = get_color(edges_copy, (x + 1), y)
                brightness2 = (r2 + g2 + b2) / 3

            black = create_color(0, 0, 0)
            white = create_color(255, 255, 255)

            if x == (width - 1) and y == (height - 1):
                set_color(edges_copy, x, y, white)

            elif x != (width - 1) or y != (height - 1):
                if abs(brightness - brightness1) > threshold or abs(
                        brightness - brightness2) > threshold:
                    set_color(edges_copy, x, y, black)

                elif abs(brightness - brightness1) < threshold or abs(
                        brightness - brightness2) < threshold:
                    set_color(edges_copy, x, y, white)

            elif x == (width - 1):
                if abs(brightness - brightness1) > threshold:
                    set_color(edges_copy, x, y, black)

                elif abs(brightness - brightness1) < threshold:
                    set_color(edges_copy, x, y, white)

            elif y == (height - 1):
                if abs(brightness - brightness2) > threshold:
                    set_color(edges_copy, x, y, black)

                elif abs(brightness - brightness2) < threshold:
                    set_color(edges_copy, x, y, white)

    return edges_copy
Ejemplo n.º 12
0
def test_three_tone() -> None:
    """ Developed by Ahmed Abdellah, 101163588
        Reviewed by Karandev Andotra, 101141882
    
    Test whether three_tone function pass or fail.
    
    >>> test_three_tone()
    """

    original = create_image(6, 1)
    set_color(original, 0, 0, create_color(0, 0, 0))
    set_color(original, 1, 0, create_color(80, 84, 88))
    set_color(original, 2, 0, create_color(80, 85, 90))
    set_color(original, 3, 0, create_color(150, 170, 190))
    set_color(original, 4, 0, create_color(170, 171, 172))
    set_color(original, 5, 0, create_color(255, 255, 255))

    expected_wbr = create_image(6, 1)
    set_color(expected_wbr, 0, 0, create_color(0, 0, 0))
    set_color(expected_wbr, 1, 0, create_color(0, 0, 0))
    set_color(expected_wbr, 2, 0, create_color(255, 255, 255))
    set_color(expected_wbr, 3, 0, create_color(255, 255, 255))
    set_color(expected_wbr, 4, 0, create_color(255, 0, 0))
    set_color(expected_wbr, 5, 0, create_color(255, 0, 0))

    expected_lby = create_image(6, 1)
    set_color(expected_lby, 0, 0, create_color(0, 255, 0))
    set_color(expected_lby, 1, 0, create_color(0, 255, 0))
    set_color(expected_lby, 2, 0, create_color(0, 0, 255))
    set_color(expected_lby, 3, 0, create_color(0, 0, 255))
    set_color(expected_lby, 4, 0, create_color(255, 255, 0))
    set_color(expected_lby, 5, 0, create_color(255, 255, 0))

    expected_cmg = create_image(6, 1)
    set_color(expected_cmg, 0, 0, create_color(0, 255, 255))
    set_color(expected_cmg, 1, 0, create_color(0, 255, 255))
    set_color(expected_cmg, 2, 0, create_color(255, 0, 255))
    set_color(expected_cmg, 3, 0, create_color(255, 0, 255))
    set_color(expected_cmg, 4, 0, create_color(128, 128, 128))
    set_color(expected_cmg, 5, 0, create_color(128, 128, 128))

    three_tone_image = three_tone(original, "black", "white", "red")
    for x, y, col in three_tone_image:
        check_equal('Checking pixel @(' + str(x) + ', ' + str(y) + ')', col,
                    get_color(expected_wbr, x, y))

    three_tone_image = three_tone(original, "lime", "blue", "yellow")
    for x, y, col in three_tone_image:
        check_equal('Checking pixel @(' + str(x) + ', ' + str(y) + ')', col,
                    get_color(expected_lby, x, y))

    three_tone_image = three_tone(original, "cyan", "magenta", "gray")
    for x, y, col in three_tone_image:
        check_equal('Checking pixel @(' + str(x) + ', ' + str(y) + ')', col,
                    get_color(expected_cmg, x, y))
def detect_edges_better(img: Image, threshold: int) -> Image:
    """
    Returns a copy of an image with the pixels changed to either black 
    or white based on the contrast of the pixel above, below, or to the right
    based on the inputed threshold.
    
    Author: Anita Ntomchukwu
    
    >>>detect_edges(img, 5)
    """
    new_img = copy(img)
    height = get_height(img)
    width = get_width(img)
    black = create_color(0, 0, 0)
    white = create_color(255, 255, 255)

    set_color(new_img, width - 1, height - 1, white)

    for x in range(0, width):
        set_color(new_img, x, height - 1, white)

    for y in range(0, height - 1):
        for x in range(0, width):

            color1 = get_color(img, x, y)
            color2 = get_color(img, x, y + 1)
            brightness1 = (color1[0] + color1[1] + color1[2]) // 3
            brightness2 = (color2[0] + color2[1] + color2[2]) // 3

            difference1 = abs(brightness1 - brightness2)

            if difference1 > threshold:
                set_color(new_img, x, y, black)
            else:
                set_color(new_img, x, y, white)

    for y in range(0, height):
        for x in range(0, width - 1):

            color3 = get_color(img, x, y)
            color4 = get_color(img, x + 1, y)
            brightness3 = (color3[0] + color3[1] + color3[2]) // 3
            brightness4 = (color4[0] + color4[1] + color4[2]) // 3

            difference2 = abs(brightness3 - brightness4)

            if difference2 > threshold:
                set_color(new_img, x, y, black)
            else:
                set_color(new_img, x, y, white)

    return new_img
Ejemplo n.º 14
0
def detect_edges_better (image:Image, threshold: float) -> Image:  
    """ Author: Benjamin Richards 
    Type Annotations: Cimpl.Image, float -> Cimpl.Image

    This function tries to find the edges of a given image by going through 
    every pixel and checking its brightness with the one below and to the right
    of it. That difference is compared with a given threshold value. In other 
    words the function will produce a black and white version of the image where
    the background is white and the main parts of the image is black. 
    
    >>> new_image= detect_edge_better(copied_image,10)
    >>> show(new_image)
    (Shows the new black and white image generated by detecting edges)
    """
    
    new_image = copy(image)  
    
    # Constants
    WIDTH = new_image.get_width()
    HEIGHT = new_image.get_height()
    
    BACK = (255,255,255)
    EDGE = (0,0,0)
    
    for x in range (WIDTH):
        for y in range (HEIGHT):
            r,g,b = get_color(new_image,x,y)
            brightness = (r+g+b)/3
            
            # The default colour value is set to BACK (white). This value later
            # Can change to EDGE (black) if the difference exceeds the threshold
            new_colour = create_color(BACK[0],BACK[1],BACK[2])
            
            if y != HEIGHT-1 and x != WIDTH -1:  
                # Makes sure the range doesn't exceed the height and the width
                # Calculates the brightness of the pixel below it
                r_down,g_down,b_down = get_color(new_image,x,y+1)
                brightness_down = (r_down+g_down+b_down)/3
                
                r_right,g_right,b_right=get_color(new_image,x+1,y)
                brightness_right = (r_right+g_right+b_right)/3                 
                
                # Checks to see if the difference between the brightness values
                # Exceeds the threshold and if so converts it to black
                if (abs(brightness-brightness_down) > threshold or 
                    abs(brightness-brightness_right) > threshold):
                    new_colour= create_color (EDGE[0],EDGE[1],EDGE[2])
                    
            set_color(new_image, x, y, new_colour)
       
    return new_image 
Ejemplo n.º 15
0
def combine(red_pic: Image, green_pic: Image, blue_pic: Image) -> Image:
    # Author: Siddharth Natamai - 101143016
    """Combines the inputted images and returns the final image
    >>> combine(image_1, image_2, image_3)
    <Cimpl.Image object at 0x7fab575d3ad0>
    """
    final_image = copy(red_pic)
    for pixel in final_image:
        x, y, (r, g, b) = pixel
        blue_colour = get_color(blue_pic, x, y)
        green_colour = get_color(green_pic, x, y)
        new_colours = create_color(r, green_colour[1], blue_colour[2])
        set_color(final_image, x, y, new_colours)

    return final_image
Ejemplo n.º 16
0
def combine(red_image:Image, green_image:Image, blue_image:Image) -> Image:
    '''Takes in three images, a red one, a green one and a blue one and returns
    one image which is the a combination of all three
    >>> combined_image = combine(red_image, green_image, blue_image)
    >>> show(combined_image)
    '''
    
    new_image = copy(red_image)
    for pixel in new_image:     
        x, y, (r,b,g) = pixel
        r1,g1,b = get_color(green_image,x,y)
        r1,g,b1 = get_color(blue_image,x,y)
        original = create_color(r,g1,b1)
        set_color(new_image, x, y, original)  
    return new_image
Ejemplo n.º 17
0
def detect_edges (image: Image, threshold: float) -> Image:  
    """ Author: Hao Lin  
    Type Annotations: Cimpl.Image, float -> Cimpl.Image

    This function tries to find the edges of a given image by going through 
    every pixel and checking its brightness with the one below it. That 
    difference is compared with a given threshold value. In other words the 
    function will produce a black and white version of the image where the 
    background is white and the main parts of the image is black. 
    
    >>> new_image= detect_edge(original_image,10)
    >>> show(new_image)
    (Shows the new black and white image generated by detecting edges)
    """
    
    new_image = copy(image)
    
    #Constants
    WIDTH = new_image.get_width()
    HEIGHT = new_image.get_height()
    
    BACK = (255,255,255)
    EDGE = (0,0,0)
    
    for x in range (WIDTH):
        for y in range (HEIGHT-1):
            r,g,b = get_color(new_image,x,y)
            r_bottom,g_bottom,b_bottom=get_color(new_image,x,y+1)
            
            # Finds the brightness of the pixel and the one below it by taking
            # An average of their rgb values
            brightness = (r+g+b)/3
            brightness_bottom = (r_bottom+g_bottom+b_bottom)/3
            
            # If the difference between the brightness values is more than the
            # The threshold then it is replaced by the EDGE colour (black) and
            # Otherwise it is replaced with the BACK colour (white)
            if abs(brightness-brightness_bottom) > threshold:
                new_colour = create_color (EDGE[0],EDGE[1],EDGE[2])
            else:
                new_colour = create_color(BACK[0],BACK[1],BACK[2])
            set_color(new_image, x,y, new_colour)
            
        # The last row can't be compared with anything so it's set to BACK 
        # Automatically
        new_colour = create_color(BACK[0],BACK[1],BACK[2])
        set_color(new_image, x, HEIGHT-1, new_colour)        
    return new_image  
def test_flip_vertical() -> None:
    '''Function Name: Flip Vertical Test
    Author: Taekwan Oh 101148069
    '''
    """ Returns Pass or Fail if the image is correctly flipped vetically
    test_flip_vertical().
    >>>test_flip_vertical()
    Checking pixel @(0, 0) PASSED
    ------
    Checking pixel @(1, 0) PASSED
    ------
    Checking pixel @(2, 0) PASSED
    """
    original = create_image(3, 2)
    set_color(original, 0, 0, create_color(0, 0, 0))
    set_color(original, 1, 0, create_color(90, 90, 90))
    set_color(original, 2, 0, create_color(255, 255, 255))
    set_color(original, 0, 1, create_color(10, 10, 10))
    set_color(original, 1, 1, create_color(0, 0, 0))
    set_color(original, 2, 1, create_color(90, 90, 90))

    expected = create_image(3, 2)
    set_color(expected, 0, 0, create_color(10, 10, 10))
    set_color(expected, 1, 0, create_color(0, 0, 0))
    set_color(expected, 2, 0, create_color(90, 90, 90))
    set_color(expected, 0, 1, create_color(0, 0, 0))
    set_color(expected, 1, 1, create_color(90, 90, 90))
    set_color(expected, 2, 1, create_color(255, 255, 255))

    flipped_vertical = flip_vertical(original)

    for x, y, col in flipped_vertical:
        check_equal('Checking pixel @(' + str(x) + ', ' + str(y) + ')', col,
                    get_color(expected, x, y))
def test_three_tone():
    ''' tests the three-tone filter, assuming the two strings passed in are 
    black and white and gray respectivley.
    >>>test_three_tone()
    
    '''
    #Creates the test image
    original = create_image(6, 1)
    set_color(original, 0, 0, create_color(0, 0, 0))
    set_color(original, 1, 0, create_color(85, 88, 95))
    set_color(original, 2, 0, create_color(127, 127, 127))
    set_color(original, 3, 0, create_color(189, 172, 224))
    set_color(original, 4, 0, create_color(254, 255, 255))
    set_color(original, 5, 0, create_color(87, 28, 25))

    #Proper Image after three_tone is applied
    actual = create_image(6, 1)
    set_color(actual, 0, 0, create_color(0, 0, 0))
    set_color(actual, 1, 0, create_color(255, 255, 255))
    set_color(actual, 2, 0, create_color(255, 255, 255))
    set_color(actual, 3, 0, create_color(128, 128, 128))
    set_color(actual, 4, 0, create_color(128, 128, 128))
    set_color(actual, 5, 0, create_color(0, 0, 0))

    threet_image = three_tone(original, 'black', 'white', 'gray')
    for x, y, col in threet_image:
        check_equal('Checking pixel @(' + str(x) + ', ' + str(y) + ')', col,
                    get_color(actual, x, y))
Ejemplo n.º 20
0
def test_blue() -> None:
    '''A test function for the blue_channel filter.
    
    written by Yahya Shah.

    >>>test_blue()
    '''
    print('=============================')
    print('     TESTING BLUE FILTER     ')
    print('=============================')

    original = create_image(6, 1)
    set_color(original, 0, 0, create_color(0, 0, 0))
    set_color(original, 1, 0, create_color(255, 0, 0))
    set_color(original, 2, 0, create_color(0, 255, 0))
    set_color(original, 3, 0, create_color(0, 0, 255))
    set_color(original, 4, 0, create_color(127, 127, 127))
    set_color(original, 5, 0, create_color(255, 255, 255))

    expected = create_image(6, 1)
    set_color(expected, 0, 0, create_color(0, 0, 0))
    set_color(expected, 1, 0, create_color(0, 0, 0))
    set_color(expected, 2, 0, create_color(0, 0, 0))
    set_color(expected, 3, 0, create_color(0, 0, 255))
    set_color(expected, 4, 0, create_color(0, 0, 127))
    set_color(expected, 5, 0, create_color(0, 0, 255))

    bluescale = T.blue_channel(original)
    for x, y, col in bluescale:
        check_equal('Checking pixel @(' + str(x) + ', ' + str(y) + ')', col,
                    get_color(expected, x, y))
Ejemplo n.º 21
0
def test_extreme_contrast():
    ''' tests the two-tone filter, assuming the two strings passed in are 
    black and white respectivley.
    >>>test_two_tone()
    Checking pixel @(0, 0) PASSED
    ------
    Checking pixel @(1, 0) PASSED
    ------
    '''
    #Creates the test image
    original = create_image(6, 1)
    set_color(original, 0, 0, create_color(0, 0, 0))
    set_color(original, 1, 0, create_color(0, 128, 128))
    set_color(original, 2, 0, create_color(127, 127, 127))
    set_color(original, 3, 0, create_color(125, 73, 224))
    set_color(original, 4, 0, create_color(254, 255, 255))
    set_color(original, 5, 0, create_color(126, 127, 128))

    #Proper Image after extreme contrast is applied
    actual = create_image(6, 1)
    set_color(actual, 0, 0, create_color(0, 0, 0))
    set_color(actual, 1, 0, create_color(0, 255, 255))
    set_color(actual, 2, 0, create_color(0, 0, 0))
    set_color(actual, 3, 0, create_color(0, 0, 255))
    set_color(actual, 4, 0, create_color(255, 255, 255))
    set_color(actual, 5, 0, create_color(0, 0, 255))

    twot_image = extreme_contrast(original)
    for x, y, col in twot_image:
        check_equal('Checking pixel @(' + str(x) + ', ' + str(y) + ')', col,
                    get_color(actual, x, y))
Ejemplo n.º 22
0
def test_green() -> None:
    '''A test function for the green_channel filter.
    
    written by Nathan MacDiarmid.

    >>>test_green()
    '''
    print('=============================')
    print('     TESTING GREEN FILTER    ')
    print('=============================')

    original = create_image(6, 1)
    set_color(original, 0, 0, create_color(0, 0, 0))
    set_color(original, 1, 0, create_color(255, 0, 0))
    set_color(original, 2, 0, create_color(0, 255, 0))
    set_color(original, 3, 0, create_color(0, 0, 255))
    set_color(original, 4, 0, create_color(127, 127, 127))
    set_color(original, 5, 0, create_color(255, 255, 255))

    expected = create_image(6, 1)
    set_color(expected, 0, 0, create_color(0, 0, 0))
    set_color(expected, 1, 0, create_color(0, 0, 0))
    set_color(expected, 2, 0, create_color(0, 255, 0))
    set_color(expected, 3, 0, create_color(0, 0, 0))
    set_color(expected, 4, 0, create_color(0, 127, 0))
    set_color(expected, 5, 0, create_color(0, 255, 0))

    greenscale = T.green_channel(original)
    for x, y, col in greenscale:
        check_equal('Checking pixel @(' + str(x) + ', ' + str(y) + ')', col,
                    get_color(expected, x, y))
Ejemplo n.º 23
0
def test_horizontal() -> None:
    """
    A test for the flip_horizontal filter.
    
    *written by Nathan MacDiarmid*
    
    >>> test_horizontal()
    """
    print('=============================')
    print('      TESTING HORIZONTAL     ')
    print('=============================')

    original = create_image(1, 6)
    set_color(original, 0, 0, create_color(0, 0, 0))
    set_color(original, 0, 1, create_color(127, 127, 127))
    set_color(original, 0, 2, create_color(56, 66, 32))
    set_color(original, 0, 3, create_color(150, 177, 132))
    set_color(original, 0, 4, create_color(200, 199, 255))
    set_color(original, 0, 5, create_color(255, 255, 255))

    expected = create_image(1, 6)
    set_color(expected, 0, 0, create_color(255, 255, 255))
    set_color(expected, 0, 1, create_color(200, 199, 255))
    set_color(expected, 0, 2, create_color(150, 177, 132))
    set_color(expected, 0, 3, create_color(56, 66, 32))
    set_color(expected, 0, 4, create_color(127, 127, 127))
    set_color(expected, 0, 5, create_color(0, 0, 0))

    new_horizontal = T.flip_horizontal(original)
    for x, y, col in new_horizontal:
        check_equal('Checking pixel @(' + str(x) + ', ' + str(y) + ')', col,
                    get_color(expected, x, y))
Ejemplo n.º 24
0
def test_vertical() -> None:
    """
    A test for the flip_vertical filter.
    
    Author: Yahya Shah
    
    >>> test_vertical()
    """
    print('=============================')
    print('       TESTING VERTICAL      ')
    print('=============================')

    original = create_image(6, 1)
    set_color(original, 0, 0, create_color(0, 0, 0))
    set_color(original, 1, 0, create_color(127, 127, 127))
    set_color(original, 2, 0, create_color(56, 66, 32))
    set_color(original, 3, 0, create_color(150, 177, 132))
    set_color(original, 4, 0, create_color(200, 199, 255))
    set_color(original, 5, 0, create_color(255, 255, 255))

    expected = create_image(6, 1)
    set_color(expected, 0, 0, create_color(255, 255, 255))
    set_color(expected, 1, 0, create_color(200, 199, 255))
    set_color(expected, 2, 0, create_color(150, 177, 132))
    set_color(expected, 3, 0, create_color(56, 66, 32))
    set_color(expected, 4, 0, create_color(127, 127, 127))
    set_color(expected, 5, 0, create_color(0, 0, 0))

    vert = T.flip_vertical(original)
    for x, y, col in vert:
        check_equal('Checking pixel @(' + str(x) + ', ' + str(y) + ')', col,
                    get_color(expected, x, y))
Ejemplo n.º 25
0
def test_detect_edges() -> None:
    """A test function for the detect_edges filter.
    
    Author: Anita Ntomchukwu
    
    >>>test_detect_edges()
    """

    print('=============================')
    print('    TESTING EDGE DETECTION   ')
    print('=============================')

    original = create_image(1, 6)
    set_color(original, 0, 0, create_color(23, 34, 26))
    set_color(original, 0, 1, create_color(36, 52, 21))
    set_color(original, 0, 2, create_color(16, 10, 52))
    set_color(original, 0, 3, create_color(96, 79, 42))
    set_color(original, 0, 4, create_color(127, 225, 255))
    set_color(original, 0, 5, create_color(80, 200, 160))

    expected = create_image(1, 6)
    set_color(expected, 0, 0, create_color(0, 0, 0))
    set_color(expected, 0, 1, create_color(0, 0, 0))
    set_color(expected, 0, 2, create_color(0, 0, 0))
    set_color(expected, 0, 3, create_color(0, 0, 0))
    set_color(expected, 0, 4, create_color(0, 0, 0))
    set_color(expected, 0, 5, create_color(255, 255, 255))

    detect_edges_image = T.detect_edges(original, 5)
    for x, y, col in detect_edges_image:
        check_equal('Checking pixel @(' + str(x) + ', ' + str(y) + ')', col,
                    get_color(expected, x, y))
Ejemplo n.º 26
0
def test_posterize() -> None:
    """A test function for the posterize filter.

    Author: Anita Ntomchukwu

    >>>test_posterize()
    """

    print('=============================')
    print('      TESTING POSTERIZE      ')
    print('=============================')

    original = create_image(6, 1)
    set_color(original, 0, 0, create_color(72, 240, 0))
    set_color(original, 1, 0, create_color(80, 127, 255))
    set_color(original, 2, 0, create_color(255, 255, 255))
    set_color(original, 3, 0, create_color(117, 111, 123))
    set_color(original, 4, 0, create_color(33, 72, 66))
    set_color(original, 5, 0, create_color(202, 152, 247))

    expected = create_image(6, 1)
    set_color(expected, 0, 0, create_color(95, 223, 31))
    set_color(expected, 1, 0, create_color(95, 95, 223))
    set_color(expected, 2, 0, create_color(223, 223, 223))
    set_color(expected, 3, 0, create_color(95, 95, 95))
    set_color(expected, 4, 0, create_color(31, 95, 95))
    set_color(expected, 5, 0, create_color(223, 159, 223))

    posterize_image = T.posterize(original)
    for x, y, col in posterize_image:
        check_equal('Checking pixel @(' + str(x) + ', ' + str(y) + ')', col,
                    get_color(expected, x, y))
Ejemplo n.º 27
0
def test_sepia() -> None:
    """
    A test function for the sepia filter.
    
    *written by Nathan MacDiarmid*
    
    >>> test_sepia()
    """
    print('=============================')
    print('        TESTING SEPIA        ')
    print('=============================')

    original = create_image(6, 1)
    set_color(original, 0, 0, create_color(0, 0, 0))
    set_color(original, 1, 0, create_color(127, 127, 127))
    set_color(original, 2, 0, create_color(56, 66, 32))
    set_color(original, 3, 0, create_color(150, 177, 132))
    set_color(original, 4, 0, create_color(200, 199, 255))
    set_color(original, 5, 0, create_color(255, 255, 255))

    expected = create_image(6, 1)
    set_color(expected, 0, 0, create_color(0, 0, 0))
    set_color(expected, 1, 0, create_color(146, 127, 107))
    set_color(expected, 2, 0, create_color(56, 51, 45))
    set_color(expected, 3, 0, create_color(175, 153, 130))
    set_color(expected, 4, 0, create_color(235, 218, 202))
    set_color(expected, 5, 0, create_color(255, 255, 237))

    new_sepia = T.sepia(original)
    for x, y, col in new_sepia:
        check_equal('Checking pixel @(' + str(x) + ', ' + str(y) + ')', col,
                    get_color(expected, x, y))
def test_flip_horizontal() -> None:
    '''Function Name: Test Flip Horizontal 
    Author: Kiyara Desilva 101165279
    '''
    """Returns Pass or Fail if the image is correctly flipped horizontally
    >>>test_flip_horizontal() 
    Checking pixel @(0, 0) PASSED
    ------
    Checking pixel @(1, 0) PASSED
    ------
    Checking pixel @(2, 0) PASSED
    """

    original = create_image(3, 2)
    set_color(original, 0, 0, create_color(0, 0, 0))
    set_color(original, 1, 0, create_color(40, 40, 40))
    set_color(original, 2, 0, create_color(255, 255, 255))
    set_color(original, 0, 1, create_color(100, 100, 100))
    set_color(original, 1, 1, create_color(0, 0, 0))
    set_color(original, 2, 1, create_color(40, 40, 40))

    expected = create_image(3, 2)
    set_color(expected, 0, 0, create_color(40, 40, 40))
    set_color(expected, 1, 0, create_color(0, 0, 0))
    set_color(expected, 2, 0, create_color(255, 255, 255))
    set_color(expected, 0, 1, create_color(100, 100, 100))
    set_color(expected, 1, 1, create_color(0, 0, 0))
    set_color(expected, 2, 1, create_color(40, 40, 40))

    flipped_horizontal = flip_horizontal(original)

    for x, y, col in flipped_horizontal:
        check_equal('Checking pixel @(' + str(x) + ', ' + str(y) + ')', col,
                    get_color(expected, x, y))
Ejemplo n.º 29
0
def test_red() -> None:
    '''A test function for the red_channel filter.

    *written by Sam Hurd*
    
    >>>test_red()
    '''
    print('=============================')
    print('      TESTING RED FILTER     ')
    print('=============================')

    original = create_image(6, 1)
    set_color(original, 0, 0, create_color(0, 0, 0))
    set_color(original, 1, 0, create_color(255, 0, 0))
    set_color(original, 2, 0, create_color(0, 255, 0))
    set_color(original, 3, 0, create_color(0, 0, 255))
    set_color(original, 4, 0, create_color(127, 127, 127))
    set_color(original, 5, 0, create_color(255, 255, 255))

    expected = create_image(6, 1)
    set_color(expected, 0, 0, create_color(0, 0, 0))
    set_color(expected, 1, 0, create_color(255, 0, 0))
    set_color(expected, 2, 0, create_color(0, 0, 0))
    set_color(expected, 3, 0, create_color(0, 0, 0))
    set_color(expected, 4, 0, create_color(127, 0, 0))
    set_color(expected, 5, 0, create_color(255, 0, 0))

    red = T.red_channel(original)
    for x, y, col in red:
        check_equal('Checking pixel @(' + str(x) + ', ' + str(y) + ')', col,
                    get_color(expected, x, y))
Ejemplo n.º 30
0
def test_extreme_contrast() -> None:
    '''A test function for the extreme contrast filter.

    *written by Sam Hurd*
    
    >>>test_extreme_contrast()
    '''
    print('=============================')
    print('   TESTING EXTREME CONTRAST  ')
    print('=============================')

    original = create_image(6, 1)
    set_color(original, 0, 0, create_color(0, 0, 0))
    set_color(original, 1, 0, create_color(255, 127, 129))
    set_color(original, 2, 0, create_color(0, 255, 0))
    set_color(original, 3, 0, create_color(128, 128, 128))
    set_color(original, 4, 0, create_color(127, 127, 127))
    set_color(original, 5, 0, create_color(255, 255, 255))

    expected = create_image(6, 1)
    set_color(expected, 0, 0, create_color(0, 0, 0))
    set_color(expected, 1, 0, create_color(255, 0, 255))
    set_color(expected, 2, 0, create_color(0, 255, 0))
    set_color(expected, 3, 0, create_color(255, 255, 255))
    set_color(expected, 4, 0, create_color(0, 0, 0))
    set_color(expected, 5, 0, create_color(255, 255, 255))

    extreme_contrast_image = T.extreme_contrast(original)
    for x, y, col in extreme_contrast_image:
        check_equal('Checking pixel @(' + str(x) + ', ' + str(y) + ')', col,
                    get_color(expected, x, y))