Last active
April 18, 2018 11:01
-
-
Save YoshiRi/7d97a80e1169ba5c41dc37a867dc622c to your computer and use it in GitHub Desktop.
Evaluation function for Image Matching SSD, NCC, ZNCC,
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
%% SSD %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
function e = SSD(img1,img2) | |
if(~(size(img1)==size(img2))) | |
error('IMG size is differnt!'); | |
end | |
[height,width] = size(img1); | |
Total = height * width; | |
%% Substractg image one by one | |
MX = double(img1) - double(img2); | |
%% Adding up squared errors with matrix form | |
VX = reshape(MX,[1 numberofelements(MX)]); | |
VY = VX.'; | |
e = VX * VY ; | |
end | |
% Normalized correlation | |
%% NCC %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
function e = NCC(img1,img2) | |
img1 = double(img1); | |
img2 = double(img2); | |
if(~(size(img1)==size(img2))) | |
error('IMG size is differnt!'); | |
end | |
%% Take correlation | |
V1 = reshape(img1,[1 numel(img1)]) ; | |
V2 = reshape(img2,[1 numel(img2)]) ; | |
% Normalization | |
Nolm =sqrt( V1* V1.' + V2 * V2.' ); | |
e = (V1 * V2.') / Nolm; | |
end | |
%% ZNCC %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
function e = ZNCC(img1,img2) | |
img1 = double(img1); | |
img2 = double(img2); | |
if(~(size(img1)==size(img2))) | |
error('IMG size is differnt!'); | |
end | |
%% Get Correlation | |
% Get mean intensity | |
avg1 = mean2(img1); | |
avg2 = mean2(img2); | |
% Calculate correlation | |
V1 = reshape(img1,[1 numel(img1)]) - avg1; | |
V2 = reshape(img2,[1 numel(img2)]) - avg2; | |
Nolm =sqrt( V1* V1.' + V2 * V2.' ); | |
e = (V1 * V2.') / Nolm; | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment