Not Enough input argument for image

2 vues (au cours des 30 derniers jours)
Newbie_image
Newbie_image le 25 Oct 2022
Commenté : KALYAN ACHARJYA le 25 Oct 2022
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 commentaire
KALYAN ACHARJYA
KALYAN ACHARJYA le 25 Oct 2022
I dit not find any coding error, can you please specify it?

Connectez-vous pour commenter.

Réponses (1)

Cris LaPierre
Cris LaPierre le 25 Oct 2022
Modifié(e) : Cris LaPierre le 25 Oct 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)
Incorrect number or types of inputs or outputs for function 'log'.

Error in solution>fftshow1 (line 9)
f1 = log (1+ abs(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);

Community Treasure Hunt

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

Start Hunting!

Translated by