LIME 低亮度图像增强的offical demo code matlab
时间: 2024-05-08 22:21:51 浏览: 263
以下是 LIME 低亮度图像增强的官方演示代码,使用 MATLAB 编写:
```matlab
clear all;
close all;
clc;
% Read the input image
inImg = imread('sample.jpg');
inImg = im2double(inImg);
figure, imshow(inImg), title('Input Image');
% Compute the dark channel prior
patchSize = 15;
darkChannel = getDarkChannel(inImg, patchSize);
% Estimate the atmospheric light
atmLight = getAtmLight(inImg, darkChannel);
% Recover the transmission
transmission = getTransmissionEstimate(inImg, atmLight, patchSize);
% Perform the image dehazing
dehazedImg = performDehazing(inImg, transmission, atmLight);
% Display the output image
figure, imshow(dehazedImg), title('Dehazed Image');
% Get the dark channel prior
function darkChannel = getDarkChannel(img, patchSize)
[h, w, ~] = size(img);
darkChannel = zeros(h, w);
paddedImg = padarray(img, [floor(patchSize/2), floor(patchSize/2)], Inf);
for i = 1:h
for j = 1:w
patch = paddedImg(i:i+patchSize-1, j:j+patchSize-1, :);
darkChannel(i, j) = min(patch(:));
end
end
end
% Get the atmospheric light
function atmLight = getAtmLight(img, darkChannel)
[h, w, ~] = size(img);
imgSize = h * w;
numPixels = round(imgSize * 0.1);
[~, indices] = sort(darkChannel(:), 'descend');
indices = indices(1:numPixels);
maxVals = max(img,[],3);
atmLight = zeros(1,3);
for i = 1:numPixels
[row, col] = ind2sub([h w], indices(i));
atmLight = max(atmLight, squeeze(img(row, col, :)));
end
end
% Get the transmission estimate
function transmission = getTransmissionEstimate(img, atmLight, patchSize)
img = im2double(img);
[h, w, ~] = size(img);
transmission = zeros(h, w);
imgGray = min(img,[],3);
A = repmat(atmLight, h, w);
for i = 1:h
for j = 1:w
patch = imgGray(max(1,i-floor(patchSize/2)):min(i+floor(patchSize/2),h), ...
max(1,j-floor(patchSize/2)):min(j+floor(patchSize/2),w));
transmission(i,j) = 1 - 0.95*min(patch(:))/A(i,j);
end
end
end
% Perform the image dehazing
function dehazedImg = performDehazing(img, transmission, atmLight)
img = im2double(img);
[h, w, ~] = size(img);
A = repmat(atmLight, h, w);
transmission = max(transmission, 0.1);
dehazedImg = zeros(size(img));
for i = 1:3
I = img(:,:,i);
J = (I - A(i))./transmission + A(i);
dehazedImg(:,:,i) = J;
end
end
```
使用时,将输入图像的文件名替换为您自己的图像文件名即可。请注意,此代码只能用于 MATLAB。
阅读全文