Not Enough input argument for image

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

KALYAN ACHARJYA
KALYAN ACHARJYA 2022년 10월 25일
I dit not find any coding error, can you please specify it?

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

답변 (1개)

Cris LaPierre
Cris LaPierre 2022년 10월 25일
편집: Cris LaPierre 2022년 10월 25일

0 개 추천

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);

카테고리

도움말 센터File Exchange에서 Image Processing Toolbox에 대해 자세히 알아보기

질문:

2022년 10월 25일

댓글:

2022년 10월 25일

Community Treasure Hunt

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

Start Hunting!

Translated by