MATLAB Answers

0

how to fix in imresize error ??

Asked by ElizabethR on 5 Mar 2016
Latest activity Commented on by Image Analyst
on 15 Jun 2018 at 12:52

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

  0 Comments

Sign in to comment.

1 Answer

Answer by 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.

  3 Comments

thank for your suggestion. I already try but, i still getting error :(

>> a=imread('1.jpg'); ( binary Image )

>> [m, n, numberOfColorChannels]=size(a);

>> WideObject=sum(sum(a));

>> ScaleFactor=20000;

>> m1=fix(m*sqrt(ScaleFactor/WideObject));

>> n1=fix(n*sqrt(ScaleFactor/WideObject));

>> c=imresize(a,[m1 n1]);

I think it is due to the scale factor

No, not due to scale factor because if it were truly a binary image, it works. See:

grayImage=imread('cameraman.tif'); % Gray scale image
% Create a binary image
a = grayImage > 128;  % Now the badly-named "a" is a binary image
[m, n, numberOfColorChannels]=size(a)
WideObject=sum(sum(a));
ScaleFactor=20000;
m1=fix(m*sqrt(ScaleFactor/WideObject));
n1=fix(n*sqrt(ScaleFactor/WideObject));
c=imresize(a,[m1, n1]);

The above code works just fine.

However if it's an RGB image, it gives the exact error message she got. See:

a=imread('peppers.png'); % Read in a color image.
[m, n, numberOfColorChannels]=size(a)
WideObject=sum(sum(a));
ScaleFactor=20000;
m1=fix(m*sqrt(ScaleFactor/WideObject));
n1=fix(n*sqrt(ScaleFactor/WideObject));
c=imresize(a,[m1, n1]);
m =
   384
n =
   512
numberOfColorChannels =
     3
Error using imresize>scaleOrSize (line 405)
Invalid scale or size input argument.
Error in imresize>parsePreMethodArgs (line 377)
[scale, output_size] = scaleOrSize(next, next_arg);
Error in imresize>parseInputs (line 260)
[params.A, params.map, params.scale, params.output_size] = ...
Error in imresize (line 146)
params = parseInputs(args{:});
Error in test (line 7)
c=imresize(a,[m1, n1]); 

So while it may look like (the badly-named) a is a binary image, it's really a color image with just 2 colors: black and white. To fix, do this:

grayImage = rgb2gray(a);
binaryImage = grayImage > 128;

Then use binaryImage instead of a from that point on.

Sign in to comment.


Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today