how to fix in imresize error ??

34 views (last 30 days)
ElizabethR
ElizabethR on 5 Mar 2016
Commented: Image Analyst on 9 Jul 2020
i try to make the function for resizing image, this the code:
>> a=imread('1.png');
>> b=20000;
>> l=sum(sum(a));
>> [m,n]=size(a);
>> m1=fix(m*sqrt(b/l));
>> n1=fix(m*sqrt(b/l));
>> c=imresize(a,[m1 n1]);
but, i get the error :
Error using imresize>scaleOrSize (line 382) Invalid scale or size input argument.
Error in imresize>parsePreMethodArgs (line 354) [scale, output_size] = scaleOrSize(next, next_arg);
Error in imresize>parseInputs (line 248) [params.A, params.map, params.scale, params.output_size] = ...
Error in imresize (line 141) params = parseInputs(varargin{:});
i don't understand what cause of the error and i try to fix the error but i can't fix it. Please Help, Thank you

Answers (1)

Image Analyst
Image Analyst on 5 Mar 2016
It's probably color. To fix, try this:
[m, n, numberOfColorChannels]=size(a)
And use descriptive names like rows, columns, grayImage, etc. not an alphabet soup of names like a,b,c,m,n,i,j, etc. That makes it hard to read code, especially when it's not commented.
  5 Comments
Image Analyst
Image Analyst on 9 Jul 2020
imresize() works fine for RGB images as well as gray scale images, but you have to pass it the number of rows and columns. When she incorrectly did
% Never use size() like this with the array that comes directly out of imread()!
[m,n]=size(a);
the (poorly-named) n was actually (the number of columns) * (the number of color channels), or if "a" were an RGB image, the number of color channels is 3 so n is 3 times as big as it should be.

Sign in to comment.

Categories

Find more on Image Processing Toolbox in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by