Pixel difference between two images


I am looking to subtract two images, then flatten them and finally get an array with the pixel-wise differences between the two images.

How can I do this in Pytorch if the images are Tensors? I tried the following code but I get TypeError: bad operand type for abs(): ‘torch.FloatTensor’.

diff_S = np.abs(np.array(test_output.data[0]) - np.array(test_secret.data[0]))

Where test_output and test_secret are the two images.

Thanks in advance!

torch.abs(test_output - test_secrete). PyTorch and NumPy are different packages. Apart from conversion methods (and probably implicit conversions), you shouldn’t expect methods of one package to work on another.

1 Like