Exemple #1
0
def apply_filter(image: Cimpl.Image, command: str) -> Cimpl.Image:
    """
    Author: Ibrahim Kasim, Himanshu Singh

    RETURNS a Cimpl.Image object and
    applies a filter to image based on command,
    and displays the result.

    image is a Cimpl.Image object
    command is a str representing the filter to be applied

    >>> apply_filter(Cimpl.load_image(Cimpl.choose_file()), 'X')
    """
    filter_functions = {
        '2': two_tone,
        '3': three_tone,
        'X': extreme_contrast,
        'T': sepia,
        'P': posterize,
        'E': detect_edges,
        'I': detect_edges_better,
        'V': flip_vertical,
        'H': flip_horizontal,
    }

    if command == 'E' or command == 'I':
        image = filter_functions[command](image, prompt_threshold())
    else:
        image = filter_functions[command](image)

    Cimpl.show(image)
    return image
def refresh_board(gameBoard: Cimpl.Image, res: int, color: Cimpl.Color, stateList: List[list]) -> None:
    '''Takes the current states of living & dead blocks, and updates the game 
    board.
    '''
    for x in range((Cimpl.get_width(gameBoard) - 1) // res):
        for y in range((Cimpl.get_height(gameBoard) - 1) // res):
            set_pixel(gameBoard, res, color, *real_coords(res, x, y), stateList[y][x])
def flip_vertical(img: Cimpl.Image) -> Cimpl.Image:
    """
    author: himanshu singh
    flips the image vertically (Cimpl.Image object) and returns it when called.
    
    >>> flip_vertical(Cimpl.load_image("image.jpg"))
    returns a vertically flipped image

    """
    newimage = Cimpl.copy(img)

    height1 = Cimpl.get_height(img)  # get image height

    width1 = Cimpl.get_width(img)  # get image width

    for y in range(height1):

        for x in range(width1):
            change = height1 - y - 1
            # editing height to flip vertically (change)
            # change implemented below to make changes to the actual image passed
            # in below
            Cimpl.set_color(newimage, x, y, Cimpl.get_color(img, x, change))
            Cimpl.set_color(newimage, x, change, Cimpl.get_color(img, x, y))

    return newimage
def set_pixel(image: Cimpl.Image, res: int, color: Cimpl.Color, x: int, y: int, state: bool) -> None:
    '''Modifies the input image by filling in a block (i.e. 15x15) with a color 
    determined by a provided state; white (dead) or black (live). The origin 
    is specified using the "true" coordinates (given by real_coords).
    '''
    if state:
        stateColor = color
    else:
        stateColor = Cimpl.Color(255,255,255)
        
    for yPix in range(res - 1):
        for xPix in range (res - 1):
            Cimpl.set_color(image, x + xPix, y + yPix, stateColor)
Exemple #5
0
def save_image(image: Cimpl.Image) -> None:
    """
    Author: Ibrahim Kasim, Himanshu Singh

    RETURNS None and prompts the user to
    select a filename to save image as

    image is a Cimpl.Image object

    >>> save_image(Cimpl.load_image(Cimpl.choose_file()))
    """

    print("Select your image's save directory")
    Cimpl.save_as(image)
def blue_channel(raw_image: Cimpl.Image) -> Cimpl.Image:
    """Author: Yanglong liu
    RETURNS a Cimpl.Image object
    whose red and green channels
    have been set to 0

    >>> Cimpl.show(blue_channel(Cimpl.load_image('p2-original.png')))
    -> Returns a Cimpl.Image object
    """
    blue_channel_image = Cimpl.copy(raw_image)
    for pi in raw_image:
        x, y, (r, g, b) = pi
        new_image_color = Cimpl.create_color(0, 0, b)
        Cimpl.set_color(blue_channel_image, x, y, new_image_color)
    return blue_channel_image
def blue_channel(img: Cimpl.Image) -> Cimpl.Image:
    """
    Author: Zakaria Ismail

    RETURNS an ImageObject whose
    channels except for blue, have
    been zeroed, after being
    PASSED a Cimpl.Image object

    >>> blue_channel(Cimpl.load_image())
    -> An a green filtered image will be displayed
    """
    copy = Cimpl.copy(img)
    for x, y, (r, g, b) in img:
        Cimpl.set_color(copy, x, y, Cimpl.create_color(0, 0, b))
    return copy
def check_equal(expected: Cimpl.Image, outcome: Cimpl.Image) -> None:
    """
    Author: Zakaria Ismail

    RETURNS nothing. Checks if PARAMETERS expected and outcome,
    both Cimpl.Image objects are:
        1. Of the same type
        2. Have the same pixel at each location - Quantitatively the same

    >>> check_equal(Cimpl.load_image('p2-original.jpg'), Cimpl.load_image('combined_image.png'))
    -> Test results and error messages are printed.
    """
    errors = 0
    if type(expected) == type(outcome):
        for x, y, exp_col in expected:
            out_col = Cimpl.get_color(outcome, x, y)
            if exp_col != out_col:
                print("ERROR: Color discrepancy detected at x:{} y:{}\n"
                      "Expected: {}\n"
                      "Outcome: {}".format(x, y, exp_col, out_col))
                errors += 1
        if errors == 0:
            print(
                "SUCCESS: expected and outcome are of the same type and have identical pixels."
            )
        else:
            print("{} ERRORS detected.".format(errors))
    else:
        print("ERROR: Different types detected.\n"
              "Expected: Type {}\n"
              "Outcome: Type {}".format(type(expected), type(outcome)))
Exemple #9
0
def check_equal(expected: Cimpl.Image, outcome: Cimpl.Image) -> None:
    """
    Author: Zakaria Ismail
    Checks if PARAMETERS expected and outcome,
    both Cimpl.Image objects are:
        1. Of the same type
        2. Have the same pixel at each location - Quantitatively the same
    Assumes both PARAMETERS have the same dimensions <- should this be taken into account?
    """
    errors = 0
    if type(expected) == type(outcome):
        for x, y, exp_col in expected:
            out_col = Cimpl.get_color(outcome, x, y)
            if exp_col != out_col:
                print("ERROR: Color discrepancy detected at x:{} y:{}\n"
                      "Expected: {}\n"
                      "Outcome: {}".format(x, y, exp_col, out_col))
                errors += 1
        if errors == 0:
            print(
                "SUCCESS: expected and outcome are of the same type and have identical pixels."
            )
        else:
            print("{} ERRORS detected.".format(errors))
    else:
        print("ERROR: Different types detected.\n"
              "Expected: Type {}\n"
              "Outcome: Type {}".format(type(expected), type(outcome)))
def red_channel(img: Cimpl.Image) -> Cimpl.Image:
    """
    Author: Zakaria Ismail

    RETURNS an ImageObject whose
    channels except for red, have
    been zeroed, after being
    PASSED a Cimpl.Image object

    >>> Cimpl.show(red_channel('p2-original.png'))
    -> An a red filtered image will be displayed
    """
    copy = Cimpl.copy(img)
    for x, y, (r, g, b) in img:
        Cimpl.set_color(copy, x, y, Cimpl.create_color(r, 0, 0))
    return copy
def red_channel(img: Cimpl.Image) -> Cimpl.Image:
    """
    Author: Zakaria Ismail

    RETURNS an Cimpl.Image object whose
    channels except for red, have
    been zeroed, after being
    PASSED an Cimpl.Image object

    >>> Cimpl.show(red_channel(Cimpl.load_image('p2-original.png')))
    -> Returns a Cimpl.Image object
    """
    copy = Cimpl.copy(img)
    for x, y, (r, g, b) in img:
        Cimpl.set_color(copy, x, y, Cimpl.create_color(r, 0, 0))
    return copy
def save_image(image: Cimpl.Image, filename: str) -> None:
    """
    Authors: Zakaria Ismail, Yanglong Liu

    RETURNS None and saves image
    to the directory using information
    from filename

    image is a Cimpl.Image object that is going to be saved

    filename is a str that defines the image's filename when saved

    >>> save_image(Cimpl.load_image(Cimpl.choose_file()), 'filename.png')
    None
    """
    Cimpl.save_as(image, filename)
def apply_filters(filename: str, commands: list) -> Cimpl.Image:
    """
    Authors: Zakaria Ismail, Yanglong Liu

    RETURNS a Cimpl.Image object and applies filters
    to an image after being PASSED filename and commands

    filename is a string directing to the location of the image file

    commands is a list containing the image filter sequences

    >>> apply_filters('filename.png', ['2', 'X', 'V', 'P'])
    """
    filter_functions = {
        '2': two_tone,
        '3': three_tone,
        'X': extreme_contrast,
        'T': sepia,
        'P': posterize,
        'E': detect_edges,
        'I': detect_edges_better,
        'V': flip_vertical,
        'H': flip_horizontal,
    }

    image = Cimpl.load_image(filename)

    i = 0
    while i < len(commands):
        # Note: Functions that have parameters have default arguments set in T121_image_filters.py
        image = filter_functions[commands[i]](image)
        i += 1
    return image
Exemple #14
0
def load_image() -> Cimpl.Image:
    """
    Author: Ibrahim Kasim, Himanshu Singh

    RETURNS a Cimpl.Image object.

    Prompts the user to select
    an image file to load, and
    displays the loaded image

    >>> load_image()
    """
    print("Select an image file to load")
    image = Cimpl.load_image(Cimpl.choose_file())
    Cimpl.show(image)
    return image
Exemple #15
0
def encrypt(img, string):
    i = 0
    length = len(string) - 1
    for pixel in img:
        x, y, col = pixel
        r, g, b = col

        #Get red component of the pixel in binary in a list
        pixel_red_binary = list(('{0:08b}'.format(r)))

        #Get green component of the pixel in binary in a list
        pixel_green_binary = list(('{0:08b}'.format(g)))

        #Get blue component of the pixel in binary in a list
        pixel_blue_binary = list(('{0:08b}'.format(b)))

        #Set the last digit of the red component to the corresponding string binary value
        if i <= length:
            pixel_red_binary[-1] = string[i]
            i += 1

        #Set the last digit of the green component to the corresponding string binary value
        if i <= length:
            pixel_green_binary[-1] = string[i]
            i += 1

        #Set the last digit of the blue component to the corresponding string binary value
        if i <= length:
            pixel_blue_binary[-1] = string[i]
            i += 1

        #Convert the altered pixel red component in binary from a list to a string
        new_red = ''.join(str(e) for e in pixel_red_binary)
        new_red = int(new_red, 2)

        #Convert the altered pixel green component in binary from a list to a string
        new_green = ''.join(str(e) for e in pixel_green_binary)
        new_green = int(new_green, 2)

        #Convert the altered pixel blue component in binary from a list to a string
        new_blue = ''.join(str(e) for e in pixel_blue_binary)
        new_blue = int(new_blue, 2)

        #Create and Set color
        new_color = Cimpl.create_color(new_red, new_green, new_blue)
        Cimpl.set_color(img, x, y, new_color)
def extreme_contrast(original_image: Cimpl.Image) -> Cimpl.Image:
    """
    The author: Ibrahim Kasim
    returns image object with extreme contrast filter apllied.
    
        >>>test_image = Cimpl.load_image(Cimpl.choose_file())
           extreme_channel(test_image)
        ...(shows orginal image in extreme contrast filter)

    """
    new_image = Cimpl.copy(original_image)
    min_pixel = 0
    max_pixel = 255
    for x, y, colour_tuple in original_image:
        i = 0
        for component in colour_tuple:
            list_colour = list(colour_tuple)
            if component <= 127:
                list_colour[i] = min_pixel
                maximized_contrast = Cimpl.create_color(
                    list_colour[0], list_colour[1], list_colour[2])
                Cimpl.set_color(new_image, x, y, maximized_contrast)
            elif component >= 128:
                list_colour[i] = max_pixel
                maximized_contrast = Cimpl.create_color(
                    list_colour[0], list_colour[1], list_colour[2])
                Cimpl.set_color(new_image, x, y, maximized_contrast)
            i += 1
    return new_image
def green_channel(original_image: Cimpl.Image) -> Cimpl.Image:
    """
    Author: Ibrahim Kasim
    RETURNS a Cimpl.Image object
    after nulling all but the green channel.
    Is PASSED a Cimpl.Image object.

    >>> Cimpl.show(green_channel(Cimpl.load_image('p2-original.png')))
    -> Returns a Cimpl.Image object
    """

    new_image = Cimpl.copy(original_image)
    for pixel in original_image:
        x, y, (r, g, b) = pixel
        green_color = Cimpl.create_color(0, g, 0)
        Cimpl.set_color(new_image, x, y, green_color)

    return new_image
Exemple #18
0
def green_channel(img: Cimpl.Image) -> Cimpl.Image:
    """
    Author: Zakaria Ismail

    RETURNS an ImageObject whose
    channels except for green, have
    been zeroed, after being
    PASSED a Cimpl.Image object

    >>> Cimpl.show(green_channel(Cimpl.load_image(('p2-original.png')))
    -> An a green filtered image will be displayed
    """
    #img = Cimpl.load_image(img)
    copy = Cimpl.copy(img)
    for x, y, (r, g, b) in img:
        Cimpl.set_color(copy, x, y, Cimpl.create_color(0, g, 0))
    #Cimpl.save_as(copy, SAVE_FILE_AS)
    return copy
def posterize(img: Cimpl.Image) -> Cimpl.Image:
    """
    Author: Zakaria Ismail

    RETURNS an image where
    img has its RGB channels
    set to the midpoint of quadrants:
        0..63, 64..127, 128..191, and 192..255
    depending on where the color channel value is situated between

    img is a Cimpl.Image object passed to the function

    >>> posterize(Cimpl.load_image(Cimpl.choose_file()))
    -> A posterized image is returned
    """
    img = Cimpl.copy(img)
    for x, y, col in img:
        channels = []
        for ch in col:
            channels += [__adjust_component__(ch)]
        Cimpl.set_color(
            img, x, y, Cimpl.create_color(channels[0], channels[1],
                                          channels[1]))
    return img
def create_empty_board(res: int, wBlocks: int, hBlocks: int) -> Tuple[Cimpl.Image, List[list]]:
    '''Returns an empty grid (board) as well as a list of all starting states 
    (dead).
    '''
    width, height = real_coords(res, wBlocks, hBlocks)    
    
    emptyBoard = Cimpl.create_image(width, height, Cimpl.Color(255,255,255))
    
    for pixel in emptyBoard:
        x, y = pixel[0], pixel[1]
        if x % res == 0 or y % res == 0:
            Cimpl.set_color(emptyBoard, x, y, Cimpl.Color(170,170,170))
    
    totalStateList = []
    
    for y in range(hBlocks):
        xStateList = []
        
        for x in range(wBlocks):
            xStateList += [0]
            
        totalStateList += [xStateList]
    
    return emptyBoard, totalStateList
def flip_horizontal(img: Cimpl.Image) -> Cimpl.Image:
    """
    Author: Zakaria Ismail

    RETURNS a Cimpl.Image
    that was flipped, after
    being PASSED img

    img is a Cimpl.Image object

    >>> flip_horizontal(Cimpl.load_image(Cimpl.choose_file()))
    """
    hgt = Cimpl.get_height(img)
    wth = Cimpl.get_width(img)
    mid_x = wth // 2
    copy = Cimpl.copy(img)
    for y in range(hgt):
        for x in range(mid_x):
            # r1, g1, b1 = Cimpl.get_color(img, x, y)
            # r2, g2, b2 = Cimpl.get_color(img, x, hgt-y)
            Cimpl.set_color(copy, x, y, Cimpl.get_color(img, wth - x - 1, y))
            Cimpl.set_color(copy, wth - x - 1, y, Cimpl.get_color(img, x, y))
    return copy
def combine(r_img: Cimpl.Image, g_img: Cimpl.Image,
            b_img: Cimpl.Image) -> Cimpl.Image:
    """
    Author: Zakaria Ismail

    RETURNS an ImageObject where
    three Cimpl.Image objects are passed.
    Combines the color channels
    of the three arguments.

    >>> Cimpl.show(combine(Cimpl.load_image('red_image.png'), Cimpl.load_image('green_image.png'), Cimpl.load_image('blue_image.png'))
    -> Returns a Cimpl.Image object
    """
    base = Cimpl.copy(r_img)

    for x, y, (r, g, b) in base:
        g_r, g_g, g_b = Cimpl.get_color(g_img, x, y)
        b_r, b_g, b_b = Cimpl.get_color(b_img, x, y)
        color = Cimpl.create_color(compute_sum(r, g_r, b_r),
                                   compute_sum(g, g_g, b_g),
                                   compute_sum(b, g_b, b_b))
        Cimpl.set_color(base, x, y, color)
    Cimpl.save_as(base, 'combined_image.png')
    return base
def green_channel():
    """
    The Author: Ibrahim Kasim
    green_channel() -> Cimpl.Image:
    Returns green filtered image. It directs user to choose an image that 
    is desired for filtering.
    
    """

    image_file = Cimpl.choose_file()
    original_image = Cimpl.load_image(image_file)
    new_image = Cimpl.copy(original_image)
    for pixel in original_image:
        x, y, (r, g, b) = pixel
        green_color = Cimpl.create_color(0, g, 0)
        Cimpl.set_color(new_image, x, y, green_color)

    return new_image
def sepia(image):
    """
    Author: YANGLONG LIU
    return a grayscaled Image object after being passed a Image object.
    """
    hgt = Cimpl.get_height(image)
    wth = Cimpl.get_width(image)
    for x in range(wth):
        for y in range(hgt):
            red, green, blue = Cimpl.get_color(image, x, y)
            if red < 63:
                blue = blue * 0.9
                red = red * 1.1
            elif 63 <= red and 193 >= red:
                blue = blue * 0.85
                red = red * 1.15
            elif red > 191:
                blue = blue * 0.93
                red = red * 1.08
            new_color = Cimpl.create_color(red, blue, green)
            Cimpl.set_color(image, x, y, new_color)
    return image
                 '4':[EX_LRG_SPACESHIP,'Extra-Large'],
                 '5':[GLIDER_GUN, 'Glider Gun'],
                 },'Spaceships'],
           '4':[{'1':[R_PENTOMINO,'R-Pentomino (P??)'],
                 '2':[DIEHARD,'Diehard (P130)'],
                 '3':[ACORN,'Acorn (P5206)'],
                 }, 'Methuselahs']
           }

# DEFAULT VALUES --------------------------------------------------------------
width, height = DEF_WIDTH, DEF_HEIGHT = 40, 40
maxFrames = DEF_MAX_FRAMES = 50
res = DEF_RES = 16
duration = DEF_DURATION = 150
gifFile = DEF_GIF_FILE = "simulation.gif"
blockColor = DEF_BLOCK_COLOR = Cimpl.Color(0, 0, 0)

# LOADING ---------------------------------------------------------------------
print("Game of Life GIF Creator v1.0; by Julian Nicolai")

gameBoard, updatedStateList = create_empty_board(DEF_RES, DEF_WIDTH, DEF_HEIGHT)

# USER INTERFACE --------------------------------------------------------------
interfaceLoop = True
while interfaceLoop == True:
    print("\nTo go back, enter 'q' into the selection prompt.")
    print("Select one of the following options:")
    print("1: Place Item")
    print("2: Load/Save/Clear Board")
    print("3: Display Game Board")
    print("4: Run Simulation")
Exemple #26
0
def algorithm():
    for image in list(list_of_image):
        path = '%s/%s' % (pathh, image)
        img = Cimpl.load_image(path)

        def lower_brightness(img):

            average_brightness = 0
            min_brightness = 60

            for x, y, col in img:

                r, g, b = col

                brightness = (r+g+b) // 3

                average_brightness += brightness

            average_brightness //= (150*150)

            if average_brightness >= min_brightness:

                for x, y, col in img:

                    r, g, b = col

                    new_col = create_color((r*(3/4)), (g*(3/4)), (b*(3/4)))
                    set_color(img, x, y, new_col)

        def black_and_white(img, threshold):
            """ (Cimpl.Image) -> None

            Convert the specified image to a black-and-white (two-tone) image.

            >>> image = load_image(choose_file())
            >>> black_and_white(image)
            >>> show(image)
            """

            # Brightness levels range from 0 to 255.
            # Change the colour of each pixel to black or white, depending on whether
            # its brightness is in the lower or upper half of this range.

            black = create_color(0, 0, 0)
            white = create_color(255, 255, 255)
            number = 0
            for x, y, col in img:
                red, green, blue = col

                brightness = (red + green + blue) // 3

                if brightness < threshold:
                    set_color(img, x, y, black)
                else:     # brightness is between threshold and 255, inclusive
                    set_color(img, x, y, white)
                    number += 1

        def scan(img):
            """(Cimpl.Image) -> (Int)

            Scans image for white pixel chunks. Returns the size of the largest chunk.
            """
            black_and_white(img, 75)
            lst = []

            for x, y, col in img:
                red, green, blue = col
                if (x > 10) and (x < 140) and (y > 10) and (y < 140):
                    if red == 255:
                        lst.append(sumplusplus(img, x, y))

            largest = 0
            for number in lst:
                if largest <= number:
                    largest = number

            return largest

        green_color = create_color(0, 255, 0)

        def sumplusplus(img, x, y):
            """(Cimpl.Image, Int, Int) -> (Int)

            Recursively determines the size of a chunk in pixels.
            """
            col = get_color(img, x, y)
            r, g, b = col
            if r == 255:
                sump = 0
                set_color(img, x, y, green_color)
                sump += 1
                if x + 1 < 150:
                    sump += sumplusplus(img, x + 1, y)
                    if y + 1 < 150:
                        sump += sumplusplus(img, x + 1, y + 1)
                    if y - 1 > 0:
                        sump += sumplusplus(img, x + 1, y - 1)
                if x - 1 > 0:
                    sump += sumplusplus(img, x - 1, y)
                    if y + 1 < 150:
                        sump += sumplusplus(img, x - 1, y - 1)
                    if y - 1 > 0:
                        sump += sumplusplus(img, x - 1, y + 1)
                if y + 1 < 150:
                    sump += sumplusplus(img, x, y + 1)
                if y - 1 > 0:
                    sump += sumplusplus(img, x, y - 1)

                return sump
            else:
                return 0

        def filter_resolution(img):
            """
            (Cimpl.image)->(Cimple.image)
            Creates a more general picture by using the average color to
            all pixels in 3x3 grid
            >>> image = load_image(choose_file())
            >>> show(filter_resolution(image))
            """

            lastpixel = (0, 0)

            for x, y, col in img:
                (xL, yL) = lastpixel

                sum_color = 0

                if (x >= 10 and x <= 140) and (y >= 10 and x <= 140):
                    #Inside border

                    if (x >= (3 + xL)) or (y >= (3 + yL)):
                        #Is 1 box width away

                        for x2 in range(-1, 2):

                            for y2 in range(-1, 2):

                                color = get_color(img, (x + x2), (y + y2))
                                r, g, b = color

                                sum_color += ((r + g + b)//3) # will add either 0 or 255

                        if(sum_color >= 1275): # 5 or more pixels of out 9 are white, changes all 9 to white

                            for x2 in range(-1, 2):

                                for y2 in range(-1, 2):
                                    new_color = create_color(255, 255, 255)
                                    set_color(img, (x + x2), (y + y2), new_color)

                        else: # 5 or more pixels of out 9 are black, changes all 9 to black

                            for x2 in range(-1, 2):

                                for y2 in range(-1, 2):
                                    new_color = create_color(0, 0, 0)
                                    set_color(img, (x + x2), (y + y2), new_color)

                        lastpixel = (x, y)

            return img

        def final_check(img):

            image_value = scan(img)

            if 750 < image_value < 1300:
                return 'Pass'
            else:
                return 'Fail'

        lower_brightness(img)
        ans = final_check(img)
        result.append('%s = %s' % (image, ans))
    str1 = ','.join(result)
    f = open("Results.txt","a")
    f.write(str1)
    f.close()
    toplevel = Toplevel()
    label1 = Label(toplevel, text="All images were processed and saved in Results.txt", height=0, width=50)
    label1.grid(column=0, row=0)
Exemple #27
0
                      "Expected: {}\n"
                      "Outcome: {}".format(x, y, exp_col, out_col))
                errors += 1
        if errors == 0:
            print(
                "SUCCESS: expected and outcome are of the same type and have identical pixels."
            )
        else:
            print("{} ERRORS detected.".format(errors))
    else:
        print("ERROR: Different types detected.\n"
              "Expected: Type {}\n"
              "Outcome: Type {}".format(type(expected), type(outcome)))


expected = Cimpl.load_image(input('Input EXPECTED image filename: '))
print("DISPLAYING EXPECTED IMAGE")
Cimpl.show(expected)

red = Cimpl.load_image(
    input("Input red image filename: "))  # choose_file does not work for me.
print("DISPLAYING RED IMAGE")
Cimpl.show(red)
green = Cimpl.load_image(input("Input green image filename: "))
print("DISPLAYING GREEN IMAGE")
Cimpl.show(green)
blue = Cimpl.load_image(input("Select blue image filename: "))
print("DISPLAYING BLUE IMAGE")
Cimpl.show(blue)

print("COMBINING IMAGES")
    Author: Zakaria Ismail

    RETURNS the sum of three numbers
    PASSED. If sum exceeds 255, then
    the sum is 255.

    >>> compute_sum(5,6,7)
    18
    """
    if r + g + b <= 255:
        return r + g + b
    else:
        return 255


original = Cimpl.load_image(input("Input image filename: "))
print("DISPLAYING IMAGE: ")
Cimpl.show(original)

print("COMPUTING RED FILTERED IMAGE")
red = red_channel(original)
print("DISPLAYING RED FILTERED IMAGE: ")
Cimpl.show(red)

print("COMPUTING GREEN FILTERED IMAGE")
green = green_channel(original)
print("DISPLAYING GREEN FILTERED IMAGE: ")
Cimpl.show(green)

print("COMPUTING BLUE FILTERED IMAGE")
blue = blue_channel(original)
def two_tone(img: Cimpl.Image, col1: str, col2: str) -> Cimpl.Image:
    """
    Author: Himanshu Singh
    Returns a two-toned Cimpl.Image object, based on the colors col1 and col2
    passed. 
    
    img is the original Cimpl.Image object passed
    
    col1 and col2 are the strings representing the image.
    
    >>>two_tone(Cimpl.load_image("image.jpg"), "col1", "col2")
    returns image with a two toned filter

    """

    COLORS = {
        "black": Cimpl.Color(0, 0, 0),  # black
        "white": Cimpl.Color(255, 255, 255),  # white
        "gray": Cimpl.Color(128, 128, 128),  # gray
        "red": Cimpl.Color(255, 0, 0),  # red
        "lime": Cimpl.Color(0, 255, 0),  # lime
        "blue": Cimpl.Color(0, 0, 255),  # blue
        "yellow": Cimpl.Color(255, 255, 0),  # yellow
        "cyan": Cimpl.Color(0, 255, 255),  # cyan
        "magenta": Cimpl.Color(255, 0, 255)  # magenta
    }

    # image = load_image(FILENAME)
    newimage = Cimpl.copy(img)

    for x, y, (r, g, b) in img:
        bright = _brightness(r, g, b)

        if bright <= 127:
            # if calculated brightness at said pixel is below 127 set color to col[1]
            black = Cimpl.create_color(0, 0, 0)
            Cimpl.set_color(newimage, x, y, COLORS[col1])

        else:
            # else set color to col2 at said pixel
            Cimpl.set_color(newimage, x, y, COLORS[col2])

    return newimage
Exemple #30
0
                      "Outcome: {}".format(x, y, exp_col, out_col))
                errors += 1
        if errors == 0:
            print(
                "SUCCESS: expected and outcome are of the same type and have identical pixels."
            )
        else:
            print("{} ERRORS detected.".format(errors))
    else:
        print("ERROR: Different types detected.\n"
              "Expected: Type {}\n"
              "Outcome: Type {}".format(type(expected), type(outcome)))


print("---TESTING FUNCTION green_channel()---")
expected = Cimpl.load_image(input("Select expected image filename: "))
print("DISPLAYING EXPECTED IMAGE: ")
Cimpl.show(expected)

testfile = Cimpl.load_image(
    input(
        "Input filename of image to be passed through FUNCTION green_channel: "
    ))
print("DISPLAYING TEST IMAGE: ")
Cimpl.show(testfile)

print("PASSING TEST IMAGE INTO function green_channel: ")
outcome = green_channel(testfile)
print("DISPLAYING OUTCOME: ")
Cimpl.show(outcome)
print("COMPARING EXPECTED AND OUTCOME")
                      "Outcome: {}".format(x, y, exp_col, out_col))
                errors += 1
        if errors == 0:
            print(
                "SUCCESS: expected and outcome are of the same type and have identical pixels."
            )
        else:
            print("{} ERRORS detected.".format(errors))
    else:
        print("ERROR: Different types detected.\n"
              "Expected: Type {}\n"
              "Outcome: Type {}".format(type(expected), type(outcome)))


print("---TESTING FUNCTION red_channel()---")
expected = Cimpl.load_image(
    input("Select expected (A RED RESULT) image filename: "))
print("DISPLAYING EXPECTED IMAGE: ")
Cimpl.show(expected)

testfile = Cimpl.load_image(
    input(
        "Input filename of image to be passed (AN UNCOLORED IMAGE) through FUNCTION red_channel: "
    ))
print("DISPLAYING TEST IMAGE: ")
Cimpl.show(testfile)

print("PASSING TEST IMAGE INTO function red_channel: ")
outcome = red_channel(testfile)
print("DISPLAYING OUTCOME: ")
Cimpl.show(outcome)
Exemple #32
0
        last_bit.append(pixel_red_binary[-1])

        #Get each component of the pixel in binary in a list
        pixel_green_binary = list(('{0:08b}'.format(green)))
        last_bit.append(pixel_green_binary[-1])

        #Get each component of the pixel in binary in a list
        pixel_blue_binary = list(('{0:08b}'.format(blue)))
        last_bit.append(pixel_blue_binary[-1])

#set variables
last_bit = []
str1 = str()
set_of_strings = []
#load image
image = Cimpl.load_image(Cimpl.choose_file())
#start decryption process
get_bin(image)
cut_off = len(last_bit)//8
last_bit = last_bit[:((cut_off*8)+1)]
num_of_characters = (Cimpl.get_height(image)*Cimpl.get_width(image)*3)//8
for i in range(num_of_characters-1):
    i = i*8
    set_of_strings.append(last_bit[0+i:8+i])
count = 0
#print(len(set_of_strings))
end = '*|*|*|*|*'
for set in set_of_strings:
    count += 1
    char = ''.join(str(e) for e in set)
    char = text_from_bits(char)
Exemple #33
0
        #Convert the altered pixel green component in binary from a list to a string
        new_green = ''.join(str(e) for e in pixel_green_binary)
        new_green = int(new_green, 2)

        #Convert the altered pixel blue component in binary from a list to a string
        new_blue = ''.join(str(e) for e in pixel_blue_binary)
        new_blue = int(new_blue, 2)

        #Create and Set color
        new_color = Cimpl.create_color(new_red, new_green, new_blue)
        Cimpl.set_color(img, x, y, new_color)


#load image
image = Cimpl.load_image(Cimpl.choose_file())


#Convert user input string to binary
string = input("Input the text you would like to hide:")
string = "*****" + string + '|||||'
string_in_bin = text_to_bits(string)
string_in_bin = list(string_in_bin)


#calculate how many bits we can alter
image_width = Cimpl.get_width(image)
image_height = Cimpl.get_height(image)
open_bits = image_width*image_height*3

        #Get each component of the pixel in binary in a list
        pixel_blue_binary = list(('{0:08b}'.format(blue)))
        last_bit.append(pixel_blue_binary[-1])


if __name__ == "__main__":
    main_loop = True

    while main_loop:
        print("To Encrypt text into a image enter 'E'.\nTo Decrypt a image enter 'D'.\nIf you would like to Quit enter 'Q'")
        command = input('Select:')

        if command == 'E' or command == 'e':
            print('You have selected to encrypt a image. A file browser has opened please select the image you would like to encrypt. The file browser may be underneath another window.')
            #load image
            image = Cimpl.load_image(Cimpl.choose_file())

            #Convert user input string to binary
            string = input("Input the text you would like to hide:")
            string = '*****' + string + '|||||'
            string_in_bin = text_to_bits(string)
            string_in_bin = list(string_in_bin)

            #calculate how many bits we can alter
            image_width = Cimpl.get_width(image)
            image_height = Cimpl.get_height(image)
            open_bits = image_width*image_height*3

            #repeat string to cover entire image
            string_bin_length = len(string_in_bin)
            possible_repeat = open_bits//string_bin_length