-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathReduce.m
More file actions
executable file
·36 lines (26 loc) · 868 Bytes
/
Reduce.m
File metadata and controls
executable file
·36 lines (26 loc) · 868 Bytes
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
% Reduce image by smoothed subsampling
% Performs horizontal and vertical convolution seperately
% The implied coordinate system originates at
% the center of the image
% Special thanks to Sohaib Khan
% Copyright 2002 University of Central Florida, MIT License
function yout = Reduce(yin)
[m,n,p]=size(yin);
if( mod(m,2)||mod(n,2) )
error('image height and width must be multiples of 2');
end
%convolution mask for smoothed subsampling
mask = [fspecial('gaussian',[1,6],1),0];
cl=class(yin);
yin=double(yin);
yout = zeros(m/2,n/2,p,cl);
for layer=1:p
yinp=yin(:,:,layer);
%horizontal convolution
yh = conv2(yinp,mask,'same');
yh = yh(:,1:2:n); %subsampling
%vertical convolution
yv = conv2(yh,mask','same');
yout(:,:,layer) = cast(yv(1:2:m,:),cl); %resampling
end
end