I got the error in the snippet. The Error message is given below. Kindly go through and rectify if possible. Thanks in Advance.
2 views (last 30 days)
Show older comments
Error using chromadapt
The value of 'illuminant' is invalid. Expected input number 2, illuminant, to be one of these types:
single, double, uint8, uint16
Error in chromadapt>parseInputs (line 248)
parser.parse(varargin{:});
Error in chromadapt (line 154)
inputs = parseInputs(varargin{:});
Error in Untitled (line 15)
K = chromadapt(J,'Method','perez');
clc
close
% Reading the NIR band of a multispectral image
CIR = multibandread('paris.lan',[512, 512, 7],'uint8=>uint8', 128,'bil','ieee-le',{'Band','Direct',[4 3 2]});
% Applying decorrelation stretch to enhance image contrast
T = decorrstretch(CIR);
% Reducing haze from the stretched image
J = imreducehaze(T);
% Applying white balance to the stretched image
D65_illuminant = whitepoint('d65');
K = chromadapt(J,'Method','perez');
% D65_illuminant = im2double(D65_illuminant);
% K = chromadapt(J,'Method','simple','illuminant',D65_illuminant);
% K = chromadapt(J,'Method','simple','illuminant', whitepoint('d65'))
% Dehazing the white-balanced RGB image using the dark channel prior algorithm
L = darkChannelPrior(K);
% Converting the dehazed RGB image to HSV color space
M = rgb2hsv(L);
% Performing linear stretching on the S channel of the HSV image
M(:,:,2) = imadjust(M(:,:,2));
% Applying multi-scale retinex with white top-hat filtering on the V channel of the HSV image
M(:,:,3) = retinex_wthat(M(:,:,3), [15 80 250]);
% Converting the HSV image back to RGB color space
N = hsv2rgb(M);
% Applying Contrast Limited Adaptive Histogram Equalization (CLAHE) on the RGB image
O = adapthisteq(N,'ClipLimit',0.02,'Distribution','rayleigh');
% Displaying the original multispectral image and all the processed images
figure;
subplot(2,4,1); imshow(CIR); title('Original Multispectral Image');
subplot(2,4,2); imshow(T); title('Decorrelation Stretch');
subplot(2,4,3); imshow(J); title('Reduced Haze');
subplot(2,4,4); imshow(K); title('White Balance');
subplot(2,4,5); imshow(L); title('Dehazed (Dark Channel Prior)');
subplot(2,4,6); imshow(N); title('Retinex + HSV Conversion');
subplot(2,4,7); imshow(O); title('CLAHE');
sgtitle('Processed Images');
% Computing the Structural Similarity Index (SSIM) and Peak Signal to Noise Ratio (PSNR) between the original and dehazed images
ssim_val = ssim(CIR, L);
psnr_val = psnr(CIR, L);
fprintf('SSIM: %f\nPSNR: %f\n', ssim_val, psnr_val);
%% Define the missing functions
% Function for computing the dark channel prior of an RGB image
function J = darkChannelPrior(I, patch_size)
if nargin < 2
patch_size = 15;
end
hazy_img = double(I);
hazy_gray = min(hazy_img, [], 3);
J = ordfilt2(hazy_gray, 1, ones(patch_size, patch_size));
end
function V = retinex_wthat(V, scales)
%RETINEX_WTHAT Multi-scale retinex with white top-hat filtering.
% V = RETINEX_WTHAT(V) applies multi-scale retinex with white top-hat
% filtering to the input image V. The function uses a set of pre-defined
% scales for the Gaussian blur and white top-hat filtering.
%
% V = RETINEX_WTHAT(V, SCALES) applies multi-scale retinex with white
% top-hat filtering using the scales specified in the input argument
% SCALES. SCALES should be a vector containing the standard deviation
% values for the Gaussian blur.
%
% Example:
% I = imread('lena.png');
% V = rgb2gray(I);
% V = im2double(V);
% V = retinex_wthat(V);
% imshow(V);
%
% Reference:
% Landini, G., and M. Randazzo. "A multi-scale Retinex for bridging
% the gap between color images and the human observation of scenes."
% Journal of Microscopy 207.2 (2002): 182-191.
%
% See also IMTOPHAT, FSPECIAL, IMFILTER.
% Set default scales
if nargin < 2
scales = [3 7 15];
end
% Apply multi-scale retinex
for i = 1:numel(scales)
sigma = scales(i);
hsize = 2 * ceil(2 * sigma) + 1;
% Gaussian blur
G = fspecial('gaussian', hsize, sigma);
V_smooth = imfilter(V, G, 'symmetric');
% White top-hat filtering
SE = strel('disk', hsize, 0);
V_wth = imtophat(V_smooth, SE);
% Add filtered image to result
V = V + V_wth;
end
% Normalize output
V = (V - min(V(:))) / (max(V(:)) - min(V(:)));
end
0 Comments
Accepted Answer
Cris LaPierre
on 8 Mar 2023
Your syntax for calling chromdapt is incorrect. You must have either 2 inputs or 4, but you have 3 so 'Method' is being treated as the 2nd input (illuminant).
0 Comments
More Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!