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 detect_edges(original_image: Cimpl.Image, threshold: float) -> Cimpl.Image:
    """ The author: Ibrahim Kasim
    returns a copy of the original image with edge detection filter apllied to it."""
    new_image = Cimpl.copy(original_image)
    total_width = Cimpl.get_width(original_image)
    total_height = Cimpl.get_height(original_image)
    blacked = Cimpl.create_color(0, 0, 0)
    whited = Cimpl.create_color(255, 255, 255)

    for x, y, pixels in original_image:
        if x != total_width and y != total_height - 1:
            pixel_top = Cimpl.get_color(original_image, x, y)
            pixel_bottom = Cimpl.get_color(original_image, x, y + 1)

            average_top = (pixel_top[0] + pixel_top[1] + pixel_top[2]) / 3
            average_bottom = (pixel_bottom[0] + pixel_bottom[1] +
                              pixel_bottom[2]) / 3
            difference = abs(average_bottom - average_top)
            if x == total_width:
                Cimpl.set_color(new_image, x, y, whited)

            elif difference > threshold:
                Cimpl.set_color(new_image, x, y, blacked)
            else:
                Cimpl.set_color(new_image, x, y, whited)
def detect_edges_better(image: Cimpl.Image, threshold: int) -> Cimpl.Image:
    """
    Author:YANGLONG LIU 101141366
    returns a Image with only black and white color depending on the comparsion 
    between contrast and threshold.
    >>>improved_detect_image = detect_edges_better(raw_image, 13)
    >>>show(improved_detect_image) which returned image looks like pencil skectches.
    """
    new_image = Cimpl.copy(image)
    wdt = Cimpl.get_width(new_image)
    hgt = Cimpl.get_height(new_image)
    for x in range(wdt):
        for y in range(hgt):
            if y < hgt - 1:  # make a confirmation for the bottom line is not in this range
                red, green, blue = Cimpl.get_color(image, x, y)
                red1, green1, blue1 = Cimpl.get_color(
                    image, x,
                    y + 1)  # the pixel below the pixel of raw image one
                red2, green2, blue2 = Cimpl.get_color(
                    image, x - 1, y)  # the right one of the pixel

                brightness1 = (red + blue + green) / 3
                brightness2 = (red1 + blue1 + green1) / 3
                brightness3 = (red2 + blue2 + green2) / 3

                contrast1 = abs(brightness2 - brightness1)
                contrast2 = abs(brightness3 - brightness1)

                if contrast1 > threshold or contrast2 > threshold:  # make a comparsion the contrast with threshold
                    red, green, blue = 0, 0, 0  # if the contrast is higher, change color to black.
                    black = Cimpl.create_color(red, green, blue)
                    Cimpl.set_color(new_image, x, y, black)

                else:
                    red, green, blue = 255, 255, 255  # if the contrast is lower, change color to white.
                    white = Cimpl.create_color(red, green, blue)
                    Cimpl.set_color(new_image, x, y, white)

            elif y == hgt - 1:  # the bottom row of the image which the bottom line is in this range
                red, green, blue = 255, 255, 255  # change to white simply.
                white = Cimpl.create_color(red, green, blue)
                Cimpl.set_color(new_image, x, y, white)

    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
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
Exemplo n.º 7
0
        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


#repeat string to cover entire image
string_bin_length = len(string_in_bin)
possible_repeat = open_bits//string_bin_length
extended_string = string_in_bin * possible_repeat
encrypt(image, extended_string)
Cimpl.save_as(image, 'newpic.png')
print("done")
Exemplo n.º 8
0
        #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)
    str1 += char
    if str1 != end and str1.find(end) != -1:
        break

str1.strip('*|*|*|*|*')