MCPcopy Create free account
hub / github.com/Atrovast/THGS / gradient_map

Function gradient_map

utils/image_utils.py:28–37  ·  view source on GitHub ↗
(image)

Source from the content-addressed store, hash-verified

26 return 20 * torch.log10(1.0 / torch.sqrt(mse))
27
28def gradient_map(image):
29 sobel_x = torch.tensor([[-1, 0, 1], [-2, 0, 2], [-1, 0, 1]]).float().unsqueeze(0).unsqueeze(0).cuda()/4
30 sobel_y = torch.tensor([[-1, -2, -1], [0, 0, 0], [1, 2, 1]]).float().unsqueeze(0).unsqueeze(0).cuda()/4
31
32 grad_x = torch.cat([F.conv2d(image[i].unsqueeze(0), sobel_x, padding=1) for i in range(image.shape[0])])
33 grad_y = torch.cat([F.conv2d(image[i].unsqueeze(0), sobel_y, padding=1) for i in range(image.shape[0])])
34 magnitude = torch.sqrt(grad_x ** 2 + grad_y ** 2)
35 magnitude = magnitude.norm(dim=0, keepdim=True)
36
37 return magnitude
38
39def colormap(map, cmap="turbo"):
40 colors = torch.tensor(plt.cm.get_cmap(cmap).colors).to(map.device)

Callers 1

render_net_imageFunction · 0.85

Calls 1

cudaMethod · 0.45

Tested by

no test coverage detected