Matlab : How to check if two images are similar to each other -
i have coloured images of size 20 20. objective :
based on query, need check recalled image closest match query. example, let 10 images recalled ones. out of 10 recalled images, need find closest match query.
i thinking of using correlation between images. 1 can use correlation coefficient - higher value, more correlation between pixel values. (please correct me wrong).
r = corr2(a,b1)
compute correlation coefficient between , b query, b1 first recalled image image of same size. used above command colored images got result r = nan
. how solve problem colored , gray scale. thank you.
the other image(recalled / retrieved b1)
update : code testing correlation of image databasae called patches.mat (patches database. consists of 59500 20x20 patches, reshaped 400-dimensional column vectors, taken bunch of motorcycle images; using 50 th example query image)
img_query = imagesc(reshape(patches(:,50),20,20)); colormap gray;axis image; r = corr2(img_query,img_query)
answer = nan
that because 1 of images black or includes single color, meaning values of matrix similar. check following examples:
i = imread('pout.tif'); j = i*0; % create black image r = corr2(i,j); r = nan = imread('pout.tif'); j = 255*ones(size(i)); % create white image r = corr2(i,j); r = nan
update
it should work in case, can see in following example, works perfectly:
i1 = abs(255*(rand(10,10)); i2 = abs(255*(rand(10,10)); corr2(i1,i2) ans = 0.0713
even images have shared, working me. find out problem, have either share part of code, or post images are, not saved images (with size 420x560x3).
note: cannot have images including more 1 layer.
your code shows using handle of image instead of image itself.
test this:
i = reshape(patches(:,50),20,20); corr2(i,i)
Comments
Post a Comment