def performs_seams():
    #---Original Image ---
    img = mpimg.imread(img_path.format(current_image))
    # plt.title('Original Image')
    plt.axis('off')
    plt.imshow(img)  # Display data as an image
    # plt.show()
    sc = SeamCarver(img_path.format(current_image))  # Performs seam_carving.py

    #---Performs Seam Carving
    bigger = sc.resize((sc.image.width - int((rates_num[interations] / 2))),
                       (sc.image.height - int((rates_num[interations] / 2))))
    plt.figure()  # Create a new figure
    # plt.title('Seam Carving')
    plt.axis('off')
    plt.imshow(np.asarray(bigger.arrayObj()))

    #---Performs LBP
    performs_lbp(bigger._array, 'seam_carving')

    #---Performs Seam Insertion
    smaller = sc.resize((sc.image.width + int((rates_num[interations] / 2))),
                        (sc.image.height + int((rates_num[interations] / 2))))
    plt.figure()
    # plt.title('Seam Insertion')
    plt.axis('off')
    plt.imshow(np.asarray(smaller.arrayObj()))

    #---Performs LBP
    performs_lbp(smaller._array, 'seam_insertion')
Пример #2
0
def image_resize_with_mask(filename_input, filename_output, new_height,
                           new_width, filename_mask):
    obj = SeamCarver(filename_input,
                     new_height,
                     new_width,
                     protect_mask=filename_mask)
    obj.save_result(filename_output)
Пример #3
0
def image_resize_without_mask(filename_input, filename_output, new_height,
                              new_width, energy):
    '''
    没有保护mask,直接最简单的resize
    '''
    obj = SeamCarver(filename_input,
                     new_height,
                     new_width,
                     fast_mode=args.fast_mode,
                     energy=energy)
    obj.save_result(filename_output)
Пример #4
0
def image_resize_with_mask(filename_input, filename_output, new_height,
                           new_width, filename_mask, energy):
    '''
    有一个保护的mask,可以选择主要想要保留的部分
    '''
    obj = SeamCarver(filename_input,
                     new_height,
                     new_width,
                     protect_mask=filename_mask,
                     fast_mode=args.fast_mode,
                     energy=energy)
    obj.save_result(filename_output)
Пример #5
0
def object_removal(filename_input, filename_output, filename_mask, demo,
                   energy):
    '''
    有一个需要移除的object的mask
    '''
    obj = SeamCarver(filename_input,
                     0,
                     0,
                     object_mask=filename_mask,
                     demo=demo,
                     fast_mode=args.fast_mode,
                     energy=energy)
    obj.save_result(filename_output)
Пример #6
0
def protect_and_removal(filename_input, filename_output, protect_mask,
                        object_mask, demo, energy):
    '''
    同时清除和保留多个对象
    '''
    obj = SeamCarver(filename_input,
                     0,
                     0,
                     object_mask=object_mask,
                     protect_mask=protect_mask,
                     demo=demo,
                     fast_mode=args.fast_mode,
                     energy=energy)
    obj.save_result(filename_output)
Пример #7
0
def main(argv):
    global word
    global img
    global img2
    global panel
    global sc
    global heightText
    global widthText

    root = tk.Tk()

    img = ImageTk.PhotoImage(Image.open(argv[1]))
    img2 = ImageTk.PhotoImage(Image.open(argv[2]))

    sc = SeamCarver(argv[1])

    panel = tk.Label(root, compound="top", image=img, text="hey")
    panel.pack()
    # heightText = tk.StringVar()
    # widthText = tk.StringVar()
    # heightEntry = tk.Entry(root, textvariable=heightText)
    # # heightText.place(x=50, y=50)
    # # heightText.pack("bottom")
    # widthEntry = tk.Entry(root, textvariable=heightText)
    # # widthText.place(x=100, y=50)
    # # widthText.pack("bottom")
    # submit = tk.Button(root, height=1, width=5, text="Submit", command=lambda: updatePhoto())
    word = True
    # panel.pack(side = "bottom", fill = "both", expand = "yes")

    root.bind("<Return>", callback)
    root.mainloop()
Пример #8
0
    if key == ord('q'):  # quit
        break
    if key == ord('r'):  # reset
        print('reset')
        img_masked[:] = img
        mask[:] = 0
        sketcher.show()
    if key == 32:  # hit spacebar
        new_width = int(
            cv2.getTrackbarPos(trackbarname='width', winname='image'))
        new_height = int(
            cv2.getTrackbarPos(trackbarname='height', winname='image'))

        if np.sum(mask) > 0:  # object removal or protect mask
            if MODE == 'remove':
                carver = SeamCarver(img, 0, 0, object_mask=mask)
            elif MODE == 'protect':
                carver = SeamCarver(img,
                                    new_height,
                                    new_width,
                                    protect_mask=mask)
            else:
                carver = SeamCarver(img, new_height, new_width)
        else:
            carver = SeamCarver(img, new_height, new_width)

        cv2.imshow('resize', cv2.resize(img, dsize=(new_width, new_height)))
        cv2.imshow('input', carver.in_image.astype(np.uint8))
        cv2.imshow('output', carver.out_image.astype(np.uint8))
Пример #9
0
def object_removal(filename_input, filename_output, filename_mask):
    obj = SeamCarver(filename_input, 0, 0, object_mask=filename_mask)
    obj.save_result(filename_output)
Пример #10
0
from seam_carving import SeamCarver

# In[6]:

# !pip install opencv-python

# In[8]:

ls

# In[9]:

folder_in = 'in'
folder_out = 'out'
filename_input = 'test.png'
filename_output = 'test_result.jpg'
filename_mask = 'mask.png'

# In[11]:

input_img = os.path.join(folder_in, filename_input)
input_mask = os.path.join(folder_in, filename_mask)
output_img = os.path.join(folder_out, filename_output)

# In[20]:

obj = SeamCarver('in/test.png', 0, 0, object_mask='in/mask.png')
obj

# In[ ]:
Пример #11
0
def image_content_amplification(filename_input, filename_output):
    obj = SeamCarver(filename_input, 0, 0)
    obj.save_result(filename_output)
Пример #12
0
#!/usr/bin/env python
# coding: utf-8

from seam_carving import SeamCarver

file_path = './test/test.jpg'
out_height, out_width = 110, 110
seam_carver = SeamCarver(file_path=file_path, out_height=out_height, out_width=out_width)

Пример #13
0
print(frames_count)
print(fps)
print(height)
print(width)

new_height = 256
new_width = 480

# video = np.empty((int(frames_count), int(new_height), int(new_width), 3))

i = 0
while cap.isOpened() and i < frames_count:
    print(i)
    ret, X = cap.read()
    if not ret:
        break
    cv2.imwrite('tmp.png', X.astype(np.uint8))
    obj = SeamCarver('tmp.png', new_height, new_width)
    obj.save_result('./images/res_' + "%02d" % i + '.png', )
    # video[i] = obj.get_img()
    i += 1

# video_name = 'video.mp4'
# fourcc = cv2.VideoWriter_fourcc(*'mp4v')
# result = cv2.VideoWriter(video_name, fourcc, fps, (new_width, new_height))
# for i in range(video.shape[0]):
#     result.write(video[i,:,:,:])

# cv2.destroyAllWindows()
# result.release()
Пример #14
0
def scale_down_example():
    sc = SeamCarver(IMAGE_FILE)
    image = sc.resize(200, 300)
    image.save("static/smaller.jpg")
    sc.debug_animation.export_gif("static/smaller.gif")
Пример #15
0
def scale_up_example():
    sc = SeamCarver(IMAGE_FILE)
    image = sc.resize(500, 500)
    image.save("static/bigger.jpg")
    sc.debug_animation.export_gif("static/bigger.gif")
def scale_down_example():
    sc = SeamCarver(IMAGE_FILE)
    image = sc.resize(200, 300)
    image.save("static/smaller.jpg")
    sc.debug_animation.export_gif("static/smaller.gif")
def scale_up_example():
    sc = SeamCarver(IMAGE_FILE)
    image = sc.resize(500, 500)
    image.save("static/bigger.jpg")
    sc.debug_animation.export_gif("static/bigger.gif")
def scale_down_example():
    sc = SeamCarver(IMAGE_FILE)
    image = sc.resize(450, 390)
    image.save("static/jack1TestWithFaceRec.jpg")
    sc.debug_animation.export_gif("static/jack1TestWithFaceRec.gif")
Пример #19
0
def image_resize_without_mask(filename_input, filename_output, new_height, new_width):
    obj = SeamCarver(filename_input, new_height, new_width)
    obj.save_result(filename_output)