📄 resize_refl.m
字号:
% RESIZE_REFL Resize REFL struct data.
%
% newrefl = resize_refl(oldrefl,redfac)
%
% where redfacn is the reduction factor.
%
% $Id: resize_refl.m,v 1.4 2006/05/17 11:13:23 danji Exp $
function newrefl = resize_refl(oldrefl,redfac);
if redfac > 0
newrefl = refl_struct(resizem(oldrefl.data,1/redfac),oldrefl.start_time,oldrefl.stop_time,oldrefl.type);
else
newrefl = oldrefl;
end
return
%*************************************************************************
%*************************************************************************
%*************************************************************************
%
% Following function RESIZEM (and functions it calls) are called
% by RESIZE_REFL. These functions have been made local to this RESIZE_REFL
% since they have been taken from other toolboxes for the
% sole purpose of making RESIZE_REFL work in the Albedo Toolbox.
%
%*************************************************************************
%*************************************************************************
%*************************************************************************
function [map,newlegend] = resizem(map0,vec,maplegend,method,n)
%RESIZEM Resizes a matrix map
%
% map = RESIZEM(map0,m) resizes the input map by a factor m.
% map = RESIZEM(map0,[r c]) resizes map0 to a r by c matrix.
%
% map = RESIZEM(map0,m,'method') and map = RESIZEM(map0,[r c],'method')
% uses 'method' to define the interpolation scheme. Allowable
% 'method' strings are: 'bilinear' for linear interpolation;
% 'bicubic' for cubic interpolation; and 'nearest' for nearest
% neighbor interpolation. For sparse matrices only nearest
% neighbor interpolation is performed. For full maps, linear
% interpolation is the default option.
%
% [map,maplegend] = RESIZEM(map0,m,maplegend0) and
% [map,maplegend] = RESIZEM(map0,m,maplegend0,'method') resizes
% regular matrix maps and returns the new map and associated
% map legend. Only scalar resize factors are allowed for regular
% matrix maps.
%
% When the map size is being reduced, RESIZEM lowpass filters
% the map before interpolating to avoid aliasing. By default,
% this filter is designed using FIR1, but can be specified using:
%
% RESIZEM(...,'method',h). The default filter is 11-by-11.
% RESIZEM(...,'method',n) uses an n-by-n filter.
% RESIZEM(...,'method',0) turns off the filtering.
%
% Unless a filter h is specified, RESIZEM will not filter when
% 'nearest' is used.
%
% See also IMRESIZE, FIR1, INTERP2, REDUCEM, MAPTRIMS
% Copyright 1996-2002 Systems Planning and Analysis, Inc. and The MathWorks, Inc.
% Written by: E. Byrns, E. Brown
% $Revision: 1.4 $ $Date: 2006/05/17 11:13:23 $
if nargin < 2
error('Incorrect number of arguments')
elseif nargin == 2
maplegend = []; method = []; n = [];
elseif nargin == 3
if isstr(maplegend)
method = maplegend; maplegend = []; n=[];
else
method = []; n = [];
end
elseif nargin == 4
if isstr(maplegend)
n = method; method = maplegend; maplegend = [];
else
n = [];
end
end
% Initialize outputs
map = []; newlegend = [];
% Set the default method
if isempty(method); method = 'nearest'; end
% Test if a new maplegend is to be computed. If so,
% require resize factor to be scalar so that latitude and
% longitude are equally scaled
if ~isempty(maplegend)
if max(size(vec)) > 1
error('Resizing regular matrix maps requires a scalar scale factor')
else
if ~isreal(maplegend)
warning('Imaginary part of complex MAPLEGEND argument ignored')
maplegend = real(maplegend);
end
newlegend = maplegend; newlegend(1) = newlegend(1)*vec;
end
end
% Resize the map
if issparse(map0)
map = reduce(map0,vec); % IMRESIZE won't support
else % sparse matrix computations
if isempty(n)
map = imresize(map0,vec,method);
else
map = imresize(map0,vec,method,n);
end
end
%*************************************************************************
%*************************************************************************
%*************************************************************************
function map = reduce(map0,vec)
%REDUCE Reduces binary sparse matrices
%
% Synopsis
%
% map = reduce(map0,m) % Reduce by a factor of m
% map = reduce(map0,[r c]) % Reduce to row and column dimension
%
% See also RESIZEM
if nargin ~= 2; error('Incorrect number of arguments'); end
% Test input dimensions
if ndims(map0) > 2
error('Input map can not contain pages')
elseif any(nonzeros(map0) ~= 1)
error('Input map must be sparse and binary')
elseif ~isreal(vec)
warning('Imaginary parts of complex argument ignored')
vec = real(vec);
end
% Set the row and column scale factors
if max(size(vec)) == 1
if vec == 1
map = map0; % No reduction required
return
else
rowfact = 1 / vec;
colfact = 1 / vec;
end
elseif isequal(sort(size(vec)),[1 2])
rowfact = size(map0,1) / vec(1); % Different row and column scaling
colfact = size(map0,2) / vec(2);
else
error('Scale factors must be a vector of 2 elements or less')
end
% Ensure that reduction is occuring
if rowfact < 1 | colfact < 1
error('REDUCE only supports matrix reduction')
end
% Determine the original size of the matrix map
[m,n]=size(map0);
% Compute the pre-multiplier for the reduction operation. The
% pre-multiplication will reduce the row dimension
prerows = (1:m)';
precols = fix( (rowfact-1+prerows) / rowfact);
indx = prerows + (precols-1)*m;
pre = sparse(m,m/rowfact);
pre(indx) = ones(size(indx));
% Compute the post-multiplier for the reduction operation. The
% post-multiplication will reduce the column dimension
postrows = (1:n)';
postcols = fix( (colfact-1+postrows) / colfact);
indx = postrows + (postcols-1)*n;
post = sparse(n,n/colfact);
post(indx) = ones(size(indx));
% Reduce the map matrix
map = pre'*map0*post;
map = (map~=0); % Ensure a binary output
%*************************************************************************
%*************************************************************************
%*************************************************************************
%
% Following function IMRESIZE (and functions it calls) are called
% by RESIZEM. These functions have been made local to this RESIZEM
% since they have been taken from other toolboxes for the
% sole purpose of making RESIZEM work in the Mapping Toolbox.
%
%*************************************************************************
%*************************************************************************
%*************************************************************************
function [rout,g,b] = imresize(arg1,arg2,arg3,arg4,arg5,arg6)
%IMRESIZE Resize image.
% B = IMRESIZE(A,M,'method') returns an image matrix that is
% M times larger (or smaller) than the image A. The image B
% is computed by interpolating using the method in the string
% 'method'. Possible methods are 'nearest','bilinear', or
% 'bicubic'. B = IMRESIZE(A,M) uses 'nearest' when A for indexed
% images and 'bilinear' for intensity images.
%
% B = IMRESIZE(A,[MROWS NCOLS],'method') returns a matrix of
% size MROWS-by-NCOLS.
%
% [R1,G1,B1] = IMRESIZE(R,G,B,M,'method') or
% [R1,G1,B1] = IMRESIZE(R,G,B,[MROWS NCOLS],'method') resizes
% the RGB image in the matrices R,G,B. 'bilinear' is the
% default interpolation method.
%
% When the image size is being reduced, IMRESIZE lowpass filters
% the image before interpolating to avoid aliasing. By default,
% this filter is designed using FIR1, but can be specified using
% IMRESIZE(...,'method',H). The default filter is 11-by-11.
% IMRESIZE(...,'method',N) uses an N-by-N filter.
% IMRESIZE(...,'method',0) turns off the filtering.
% Unless a filter H is specified, IMRESIZE will not filter
% when 'nearest' is used.
%
% See also IMZOOM, FIR1, INTERP2.
% Written by: Clay M. Thompson 7-7-92
error(nargchk(2,6,nargin));
% Trap imresize(r,b,g,...) calls.
if nargin==4,
if ~isstr(arg3), % imresize(r,g,b,m)
r = imresize(arg1,arg4,'bil');
g = imresize(arg2,arg4,'bil');
b = imresize(arg3,arg4,'bil');
if nargout==0, imshow(r,g,b), else, rout = r; end
return
end
elseif nargin==5, % imresize(r,g,b,m,'method')
r = imresize(arg1,arg4,arg5);
g = imresize(arg2,arg4,arg5);
b = imresize(arg3,arg4,arg5);
if nargout==0, imshow(r,g,b), else, rout = r; end
return
elseif nargin==6, % imresize(r,g,b,m,'method',h)
r = imresize(arg1,arg4,arg5,arg6);
g = imresize(arg2,arg4,arg5,arg6);
b = imresize(arg3,arg4,arg5,arg6);
if nargout==0, imshow(r,g,b), else, rout = r; end
return
end
% Determine default interpolation method
if nargin<3,
if isgray(arg1), case0 = 'bil'; else case0 = 'nea'; end,
else
method = [lower(arg3),' ']; % Protect against short method
case0 = method(1:3);
end
if prod(size(arg2))==1,
bsize = floor(arg2*size(arg1));
else
bsize = arg2;
end
if any(size(bsize)~=[1 2]),
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -