Home > Blockchain >  Is it possible to reverse an image if we did a dot product between noise and the image?
Is it possible to reverse an image if we did a dot product between noise and the image?

Time:04-26

I did dot product of the image with a noise.

import numpy as np
np.random.seed(100)
x = grayscale.shape[0]
y = grayscale.shape[1]
noise = np.random.rand(x,y)
noise_dot_img = grayscale.dot(noise)
plt.imshow(noise_dot_img, cmap = "gray")

Image with noise

Original image

CodePudding user response:

Apologies for the horrible formatting but stack overflow doesn't support latex.

The dot product between two vectors (if they are NxM matrices you can just drop the transpose since dot product between matrices is defined as matrix multiplication in numpy) A and B is A dot B = AB^T

If A is your original image and B is the noise matrix you can reverse it by multiplying your final image matrix with the inverse of B^T (if it has one), since matrix multiplication is associative.

So to get your original matrix A = A dot B * (B^T)^-1

EDIT: for clarity here is some example code:

import numpy as np

A = np.random.randint(10, size=(3, 3))
B = np.random.randint(10, size=(3, 3))

image_with_noise = A.dot(B)
noise_inverse = np.linalg.inv(B)
recreated_image = np.matmul(image_with_noise, noise_inverse)

CodePudding user response:

I think you should share some more information about what exactly you are trying to achieve here.

In any case, you actually can get your image back in this specific example, by inverting the noise matrix and multiplying with it the noisy image:

inv = np.linalg.inv(noise)
restored_img = noise_dot_img@inv

However, there are a lot of things that need explaining. Overall, this is not really how we tackle this problem, since we almost never know the "noise" matrix. This is why signal processing exists. Also, in this example you are dealing with a square image. Otherwise, we would not be able to find the inverse (and we would have to use the pseudo-inverse). That said, one should always be careful before deciding to invert matrices.

  • Related