diff --git a/multiTout.py b/multiTout.py index 4066536..b25ccc0 100644 --- a/multiTout.py +++ b/multiTout.py @@ -10,15 +10,9 @@ maskImg = read("./dog/cow_mask.bmp") img = img.copy() height, width = img.shape[:2] -mask = np.zeros((height,width),dtype=bool) -for y in range(height): - for x in range(width): - mask[y,x] = maskImg[y,x] == 255 -for y in range(height): - for x in range(width): - if mask[y,x]: - img[y,x] = (255,0,0) +mask = maskImg == 255 +img[mask] = (255,0,0) plt.imshow(mask) plt.show() diff --git a/nnf.py b/nnf.py index dad59a6..509c116 100644 --- a/nnf.py +++ b/nnf.py @@ -9,7 +9,6 @@ class Nnf: self.patchSize = patchSize def randomize(self): - self.field = np.zeros((self.input.height, self.input.width, 3), dtype=int) self.field[:,:,2] += MaskedImage.DSCALE self.field[:,:,0] = np.random.randint(0,self.output.width,self.input.width) diff --git a/selection.py b/selection.py new file mode 100644 index 0000000..5191155 --- /dev/null +++ b/selection.py @@ -0,0 +1,48 @@ +from matplotlib.widgets import RectangleSelector +import matplotlib.pyplot as plt +from function import * +import numpy as np + +def onselect(eclick, erelease): + x1, y1 = int(eclick.xdata), int(eclick.ydata) + x2, y2 = int(erelease.xdata), int(erelease.ydata) + img[y1:y2,x1:x2] = (255,0,0) + mask[y1:y2,x1:x2] = True + ax.imshow(img) + plt.draw() + + + +img = read(input("lien relatif de l'image: ")) +img = img.copy() + +rep = input("avez vous le mask de l'image ?(y:n)") +yes = ["y","Y","yes","YES","Yes","o","O","oui","OUI"] +height, width = img.shape[:2] +if (rep in yes): + maskImg = read(input("lien relatife de l'image: ")) + mask = maskImg == 255 + img[mask] = (255,0,0) +else: + fig, ax = plt.subplots() + ax.imshow(img) + mask = np.zeros((height, width), dtype=bool) + toggle_selector = RectangleSelector(ax, onselect, useblit=True, + button=[1], minspanx=5, minspany=5, spancoords='pixels', + interactive=True) + plt.imshow(img) + plt.show() + +plt.ion() +plt.axis("off") + +plt.imshow(mask) +plt.show() +plt.title("mask de l'image") +plt.pause(1) +plt.title("génération de l'image") + +img = doTheInpainting(img,mask,2) +plt.imshow(img) +plt.title("image final") +plt.pause(20)