function [R] = Correlate2D(fiRe, fiIm, foRe, foIm, w, intFlg, polFlg, n) fiIm = ''; % The math didn't work well with complex values. % Generate an n x n matrix representing R(0) through R(n-1) % .. (shift correlations) % .. for the rows and columns of the matrix represented in fileIn. % % Due to D.Salomon, "Correlation in Statistics and in Data Compression" (2000) % Adapted 12 Jan 2009 D.Bozarth - SSU Engineering Science % 13 Jan 2009 - Add flag for polar coordinates, enable components % imFlg = 1; if isequal(fiIm, '') || isequal(foIm, '') imFlg = 0; polFlg = 0; fiIm = ''; foIm = ''; end img = GetSignalFromComponents( fiRe, fiIm, w, intFlg, polFlg ); h = size( img, 1 ); for x = 0:(n-1) for y = 0:(n-1) iimg = img( 1:h-x, 1:w-y ); % delete last x,y rows cols simg = img( 1+x:h, 1+y:w ); % delete first x,y rows cols Ibar = sum(sum( iimg, 1 ), 2) / ((h - x) * (w - y)); Sbar = sum(sum( simg, 1 ), 2) / ((h - x) * (w - y)); timg = (iimg - Ibar) .* (iimg - Ibar); SQI = sqrt(sum( sum(timg, 1), 2 )); timg = (simg - Sbar) .* (simg - Sbar); SQS = sqrt(sum( sum(timg, 1), 2 )); timg = (iimg - Ibar) .* (simg - Sbar); R( x+1, y+1 ) = sum( sum(timg, 1), 2 ) / (SQI * SQS); end end %FileSignalAsComponents( foRe, foIm, R, n, n, intFlg, polFlg ); FileSignalAsComponents( foRe, foIm, R, intFlg, polFlg ); % % end script