summaryrefslogtreecommitdiff
path: root/macros/crossCorrelator.sci
diff options
context:
space:
mode:
authorshamikam2017-01-16 02:56:17 +0530
committershamikam2017-01-16 02:56:17 +0530
commita6df67e8bcd5159cde27556f4f6a315f8dc2215f (patch)
treee806e966b06a53388fb300d89534354b222c2cad /macros/crossCorrelator.sci
downloadFOSSEE_Image_Processing_Toolbox-master.tar.gz
FOSSEE_Image_Processing_Toolbox-master.tar.bz2
FOSSEE_Image_Processing_Toolbox-master.zip
First CommitHEADmaster
Diffstat (limited to 'macros/crossCorrelator.sci')
-rw-r--r--macros/crossCorrelator.sci48
1 files changed, 48 insertions, 0 deletions
diff --git a/macros/crossCorrelator.sci b/macros/crossCorrelator.sci
new file mode 100644
index 0000000..c676044
--- /dev/null
+++ b/macros/crossCorrelator.sci
@@ -0,0 +1,48 @@
+function relation = crossCorrelator(inputMatrix1,inputMatrix2)
+//Calculate 2-D cross correlation of two input matrices
+//
+//Calling Sequence
+// relation=crossCorrelator(inputMatrix1, inputMatrix2);
+//
+//Parameters
+// inputMatrix1: matrix of any size
+// inputMatrix2: matrix of any size
+//
+//Description
+//This function computes 2-D cross correlation of two input matrices
+//
+// Examples
+// A=[1 4;2 3];
+// B=[2 3 5;6 1 4];
+// relation=crossCorrelator(A,B);
+
+[r,c,channels1] = size(inputMatrix1);
+[m,n,channels2] = size(inputMatrix2);
+ if channels1<> 1 then
+ error(msprintf("wrong argument #1: cross correlator function do not support more than two dimensions"))
+ elseif type(inputMatrix1)<> 1
+ error(msprintf("wrong argument #1: cross correlator function do not support input type %s",typeof(A)))
+ end
+ if channels2<> 1 then
+ error(msprintf("wrong argument #2: cross correlator function do not support more than two dimensions"))
+ elseif type(inputMatrix2)<> 1
+ error(msprintf("wrong argument #2: cross correlator function do not support input type %s",typeof(B)))
+ end
+conjMatrix=conj(inputMatrix2);
+Rep = zeros(r + m*2-2, c + n*2-2);
+for x = m : m+r-1
+ for y = n : n+c-1
+ Rep(x,y) = inputMatrix1(x-m+1, y-n+1);
+ end
+end
+relation = zeros(r+m-1,n+c-1);
+for x = 1 : r+m-1
+ for y = 1 : n+c-1
+ for i = 1 : m
+ for j = 1 : n
+ relation(x, y) = relation(x, y) + (Rep(x+i-1, y+j-1) * conjMatrix(i, j));
+ end
+ end
+ end
+end
+endfunction