You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
patchMatch/customPatchMatch.py

60 lines
1.2 KiB

from matplotlib.widgets import RectangleSelector
import matplotlib.pyplot as plt
import numpy as np
def doPatchMatch(img,x1,y1,x2,y2,patchSize=20):
def getRandomPatch():
rx = np.random.randint(0, width - patchSize)
ry = np.random.randint(0, height - patchSize)
return rx, ry
semiPatch = int(patchSize/2)
height, width, _ = img.shape
xx1 = max(0, x1-semiPatch)
yy1 = max(0, y1-semiPatch)
xx2 = min(width, x2+semiPatch)
yy2 = min(height, y2+semiPatch)
if (xx2-xx1 < patchSize or yy2-yy1 < patchSize):
return img
return img
img = plt.imread('boat.png')
if len(img.shape) == 2:
img = np.stack((img,)*3, axis=-1)
def onselect(eclick, erelease):
x1, y1 = eclick.xdata, eclick.ydata
x2, y2 = erelease.xdata, erelease.ydata
print("drawing")
img_copy = np.copy(img)
#res = doKnn(img_copy,int(x1),int(y1),int(x2),int(y2))
ax.imshow(img_copy)
plt.draw()
print("drawed")
fig, ax = plt.subplots()
ax.imshow(img)
toggle_selector = RectangleSelector(ax, onselect, useblit=True,
button=[1], minspanx=5, minspany=5, spancoords='pixels',
interactive=True)
plt.axis('off')
plt.show()