Code h2>
8 directions 4 directions Veuillez choisir votre favori
def LaplacianLayer(self, img):
# 4 direction Laplacian
laplacian_filter = torch.cuda.FloatTensor(
[[0, 1, 0], [1, -4, 1], [0, 1, 0]]).view(1, 1, 3, 3)
# 8 direction Laplacian
# laplacian_filter = torch.cuda.FloatTensor(
# [[1, 1, 1], [1, -8, 1], [1, 1, 1]]).view(1, 1, 3, 3)
gray = self.getGrayImage(img)
img_lap = torch.nn.functional.conv2d(input=gray,
weight=Variable(laplacian_filter),
stride=1,
padding=0)
img_lap = torch.abs(img_lap)
return img_lap
def getGrayImage(self,rgbImg):
gray = 0.114*rgbImg[:,0,:,:] + 0.587*rgbImg[:,1,:,:] + 0.299*rgbImg[:,2,:,:]
gray = torch.unsqueeze(gray,1)
return gray