I have coloured images of size 20 by 20. The objective is that :

based on a query, I need to check which recalled image is the closest match to the query. For example, let 10 images be the recalled ones. Out of the 10 recalled images, I need to find the closest match to the query. 

I was thinking of using the correlation between the images. One can use the Correlation coefficient - higher the value, more is the correlation between pixel values. (Please correct me where wrong).

`R = corr2(A,B1)` will compute the correlation coefficient between A and B where A is the query, B1 is the first recalled image image of the same size. I used the above command for colored images but I got the result `R = NaN`. How do I solve this problem for colored and gray scale. Thank you.

This is the QUERY IMAGE
[![Query Image](https://i.stack.imgur.com/UqHOQ.jpg)](https://i.stack.imgur.com/UqHOQ.jpg)

The other image(recalled / retrieved B1)
[![Recal](https://i.stack.imgur.com/pm6Jb.jpg)](https://i.stack.imgur.com/pm6Jb.jpg)

UPDATE : Code for testing correlation of an image with itself from a databasae called patches.mat (patches is the database. It consists of 59500 20x20 patches, reshaped into 400-dimensional column vectors,
taken from a bunch of motorcycle images; I am using the 50 th example as the query image)

```
img_query = imagesc(reshape(patches(:,50),20,20));
colormap gray;axis image;

R = corr2(img_query,img_query)

```

Answer = NaN