Check for incorrect argument data type or missing argument in call to function 'log'.

function [BrightImage] = Brightness(image , val)
[row , col, depth] = size(image);
BrightImage = zeros(row,col);
BrightImage = im2double(BrightImage);
for r = 1:row
for c = 1:col
BrightImage(r,c) = val * log(image(r,c) + 1);
end
end
BrightImage = im2uint8(BrightImage);
end

1 commentaire

What is your question? What are the inputs you provide to this function? Do you get an error message? Then please post a copy of the complete message.
This part looks strange:
BrightImage = zeros(row,col);
BrightImage = im2double(BrightImage);
BrightImage is a double matrix and with im2double you convert it to a double array, but this does not change anything.
What happens with the 3rd dimension depth?
You ran replace:
BrightImage = zeros(row,col);
BrightImage = im2double(BrightImage);
for r = 1:row
for c = 1:col
BrightImage(r,c) = val * log(image(r,c) + 1);
end
end
by the much simpler:
BrightImage = val * log(image + 1);
but this does not change the error.

Connectez-vous pour commenter.

Réponses (1)

I suspect your image variable (which you probably want to rename, as image already has a meaning in MATLAB) is one of the eight integer data types in MATLAB. The log function is not defined for any of the integer data types.
z = zeros('int8');
which -all log(z)
'log(z)' not found.
It is defined for double and single precision data as you can see from the code below.
d = 0;
which -all log(d)
built-in (/MATLAB/toolbox/matlab/elfun/@double/log) % double method
s = 0;
which -all log(s)
built-in (/MATLAB/toolbox/matlab/elfun/@double/log) % double method
If you were to try to call log on z then MATLAB will throw an error. [The exact error message appears to have changed between release R2021a and the current release.]
y = log(z)
Incorrect number or types of inputs or outputs for function 'log'.
Convert your data to double or single precision if you need to take its logarithm.

Catégories

En savoir plus sur Convert Image Type dans Centre d'aide et File Exchange

Produits

Version

R2021a

Question posée :

le 1 Nov 2022

Commenté :

Jan
le 1 Nov 2022

Community Treasure Hunt

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

Start Hunting!

Translated by