how to fix in imresize error ??

조회 수: 40(최근 30일)
ElizabethR 2016년 3월 5일
댓글: Image Analyst 2020년 7월 9일
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.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


Image Analyst
Image Analyst 2016년 3월 5일
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
Image Analyst
Image Analyst 2020년 7월 9일
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()!
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.

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


Find more on Convert Image Type 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