Why do I get the following error when I am trying to run my code - Undefined function 'imadjust' for input arguments of type 'uint8'.

Why do I get the following error when I am trying to run my code - Undefined function 'imadjust' for input arguments of type 'uint8'.

1 Comment

Guessing: because you do not have the Image Processing toolbox installed and/or no valid license for it.

Sign in to comment.

 Accepted Answer

hello
alternative code if you don't have access to the Image Processing toolbox
I = imread('your image.jpg'); % Example image
% Equivalent to imadjust(I, [0.2 0.8], [0 1], 1)
J = imadjust_alternative(I, [0.2 0.8], [0 1], 1);
% Display side-by-side
figure;
subplot(1,2,1);
imshow(I);
title('Image I');
subplot(1,2,2);
imshow(J);
title('Image J');
function J = imadjust_alternative(I, inRange, outRange, gamma)
% imadjust_alternative - Adjust image intensity values without imadjust
%
% I : Input image (grayscale or RGB, uint8/uint16/double)
% inRange : [low_in high_in] input intensity range (default: [min(I) max(I)])
% outRange : [low_out high_out] output intensity range (default: [0 1])
% gamma : Gamma correction value (default: 1)
% inRange and outRange work like in imadjust.
% Gamma correction is applied after normalization.
% Works for grayscale and RGB images.
% Convert to double for calculations
I = im2double(I);
% Default parameters
if nargin < 2 || isempty(inRange)
inRange = [min(I(:)) max(I(:))];
end
if nargin < 3 || isempty(outRange)
outRange = [0 1];
end
if nargin < 4 || isempty(gamma)
gamma = 1;
end
% Clip input values to inRange
I = max(min(I, inRange(2)), inRange(1));
% Normalize to [0,1]
I_norm = (I - inRange(1)) / (inRange(2) - inRange(1));
% Apply gamma correction
I_gamma = I_norm .^ gamma;
% Scale to output range
J = outRange(1) + I_gamma * (outRange(2) - outRange(1));
% Preserve original class
if isinteger(I)
J = im2uint8(J);
end
end

More Answers (0)

Categories

Find more on Graphics Performance in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!