forked from LabForComputationalVision/matlabPyrTools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcorrDn.m
executable file
·63 lines (51 loc) · 2.22 KB
/
corrDn.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
% RES = corrDn(IM, FILT, EDGES, STEP, START, STOP)
%
% Compute correlation of matrices IM with FILT, followed by
% downsampling. These arguments should be 1D or 2D matrices, and IM
% must be larger (in both dimensions) than FILT. The origin of filt
% is assumed to be floor(size(filt)/2)+1.
%
% EDGES is a string determining boundary handling:
% 'circular' - Circular convolution
% 'reflect1' - Reflect about the edge pixels
% 'reflect2' - Reflect, doubling the edge pixels
% 'repeat' - Repeat the edge pixels
% 'zero' - Assume values of zero outside image boundary
% 'extend' - Reflect and invert (continuous values and derivs)
% 'dont-compute' - Zero output when filter overhangs input boundaries
%
% Downsampling factors are determined by STEP (optional, default=[1 1]),
% which should be a 2-vector [y,x].
%
% The window over which the convolution occurs is specfied by START
% (optional, default=[1,1], and STOP (optional, default=size(IM)).
%
% NOTE: this operation corresponds to multiplication of a signal
% vector by a matrix whose rows contain copies of the FILT shifted by
% multiples of STEP. See upConv.m for the operation corresponding to
% the transpose of this matrix.
% Eero Simoncelli, 6/96, revised 2/97.
function res = corrDn(im, filt, edges, step, start, stop)
%% NOTE: THIS CODE IS NOT ACTUALLY USED! (MEX FILE IS CALLED INSTEAD)
fprintf(1,'WARNING: You should compile the MEX version of "corrDn.c",\n found in the MEX subdirectory of matlabPyrTools, and put it in your matlab path. It is MUCH faster, and provides more boundary-handling options.\n');
%------------------------------------------------------------
%% OPTIONAL ARGS:
if (exist('edges') == 1)
if (strcmp(edges,'reflect1') ~= 1)
warning('Using REFLECT1 edge-handling (use MEX code for other options).');
end
end
if (exist('step') ~= 1)
step = [1,1];
end
if (exist('start') ~= 1)
start = [1,1];
end
if (exist('stop') ~= 1)
stop = size(im);
end
%------------------------------------------------------------
% Reverse order of taps in filt, to do correlation instead of convolution
filt = filt(size(filt,1):-1:1,size(filt,2):-1:1);
tmp = rconv2(im,filt);
res = tmp(start(1):step(1):stop(1),start(2):step(2):stop(2));