Professional Documents
Culture Documents
Create PDF in your applications with the Pdfcrowd HTML to PDF API PDFCROWD
% Grandfathered Syntaxes:
%
% [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.
[A,m,method,classIn,h] = parse_inputs(varargin{:});
if threeD,
r = resizeImage(A(:,:,1),m,method,h);
g = resizeImage(A(:,:,2),m,method,h);
b = resizeImage(A(:,:,3),m,method,h);
if nargout==0,
imshow(r,g,b);
return;
elseif nargout==1,
if strcmp(classIn,'uint8');
rout = repmat(uint8(0),[size(r),3]);
rout(:,:,1) = uint8(round(r*255));
rout(:,:,2) = uint8(round(g*255));
rout(:,:,3) = uint8(round(b*255));
Create PDF in your applications with the Pdfcrowd HTML to PDF API PDFCROWD
else
rout = zeros([size(r),3]);
rout(:,:,1) = r;
rout(:,:,2) = g;
rout(:,:,3) = b;
end
else % nargout==3
if strcmp(classIn,'uint8')
rout = uint8(round(r*255));
g = uint8(round(g*255));
b = uint8(round(b*255));
else
rout = r; % g,b are already defined correctly above
end
end
else
r = resizeImage(A,m,method,h);
if nargout==0,
imshow(r);
return;
end
if strcmp(classIn,'uint8')
r = uint8(round(r*255));
end
rout = r;
end
Create PDF in your applications with the Pdfcrowd HTML to PDF API PDFCROWD
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% Function: resizeImage
%
function b = resizeImage(A,m,method,h)
% Inputs:
% A Input Image
% m resizing factor or 1-by-2 size vector
% method 'nearest','bilinear', or 'bicubic'
% h the anti-aliasing filter to use.
% if h is zero, don't filter
% if h is an integer, design and use a filter of size h
% if h is empty, use default filter
if prod(size(m))==1,
bsize = floor(m*size(A));
else
bsize = m;
end
if any(size(bsize)~=[1 2]),
error('M must be either a scalar multiplier or a 1-by-2 size vector.');
end
if isempty(h),
nn = 11; % Default filter size
else
if prod(size(h))==1,
nn = h; h = [];
else
nn = 0;
end
end
[m,n] = size(A);
%
% Interpolate in blocks
%
nu = length(uu); nv = length(vv);
blk = bestblk([nv nu]);
nblks = floor([nv nu]./blk); nrem = [nv nu] - nblks.*blk;
mblocks = nblks(1); nblocks = nblks(2);
mb = blk(1); nb = blk(2);
if nargout==0,
if isgray(b), imshow(b,size(colormap,1)), else imshow(b), end
return
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% Function: parse_inputs
%
switch nargin
case 2, % imresize(A,m)
A = varargin{1};
m = varargin{2};
method = 'nearest';
classIn = class(A);
h = [];
case 3, % imresize(A,m,method)
A = varargin{1};
m = varargin{2};
method = varargin{3};
classIn = class(A);
h = [];
case 4,
if isstr(varargin{3}) % imresize(A,m,method,h)
A = varargin{1};
m = varargin{2};
method = varargin{3};
classIn = class(A);
h = varargin{4};
else % imresize(r,g,b,m)
Create PDF in your applications with the Pdfcrowd HTML to PDF API PDFCROWD
for i=1:3
if isa(varargin{i},'uint8')
error('Please use 3-d RGB array syntax with uint8 image data');
end
end
A = zeros([size(varargin{1}),3]);
A(:,:,1) = varargin{1};
A(:,:,2) = varargin{2};
A(:,:,3) = varargin{3};
m = varargin{4};
method = 'nearest';
classIn = class(A);
h = [];
end
case 5, % imresize(r,g,b,m,'method')
for i=1:3
if isa(varargin{i},'uint8')
error('Please use 3-d RGB array syntax with uint8 image data');
end
end
A = zeros([size(varargin{1}),3]);
A(:,:,1) = varargin{1};
A(:,:,2) = varargin{2};
A(:,:,3) = varargin{3};
m = varargin{4};
method = varargin{5};
classIn = class(A);
h = [];
Create PDF in your applications with the Pdfcrowd HTML to PDF API PDFCROWD
case 6, % imresize(r,g,b,m,'method',h)
for i=1:3
if isa(varargin{i},'uint8')
error('Please use 3-d RGB array syntax with uint8 image data');
end
end
A = zeros([size(varargin{1}),3]);
A(:,:,1) = varargin{1};
A(:,:,2) = varargin{2};
A(:,:,3) = varargin{3};
m = varargin{4};
method = varargin{5};
classIn = class(A);
h = varargin{6};
otherwise,
error('Invalid input arguments.');
end
Create PDF in your applications with the Pdfcrowd HTML to PDF API PDFCROWD