Too many input arguments IMRESIZE

조회 수: 2 (최근 30일)
Kevin Akash Rajasekaran
Kevin Akash Rajasekaran 2021년 5월 18일
댓글: Kevin Akash Rajasekaran 2021년 5월 18일
Hey all! I'm using a custom built code to resize and format an image from a database, such that the final result is in grayscale and at 1920x1080 resolution, with corrected luminance and other properties. etc. The code is given below
function img = getImg(rec,width,height,screen,varargin)
% retrieve the image (rec) from the UT natural scene collection, down
% sampling to the monitor resolution... this should preserve the overall
% dimensions (in deg.) and therefore preserve the spatial frequency
%
% inputs:
%
% rec - a record from the geisler image db
% width - final width of the image (deg.)
% height - final height of the image (deg.)
% screen - a struct containing screen resolution (pixels) and size (deg.)
%
% the screen struct should contain fields as follows:
%
% xpixels - screen width in pixels
% ypixels - screen height in pixels
% width - screen width in deg.
% height - screen height in deg.
%
% optional parameters:
%
% clip - clipping limits as percentiles of the luminance histogram (default: [2,99[)
% pad - padding method, 'none' or 'mean' (default: 'mean')
% parse arguments
p = inputParser();
p.addParameter('clip',[2,99],@(x) validateattributes(x,{'numeric'},{'positive','numel',2,'>=',1,'<=',100})); % as per Geisler and Perry, 2011.
p.addParameter('pad','mean',@(x) ~isempty(x) & ismember(lower(x),{'none','mean','noise'}))
p.parse(varargin{:});
args = p.Results;
%
img = imgdb.geisler.load(rec,'colorMode','lum');
pat = '(?<deg>[.\d]+).*\((?<m>[.\d]+).*'; % field of view in deg. and meters
fov = regexp(rec.meta.Field_Of_View,pat,'names');
fov = str2double(fov.deg);
ippd = size(img,2)/fov; % image pixels/deg.
sppd = screen.xpixels/screen.width; % screen pixels/deg.
img = imresize(img,sppd/ippd,'method','bicubic','antialiasing',true);
% clip...?
%
% the image histograms have long tails on the high end. Here we extend
% the dynamic range by clipping the tails of the distribution. By default
% we clip 2% of pixels at the low end and 1% of pixels at the high end.
%
% See Geisler and Perry, JoV, 2011.
if ~isempty(args.clip)
lim = prctile(img(:),args.clip);
img = min(max(img - lim(1),0.0)./(lim(2)-lim(1)),1.0);
end
% pad...?
[yimg,ximg] = size(img);
% size on screen (pixels)
xscr = floor(width*screen.xpixels/screen.width);
yscr = floor(height*screen.ypixels/screen.height);
if xscr > ximg || yscr > yimg
nx = max(xscr,ximg); ny = max(yscr,yimg);
mn = mean(img(:));
sd = std(img(:)); % rms contrast
switch lower(args.pad)
case 'none'
return
case 'mean'
% pad with mean luminance...
z = mn*ones([ny,nx]);
otherwise
error('Padding with %s is not supported.',args.pad);
end
z(1:yimg,1:ximg) = img;
img = circshift(z,[floor((ny-yimg)/2),floor((nx-ximg)/2)]);
end
% img = real(img.^(1/2.2)); % ghetto gamma - for testing only
end
I call the above function through
img = freeviewing.analysis.getImg(rec,56.9781,32.0502,screen);
where 'rec and 'screen' are both structs containing info about the image. The error supposedly occurs at line 44, giving the following,
Error using imresize
Too many input arguments.
Error in freeviewing.analysis.getImg (line 44)
img = imresize(img,sppd/ippd,'method','bicubic','antialiasing',true);
Can anyone let me know as to what's exactly wrong with the code? Thanks!

답변 (2개)

Image Analyst
Image Analyst 2021년 5월 18일
The method is not specified using Name/value pairs. Get rid of 'method' so that it's
img = imresize(img, sppd/ippd, 'bicubic', 'antialiasing', true);
  댓글 수: 1
Kevin Akash Rajasekaran
Kevin Akash Rajasekaran 2021년 5월 18일
Does not seem to work unfortunately. Still gives me the same error.

댓글을 달려면 로그인하십시오.


Sulaymon Eshkabilov
Sulaymon Eshkabilov 2021년 5월 18일
You'd need to check:
sppd = screen.xpixels/screen.width; % screen pixels/deg.
  댓글 수: 1
Kevin Akash Rajasekaran
Kevin Akash Rajasekaran 2021년 5월 18일
What exactly should I be looking at here. Thanks!

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

태그

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by