# Finding Patch Offsets in an Image

I have an image in which I am trying to find the statistics of the offsets for 8 x 8 patches that are taken by sliding them pixel wise.

To be more clear, what I do is I take a patch and try finding the most similar one in the same image by taking the Euclidean distance of the pixel values and keeping the index of the minimum value. I know how to do this, but what struggles me is that, to keep reliable statistics, I must preclude nearby patches, where I intend to take the distance of preclusion as 8 pixels.

Achieving this in MATLAB with decent vectorization causes algorithmic problems. I use im2col to vectorize all the patches with sliding property, and then I take the first patch, repmat it to the same size, and take the euclidean distance between them and get the min of it. I repeat the process for all other patches in a for loop and keep the statistics.

Any suggestions on implementing the preclusion of the nearby patches are appreciated.

• What you are doing is a version of "matched filtering". You don't need to exclude the nearby patches. If you use the standard matched filter convolution, instead of your version, you will get a new image with smooth peaks near the similar images. – Dave Kielpinski Aug 14 '17 at 22:29
• @DaveKielpinski It's a good recommendation, I was looking for such an algorithm, I will dig it deeper. Much appreciated! – Archura Aug 16 '17 at 7:59