You are on page 1of 5

IMAGE DEHAZING USING DARK CHANNEL

PRIOR ALGORITHM
S. MAHALAKSHMI 19ML05

R. KEERTHANA 19ML33

DEHAZING OF IMAGES

The presence of haze in the atmosphere degrades the quality of images captured by
visible camera sensors. The removal of haze, called dehazing, is typically performed under the
physical degradation model, which necessitates a solution of an ill-posed inverse problem. To
relieve the difficulty of the inverse problem, a novel prior called dark channel prior (DCP) was
recently proposed and has received a great deal of attention. The DCP is derived from the
characteristic of natural outdoor images that the intensity value of at least one color channel
within a local window is close to zero. Based on the DCP, the dehazing is accomplished
through four major steps: atmospheric light estimation, transmission map estimation,
transmission map refinement, and image reconstruction. This four-step dehazing process
makes it possible to provide a step-by-step approach to the complex solution of the ill-posed
inverse problem. This also enables us to shed light on the systematic contributions of recent
researches related to the DCP for each step of the dehazing process. Our detailed survey and
experimental analysis on DCP-based methods will help readers understand the effectiveness
of the individual step of the dehazing process and will facilitate development of advanced
dehazing algorithms.

DARK CHANNEL PRIOR ALGORITHM

Dark Channel Prior used by Kaiming for single image dehazing. His observation
revealed that, at least one colour channel of an rgb image has some pixels of lowest intensities,
which tends to zero. The dark channel suggests that at least one colour channel of an RGB
image have lowest intensities, which will almost tends to zero(When the pixels have lowest
intensities or tendency to zero, the colour diverges towards dark or black-That’s why he named
this phenomena as Dark Channel). So Kaiming He found this phenomena and used it for image
dehazing(To remove fog from natural outdoor image). By splitting the RGB image in Red
Green Blue channels and by selecting the minimum intensities pixels from all three channels
will result in some sort of dark image. Again dark channel can be refer to, selecting lowest
intensity pixels from three channels of a RGB image. The process of selecting the minimum
intense pixels from a RGB image can be refer to term prior, and we say it dark channel prior
DCP. For selecting the minimum pixels from an RGB colour channels a min{minimum
operator} is used.
ALGORITHM

MATLAB CODE:

fogged = imread('fog2.jpg'); %Fogged Image


figure, imshow(fogged);

fogged=imcomplement(fogged);
figure;
imshow(fogged);

%STEP.1. ESTIMATION OF GLOBAL AIRLIGHT.


frame = 10; % Local Patch Size
for k = 1 : 3
minimum_intense = ordfilt2(double(fogged(:, :, k)), 1, ones(frame), 'symmetric');
Airlight(k) = max(minimum_intense(:));
end

%STEP.2. CALCULATION OF DARK CHANNEL AND APPLY BOUNDARY CONSTRAINT


frame = 3;
bounded_fogged = boundary_constraint(fogged, Airlight, 30, 300, frame);
figure, imshow(bounded_fogged, []),title('Constraint Bounded Dark Channel Prior
Image');

%STEP.3. TRANSMISSION MAP CALCULATION.


reg_param = 2; % regularization parameter.
t = depth_map(fogged, bounded_fogged, reg_param, 0.5);
figure, imshow(1-t, []); colormap hot,title('Transmission Map');

%STEP.4. RECOVERY OF DE-FOGGGED IMAGE.


defog_param = 0.9;
t = max(abs(t), 0.0001).^defog_param;
fogged = double(fogged);
if length(Airlight) == 1
Airlight = Airlight * ones(3, 1);
end
R = (fogged(:, :, 1) - Airlight(1)) ./ t + Airlight(1);
G = (fogged(:, :, 2) - Airlight(2)) ./ t + Airlight(2);
B = (fogged(:, :, 3) - Airlight(3)) ./ t + Airlight(3);
defogged = cat(3, R, G, B) ./ 255;

figure,
imshow(defogged, []),title('Final Defogged Image');

defogged=imcomplement(defogged);
figure;
imshow(defogged, []),title('Final Defogged and enhanced Image');

BOUNDARY CONSTRAINT FUNCTION

function [p1, p2] = boundary_constraint(fogged, Airlight, C0, C1, frame)


% patch wise transmission from boundary constraint

if length(Airlight) == 1
Airlight = Airlight * ones(3, 1);
end
if length(C0) == 1
C0 = C0 * ones(3, 1);
end
if length(C1) == 1
C1 = C1 * ones(3, 1);
end
fogged = double(fogged);

% pixel-wise boundary
t_r = max((Airlight(1) - fogged(:, :, 1)) ./ (Airlight(1) - C0(1)), (fogged(:, :, 1)
- Airlight(1)) ./ (C1(1) - Airlight(1) ));
t_g = max((Airlight(2) - fogged(:, :, 2)) ./ (Airlight(2) - C0(2)), (fogged(:, :, 2) -
Airlight(2)) ./ (C1(2) - Airlight(2) ));
p2 = max((Airlight(3) - fogged(:, :, 3)) ./ (Airlight(3) - C0(3)), (fogged(:, :, 3) -
Airlight(3)) ./ (C1(3) - Airlight(3) ));
p2 = max(cat(3, t_r, t_g, p2), [], 3);
p2 = min(p2, 1);

% minimum filtering
se = strel('square', frame);
p1 = imclose(p2, se);

DEPTH MAP FUNCTION

function bound_fogged = depth_map(fogged, bound_fogged, reg_param, val)

[nRows, nCols] = size(bound_fogged);

% various filters to be applied


nsz = 3;
total = nsz * nsz;
d{1} = [5, 5, 5; -3, 0, -3; -3, -3, -3];
d{2} = [-3, 5, 5; -3, 0, 5; -3, -3, -3];
d{3} = [-3, -3, 5; -3, 0, 5; -3, -3, 5];
d{4} = [-3, -3, -3; -3, 0, 5; -3, 5, 5];
d{5} = [5, 5, 5; -3, 0, -3; -3, -3, -3];
d{6} = [-3, -3, -3; 5, 0, -3; 5, 5, -3];
d{7} = [5, -3, -3; 5, 0, -3; 5, -3, -3];
d{8} = [5, 5, -3; 5, 0, -3; -3, -3, -3];

% normalizing filters
num_filters = length(d);
for k = 1 : num_filters
d{k} = d{k} / norm(d{k}(:));
end

% calculating weighting function


for k = 1 : num_filters
weight{k} = weight_function(fogged, d{k}, val);
end

Tf = fft2(bound_fogged);
DS = 0;
for k = 1 : num_filters
D{k} = psf2otf(d{k}, [nRows, nCols]);
DS = DS + abs(D{k}).^2;
end

xponent = 1; xponent_rate = 2 * sqrt(2);


xponent_max = 2^8;

while xponent < xponent_max

gamma = reg_param / xponent;

DU = 0;
for k = 1 : num_filters
dt{k} = imfilter(bound_fogged, d{k}, 'circular');
u{k} = max(abs(dt{k}) - weight{k} / xponent / num_filters, 0) .* sign(dt{k});
DU = DU + fft2(imfilter(u{k}, flipud(fliplr(d{k})), 'circular'));
end

bound_fogged = abs(ifft2((gamma * Tf + DU) ./ ( gamma + DS)));

xponent = xponent * xponent_rate;


end

%%
function Weight = weight_function(fogged, D, val)
fogged = double(fogged) / 255;
d_r = imfilter(fogged(:, :, 1), D, 'circular');
d_g = imfilter(fogged(:, :, 2), D, 'circular');
d_b = imfilter(fogged(:, :, 3), D, 'circular');
Weight = exp(-(d_r.^2 + d_g.^2 + d_b.^2) / val / 2);
OUTPUT
INPUT IMAGE:

OUTPUT IMAGE:

You might also like