def test_invert(self):
        inverter = filters.invert(9)

        expected = np.array([9, 8, 7, 6, 5, 4, 3, 2, 1, 0])
        exist = inverter(list(range(10)))

        self.assertTrue(np.array_equal(exist, expected))
def checkButtons():
    global IMAGE_CURRENT, PREV_FILENAME, USER_INPUT, FILENAME, IMAGE_ORIGINAL
    x = pygame.mouse.get_pos()[0]
    y = pygame.mouse.get_pos()[1]
    for button in buttons:
        if pointInRect(x, y, button.x, button.y, button.w, button.h):
            if button.title == "Black & White":
                blackAndWhitePhoto = filters.blackAndWhite(
                    PREV_FILENAME)  # call function in filters.py file
                IMAGE_CURRENT = pygame.image.load(blackAndWhitePhoto)
                IMAGE_CURRENT = scaledImage(IMAGE_CURRENT)
                PREV_FILENAME = blackAndWhitePhoto
            elif button.title == "Blur":
                bluredPhoto = filters.blur(PREV_FILENAME)
                IMAGE_CURRENT = pygame.image.load(bluredPhoto)
                IMAGE_CURRENT = scaledImage(IMAGE_CURRENT)
                filters.blurRadius += 1
                PREV_FILENAME = bluredPhoto
            elif button.title == "Invert":
                invertedPhoto = filters.invert(PREV_FILENAME)
                IMAGE_CURRENT = pygame.image.load(invertedPhoto)
                IMAGE_CURRENT = scaledImage(IMAGE_CURRENT)
                PREV_FILENAME = invertedPhoto
            elif button.title == "Edge Detection":
                demonicPhoto = filters.findEdge(PREV_FILENAME)
                IMAGE_CURRENT = pygame.image.load(demonicPhoto)
                IMAGE_CURRENT = scaledImage(IMAGE_CURRENT)
                PREV_FILENAME = demonicPhoto
            elif button.title == "Sharpen":
                sharpPhoto = filters.sharpen(PREV_FILENAME)
                IMAGE_CURRENT = pygame.image.load(sharpPhoto)
                IMAGE_CURRENT = scaledImage(IMAGE_CURRENT)
                filters.sharpness += 2.5
                PREV_FILENAME = sharpPhoto
            elif button.title == "Sepia":
                sepiaPhoto = filters.diySepia(PREV_FILENAME)
                IMAGE_CURRENT = pygame.image.load(sepiaPhoto)
                IMAGE_CURRENT = scaledImage(IMAGE_CURRENT)
                PREV_FILENAME = sepiaPhoto
            elif button.title == "Reset":
                for slider in sliders:
                    slider.Ex = slider.middleX
                IMAGE_CURRENT = IMAGE_ORIGINAL
                PREV_FILENAME = FILENAME
            elif button.title == "New Image":
                choose_image()
                PREV_FILENAME = FILENAME
                IMAGE_ORIGINAL = pygame.image.load(FILENAME)
                IMAGE_ORIGINAL = scaledImage(IMAGE_ORIGINAL)
                IMAGE_CURRENT = IMAGE_ORIGINAL
            elif button.title == "Save Final":
                filters.saveFinal(PREV_FILENAME)
예제 #3
0
def main():
    # ask user for filename to modify
    filename = input("Enter the name of the image file:  ")
    #print(filename)

    #load the image
    image = filters.load_img(filename)

    #obama
    new_image = filters.invert(image)

    #save new image
    filters.save_img(new_image, "filtered.jpg")
예제 #4
0
def ask(picture):
    print("What filter do you want to apply?")
    while True:
        res = input(
            "\nObamicon[o], Gray[g], Inverted[i], Yellow-Tinted[y], Quit[q] ")

        try:
            res = res.lower()
        except:
            print("Wrong Input. Please try again.\n")
            continue

        if res == 'o':
            print("...generating obamicon...")
            obamicon_pic = filters.obamicon(picture)
            curr_pic = obamicon_pic
            filters.show_img(obamicon_pic)

        elif res == 'g':
            print("...generating grayscale...")
            gray_pic = filters.gray(picture)
            curr_pic = gray_pic
            filters.show_img(gray_pic)

        elif res == 'i':
            print("...generating inverted...")
            inverted = filters.invert(picture)
            curr_pic = inverted
            filters.show_img(inverted)

        elif res == 'y':
            print("...generating yellow-tinted...")
            tinted_pic = filters.tint(picture)
            curr_pic = tinted_pic
            filters.show_img(tinted_pic)

        elif res == 'q':
            print("...quitting...\n")
            break

        else:
            print("Invalid response. Please Try Again.\n")
            continue

        print("success!\n")

        if (shouldSave()):
            newName(curr_pic)
            print("All Saved!\n")
예제 #5
0
def main():

    filename = input("Enter the name of the image file to edit: ")

    img = filters.load_img(filename)

    newimg = filters.obamicon(img)
    newimg = filters.grayscale(newimg)

    blue = (30, 85, 115)
    anotherimg = filters.emphasize(img, blue, 50)

    blueimg = filters.add_color(img, blue)

    lastimg = filters.invert(blueimg)

    filters.save_img(newimg, "recolored1.jpg")
예제 #6
0
def main():
    file_name = input("enter the name of the image file you want to edit: ")

    img = filters.load_img(file_name)

    new_img = filters.obamicon(img)

    new_img_2 = filters.greyscale(new_img)

    blue = (30, 85, 115)

    new_img_3 = filters.emphasize(img, blue, 50)

    new_img_4 = filters.add_color(img, blue)

    new_img_5 = filters.invert(new_img_4)

    #save filtered image as a new image
    filters.save_img(new_img_2, "new_im.jpg")
예제 #7
0
def main():
    file = input("What file are you trying to edit: ")

    img = filters.load_img(file)

    new_img = filters.obamicon(img)
    gray_img = filters.grayscale(new_img)

    blue = (30, 85, 115)
    emph_img = filters.emphasize(img, blue, 50)

    blue_img = filters.add_color(img, blue)

    invert_img = filters.invert(blue_img)

    filters.save_img(gray_img, "recolored.jpg")
    filters.save_img(emph_img, "emph.jpg")
    filters.save_img(blue_img, "blue.jpg")
    filters.save_img(invert_img, "invert.jpg")
예제 #8
0
def main():
    filename = input("Enter the name of the image file to edit: ")

    img = filters.load_img(filename)

    obamicon_image = filters.obamicon(img)

    filters.save_img(obamicon_image, "recolored.jpg")

    grayscale_image = filters.grayscale(img)

    filters.save_img(grayscale_image, "grayscale.jpg")

    inverted_image = filters.invert(img)

    filters.save_img(inverted_image, "inverted.jpg")

    bluescale_image = filters.blue_recolor(img)

    filters.save_img(bluescale_image, "blue_recolor.jpg")
예제 #9
0
def main():
    # Ask what image the user wants to edit
    filename = input("Enter the name of the image file to edit: ")

    # Load the image from the specified file
    img = filters.load_img(filename)

    # Apply filters!
    newimg = filters.bq.jpg(img)
    newimg = filters.grayscale(newimg)

    blue = (30, 85, 115)
    anotherimg = filters.emphasize(img, blue, 50)

    blueimg = filters.add_color(img, blue)

    lastimg = filters.invert(blueimg)

    # Save the final images
    filters.save_img(newimg, "recolored1.jpg")
    filters.save_img(anotherimg, "recolored2.jpg")
    filters.save_img(blueimg, "recolored3.jpg")
    filters.save_img(lastimg, "recolored4.jpg")
예제 #10
0
def get_filters(digit_width,
                digit_max_value,
                digits_len,
                spacing_range,
                image_width,
                evenly=False,
                fltrs=None):
    """
    Getting complete list of filters to process a digit images: resizing, spacing, etc.

    Parameters
    ----------
    digit_width: int
        The standard width of an image stored in MNIST DB.

    digit_max_value: int
        The max (white) value of the image array.

    digits_len: int
        A count of a digit of the generated sequence.

    spacing_range: tuple
        A (minimum, maximum) pair (tuple), representing the min and max spacing between digits.
        A unit should be a pixel.

    evenly: boolean    Default: False
        A mode of generating an image.
        If False - Randomly choosing a spacing in the spacing_range.
        If True - evenly interval for each image and spacing.

    fltrs: list of functions
        A list-like containing functions. Each of them will apply on a digit image and modify it
        before adding to sequence.

    Return
    ------
    A list-like containing filter functions.
    The result has to contain a default filters like as invert, resize and spacing
    and might be extending a custom list of filters.
    Each of them will apply on a digit image and modify it before adding to sequence.
    """
    # image parameters
    digit_count = digits_len
    digit_width = digit_width
    # default filter - invert
    processing_filters = [
        filters.invert(digit_max_value),
        filters.normalize(digit_max_value)
    ]
    if evenly and fltrs:
        processing_filters += fltrs
    # calc image and spacing parameters
    creating_interval = helper.randomly_image_interval if not evenly else helper.evenly_image_interval

    digit_width_seq, spacing_width_seq = creating_interval(
        digit_width=digit_width,
        digit_count=digit_count,
        image_width=image_width,
        spacing=spacing_range)
    # add default post process filters
    processing_filters.append(
        filters.resize_seq(digit_width_seq, default=digit_width))
    processing_filters.append(
        filters.spacing_seq(spacing_width_seq, digit_max_value))

    postprocessing_filters = []
    if not evenly:
        if fltrs:
            postprocessing_filters += fltrs
        postprocessing_filters.append(filters.resize(image_width))

    return processing_filters, postprocessing_filters
예제 #11
0
            shapes.draw_point(draw,points[cl],
                              c_colors[clust.index(c_map[cl])],
                              rsize(50),rthick(6))
    if(LIN):
        for z in range(0,n):
            shapes.draw_line(draw,points[z],points[c_map[z]],
                             c_colors[clust.index(c_map[z])],1) 
    #check for cluster & line toggles__________________________
            
    source.win_diag(draw,n,p.diff(),k,diag)
    p.start()
    #.......................drawing................................

    #check for background toggle
    if(IM): draw,diag = draw,black#toggles viewing mode
    else:   draw,diag = filters.invert(draw),black #between input+overlay && overlay
        
    #Sentel Loop Control Logic============================
    K = cv2.waitKey(60)           #wait period => FPS requested
    if K == KEY_ESC: break        #'esc' key exit
    if K == KEY_W: IM = not IM    #toggle viewing mode
    if K == KEY_R:
        #general data and args calls---------------------------------
        next_points(10,points)               #offset keeps your place
        n = n + 10
        for i in range(0,10): p_colors.append(rred())
        #print(points)
        next_args(k,n,10,points,args) #in the max nxd space
        #print(args)
        out = greedy_sample(args) #pass to program here
        out = out[:-1] #trim one extra blank
예제 #12
0
#new video source object (makes windows, opens videos, camera,ect)
source = sources.Sources()
#new window to view video streams
source.win_start('video_input')
p = perform.CPU()
#captures video files or default webcam = 0
f, M = 1, 10  #n=number of max frames, m= a divsor for output
RT, IM, frame, diag = True, True, 0, white
CL, LIN, PO = False, False, True  # for display of clusters and lines
p_colors, c_colors, clust, c_map = [], [], [], {}
c_colors.append(rwhite())  #clusters draw white/grey?
c_map = {}  #color map
while RT and (frame < f):  #Real-Time Loop=> 'esc' key turns off
    p.stop()
    imc = np.zeros((height, width, 4), np.uint8)
    ims = filters.invert(imc)
    #check for background toggle
    if (IM): draw, diag = imc, black  #toggles viewing mode
    else: draw, diag = ims, white  #between input+overlay && overlay

    #draw points here)))))))))))))))))))))))))))))))))))))))))))))))
    if (PO):
        for z in range(0, n):
            #shapes.draw_point(im,  (x,y)    ,c  ,size), c_map[z] -> cluster,dist
            #print("color map entry z: "+str(c_map[z]))
            #print("c_colors: "+str(c_colors))
            shapes.draw_point(draw, points[z], p_colors[z], 2, 2)

    #draw points here)))))))))))))))))))))))))))))))))))))))))))))))

    #check for cluster & line toggles__________________________