-
Notifications
You must be signed in to change notification settings - Fork 3
/
colfilter.m
26 lines (23 loc) · 900 Bytes
/
colfilter.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
function Y = colfilter(X, h)
% function Y = colfilter(X, h)
% Filter the columns of image X using filter vector h, without decimation.
% If length(h) is odd, each output sample is aligned with each input sample
% and Y is the same size as X.
% If length(h) is even, each output sample is aligned with the mid point
% of each pair of input samples, and size(Y) = size(X) + [1 0];
%
% Cian Shaffrey, Nick Kingsbury
% Cambridge University, August 2000
[r,c] = size(X);
m = length(h);
m2 = fix(m/2);
if any(X(:))
% Symmetrically extend row indices with repeat of end samples.
xe = reflect([(1-m2):(r+m2)], 0.5, r+0.5);
% Perform filtering on the columns of the extended matrix X(xe,:), keeping
% only the 'valid' output samples, so Y is the same size as X if m is odd.
Y = conv2(X(xe,:),h(:),'valid');
else
Y = zeros(r+1-rem(m,2),c); % Short cut if X is all zeros.
end
return;