# 圖像增強序列——Adaptive Local Power-Law Transformation for Color Image Enhancement(自適應伽馬變換)

1. 參考文獻

2. 模型實現

``````% 論文： Adaptive Local Power-Law Transformation for Color Image Enhancement
% 作者： Chun-Ming Tsai
%
% Author: HSW
% Date: 2018-04-27

clc;
close all;
clear;

figure(1);
imshow(img, []);
title('原圖像');

if size(img, 3) == 3
img_hsv = rgb2hsv(img);
img_V = img_hsv(:, :, 3);
img_V  = img_V .* 255;
img_V_out = img_V;
alpha = 2.2;
[m, n] = size(img_V);
hsize = 3;
totalPixel = (2*hsize + 1) * (2*hsize + 1);
method = 2; % = 1 表示普通的計算方法， = 2 表示利用積分圖的計算方法

if method == 1
t0_1 = tic;
for i = hsize + 1:m - hsize
for j = hsize + 1:n - hsize
mu = sum(sum(img_V(i + [-hsize:hsize], j + [-hsize:hsize]))) / totalPixel;
gama = ( 1 / alpha)^((128 - mu) / 128.0);
img_V_out(i, j) = uint8(255 * (img_V(i,j) / 255.0)^gama);
end
end
t0_2 = toc(t0_1);
disp(num2str(t0_2));
else
img_v_int = boxFilter(img_V); % 計算積分圖花費的時間比較多，但是，對於矩形窗口較大的場景是有利的，感興趣的可以自己測試
t1_1 = tic;
for i = hsize+1:m-hsize
for j = hsize+1:n-hsize
mu = (img_v_int(i + hsize, j + hsize) + img_v_int(i - hsize, j - hsize) - img_v_int(i + hsize, j - hsize) - img_v_int(i - hsize, j + hsize)) / totalPixel;
gama = ( 1 / alpha)^((128 - mu) / 128.0);
img_V_out(i, j) = uint8(255 * (img_V(i,j) / 255.0)^gama);
end
end
t1_2 = toc(t1_1);
disp(num2str(t1_2));
end

img_hsv_out = img_hsv;
img_hsv_out(:, :, 3) = img_V_out ./ 255;
img_out = hsv2rgb(img_hsv_out);

figure(2);
imshow(img_out, []);
title('增強圖像');

else
disp('輸入需要彩色圖像');
end``````

``````function img_int = boxFilter(img)
% inputs:
%       img:
% outputs:
%        img_int:
% Author: HSW
% Date: 2018-04-27

img_int = zeros(size(img));
[rows, cols, dims] = size(img);

for i = 1:rows
for j = 1:cols
for dim = 1:dims
img_int(i, j, dim) =  img(i, j, dim);
if i - 1 > 0
img_int(i, j, dim) = img_int(i, j, dim) + img_int(i - 1, j, dim);
end
if j - 1 > 0
img_int(i, j, dim) = img_int(i, j, dim) + img_int(i, j-1, dim);
end
if i - 1 > 0 && j - 1 > 0
img_int(i, j, dim) = img_int(i, j, dim)  - img_int(i - 1, j -1, dim);
end
end
end
end

end``````

3. 模型效果