how can I make 2d auto-correlation and 2d cross-correlation for images dataset

4 views (last 30 days)
I want to classify an image based on 1. make 2D auto-correlation for a dataset 2. then make 2D cross-correlation for the same dataset with an image to measure the similrity. 3. Ater that find the MSE between 2D auto-correlation and 2D cross-correlation. 4. classify the image to the class get the minimum Mean square error (MSE) if true % code
%the normalized 2-D cross-correlation
trainedIamge = gpuArray(Final) %Final is binary image
testImage = gpuArray(Final1) %Final1 is binary image
c1 = normxcorr2(trainedIamge,testImage);
%figure, surf(c), shading flat
[ypeak, xpeak] = find(c==max(c(:)))
c2 = normxcorr2(trainedIamge,trainedIamge); % I don't know how I make it Auto correlation
%figure, surf(c), shading flat
end
I used the following code for finding MSE between 2D auto-correlation and 2D cross-correlation but it gave me an error.
if true
% code
err = immse(mat2gray(c1),mat2gray(c2))
end
I converted c1 and c2 onto grayscale images because it gave an error about the datatypes. the above code is for one image. Do I have to make a loop for a dataset or there is a specific method?
thanks

Answers (1)

Image Analyst
Image Analyst on 23 Mar 2018
Yes you need to have a loop. See the FAQ for code examples: http://matlab.wikia.com/wiki/FAQ#How_can_I_process_a_sequence_of_files.3F
  2 Comments
Suheer Ali
Suheer Ali on 25 Mar 2018
thanks for your answer. my question here is about finding the mse error between autocorrelation and cross correlation. how can I do it? and using using
if true
c2 = normxcorr2(trainedIamge,trainedIamge);
end
is it true for auto-correlation?
Image Analyst
Image Analyst on 26 Mar 2018
That is the autocorrelation. But it's normalized. You can use xcorr2(). Then use immse() to get the mean square error.

Sign in to comment.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!