forked from mktiede/GetContours
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRescale.m
48 lines (40 loc) · 1.07 KB
/
Rescale.m
1
function img = Rescale(img, scale)%RESCALE - resize image%% usage: img = Rescale(img, scale)%% resizes input single-plane image per specified SCALE factor% output IMG matches class of input (double, uint8, etc.)%% see also RESIZE% mkt 12/15% parse argsif nargin < 2, eval('help Rescale'); return; end;if ndims(img) > 2, error('operates on single-plane images only'); end;if ~isnumeric(scale) || prod(size(scale))>1 || scale<=0, error('scale factor must be numeric scalar value > 0');end;urClass = class(img);img = im2double(img);% filter when scale < 1 to avoid aliasingif scale < 1, [ih, iw] = size(img); mih = floor(ih*scale); miw = floor(iw*scale); h = fir1(10, mih/ih)' * fir1(10, miw/iw); img = filter2(h, img);end;% build interpolation indices[ih, iw] = size(img);mih = floor(ih*scale);miw = floor(iw*scale);[x,y] = meshgrid(1:(iw-1)/(miw-1):iw, 1:(ih-1)/(mih-1):ih);% interpolateimg = interp2(img, x, y, 'cubic');% adjust output classswitch urClass, case 'uint8', img = im2uint8(img); case 'single', img = im2single(img); otherwise,end;