|
|
|
@ -1,7 +1,7 @@
|
|
|
|
|
import numpy as np
|
|
|
|
|
|
|
|
|
|
class MaskedImage:
|
|
|
|
|
DSCALE = 65535
|
|
|
|
|
DSCALE = 10_000 # valeur arbitraire qui est le nombre max de la function de distance
|
|
|
|
|
base = [1.0, 0.99, 0.96, 0.83, 0.38, 0.11, 0.02, 0.005, 0.0006, 0.0001, 0]
|
|
|
|
|
similarity = np.interp(np.linspace(0, 1, DSCALE + 1), np.linspace(0, 1, len(base)), base)
|
|
|
|
|
|
|
|
|
@ -18,11 +18,11 @@ class MaskedImage:
|
|
|
|
|
|
|
|
|
|
def containsMask(self,x,y,patchSize):
|
|
|
|
|
for dy in range(-patchSize,patchSize):
|
|
|
|
|
if (y+dy < 0 or self.height <= y+dy):
|
|
|
|
|
continue
|
|
|
|
|
for dx in range(-patchSize,patchSize):
|
|
|
|
|
if (x+dx < 0 or self.width <= x+dx):
|
|
|
|
|
continue
|
|
|
|
|
if (y+dy < 0 or self.height <= y+dy):
|
|
|
|
|
continue
|
|
|
|
|
if self.mask[y+dy,x+dx]:
|
|
|
|
|
return True
|
|
|
|
|
return False
|
|
|
|
@ -60,7 +60,7 @@ class MaskedImage:
|
|
|
|
|
m += 1
|
|
|
|
|
|
|
|
|
|
if ksum > 0:
|
|
|
|
|
newimage[y // 2, x // 2] = [r // ksum, g // ksum, b // ksum]
|
|
|
|
|
newimage[y // 2, x // 2] = (r // ksum, g // ksum, b // ksum)
|
|
|
|
|
newmask[y // 2, x // 2] = False
|
|
|
|
|
else:
|
|
|
|
|
newmask[y // 2, x // 2] = True
|
|
|
|
@ -68,15 +68,10 @@ class MaskedImage:
|
|
|
|
|
return MaskedImage(image=newimage, mask=newmask)
|
|
|
|
|
|
|
|
|
|
def upscale(self, newH, newW):
|
|
|
|
|
y_indices = np.floor(np.linspace(0, self.height-1, newH)).astype(int)
|
|
|
|
|
x_indices = np.floor(np.linspace(0, self.width-1, newW)).astype(int)
|
|
|
|
|
y_coords, x_coords = np.meshgrid(y_indices, x_indices, indexing='ij')
|
|
|
|
|
newImage = MaskedImage(width=newW, height=newH)
|
|
|
|
|
for y in range(newH):
|
|
|
|
|
for x in range(newW):
|
|
|
|
|
xs = int(x*self.width/newW)
|
|
|
|
|
ys = int(y*self.height/newH)
|
|
|
|
|
|
|
|
|
|
if not self.mask[ys,xs]:
|
|
|
|
|
newImage.image[y,x] = self.image[ys,xs]
|
|
|
|
|
newImage.mask[y,x] = False
|
|
|
|
|
else:
|
|
|
|
|
newImage.mask[y,x] = True
|
|
|
|
|
newImage.image = self.image[y_coords, x_coords]
|
|
|
|
|
newImage.mask = self.mask[y_coords, x_coords]
|
|
|
|
|
return newImage
|
|
|
|
|