bitmap_downsize

PURPOSE ^

BITMAP_DONWSIZE scale down an image (anti-aliasing)

SYNOPSIS ^

function A = bitmap_downsize(A, factor)

DESCRIPTION ^

BITMAP_DONWSIZE scale down an image (anti-aliasing)
 A = downsize(A, N) downsizes image array A by a factor N (natural number)

 This function is part of the EXPORT_FIG suite by Oliver Woodford
 http://www.mathworks.com/matlabcentral/fileexchange/23629

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function A = bitmap_downsize(A, factor)
0002 %BITMAP_DONWSIZE scale down an image (anti-aliasing)
0003 % A = downsize(A, N) downsizes image array A by a factor N (natural number)
0004 %
0005 % This function is part of the EXPORT_FIG suite by Oliver Woodford
0006 % http://www.mathworks.com/matlabcentral/fileexchange/23629
0007 
0008 % Copyright (C) Oliver Woodford 2008-2012
0009 % License: BSD, see accompanying license.txt
0010 % $Id: bitmap_downsize.m 5522 2017-06-07 12:03:37Z aadler $
0011 
0012 if factor == 1
0013     % Nothing to do
0014     return
0015 end
0016 try
0017     % Faster, but requires image processing toolbox
0018     A = imresize(A, 1/factor, 'bilinear');
0019 catch
0020     % No image processing toolbox - resize manually
0021     % Lowpass filter - use Gaussian as is separable, so faster
0022     % Compute the 1d Gaussian filter
0023     filt = (-factor-1:factor+1) / (factor * 0.6);
0024     filt = exp(-filt .* filt);
0025     % Normalize the filter
0026     filt = single(filt / sum(filt));
0027     % Filter the image
0028     padding = floor(numel(filt) / 2);
0029     for a = 1:size(A, 3)
0030         A(:,:,a) = conv2(filt, filt', single(A([ones(1, padding) 1:end repmat(end, 1, padding)],[ones(1, padding) 1:end repmat(end, 1, padding)],a)), 'valid');
0031     end
0032     % Subsample
0033     A = A(1+floor(mod(end-1, factor)/2):factor:end,1+floor(mod(end-1, factor)/2):factor:end,:);
0034 end

Generated on Fri 30-Dec-2022 19:44:54 by m2html © 2005