Not Enough input argument for image
Mostrar comentarios más antiguos
Hi, I'm very new to MATLAB and I am having some trouble. Lots of people have had the same problem but nobody seems to be able to explain or solve it in plain English. Could somebody please explain what this error is and how to fix it?
I have a simple function
function fftshow1(f, type)
if nargin<2
type = 'log';
end
if (type =='log')
f1 = log (1+ abs(f));
fm = max(f1(:));
imshow(im2uint8(f1/fm))
elseif (type == 'abs')
fa = abs(f);
fm =max (fa);
imshow (fa/fm)
else
error('Type mush be log or abs')
end
It seems to give this error for line 6 but I'm not sure why.
Thanks
1 comentario
KALYAN ACHARJYA
el 25 de Oct. de 2022
I dit not find any coding error, can you please specify it?
Respuestas (1)
Cris LaPierre
el 25 de Oct. de 2022
Editada: Cris LaPierre
el 25 de Oct. de 2022
I could be more certain if you shared the data you used to call your function, but here is the example I tested.
f = imread('peppers.png');
fftshow1(f)
function fftshow1(f, type)
if nargin<2
type = 'log';
end
if (type =='log')
f1 = log (1+ abs(f));
fm = max(f1(:));
imshow(im2uint8(f1/fm))
elseif (type == 'abs')
fa = abs(f);
fm =max (fa);
imshow (fa/fm)
else
error('Type mush be log or abs')
end
end
When I inspect the variables, I discover that f is of type uint8. I then checked what data types log accepts as inputs:
- Data Types: single | double
The error is therefore a result of a data type mismatch. It is common for images to be read in as unit8 or uint16, so there is a function you can use in MATLAB to convert an image to double precision: im2double
To fix the error, you could add the following code to the top of your function
f=im2double(f);
Categorías
Más información sobre Image Processing Toolbox en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!