AHE和CLAHE matlab代码实现
时间: 2024-02-12 07:33:08 浏览: 147
以下是AHE和CLAHE的Matlab代码实现。
AHE:
```matlab
function J = AHE(I,ws)
% Adaptive Histogram Equalization
% I: input image
% ws: window size
I = im2double(I);
[m,n] = size(I);
J = zeros(m,n);
for i = 1:m
for j = 1:n
i1 = max(i-ws,1);
i2 = min(i+ws,m);
j1 = max(j-ws,1);
j2 = min(j+ws,n);
J(i,j) = histeq(I(i1:i2,j1:j2),256);
end
end
end
```
CLAHE:
```matlab
function J = CLAHE(I,ws,K)
% Contrast-Limited Adaptive Histogram Equalization
% I: input image
% ws: window size
% K: contrast enhancement factor
I = im2double(I);
[m,n] = size(I);
J = zeros(m,n);
for i = 1:m
for j = 1:n
i1 = max(i-ws,1);
i2 = min(i+ws,m);
j1 = max(j-ws,1);
j2 = min(j+ws,n);
J(i,j) = adapthisteq(I(i1:i2,j1:j2),'NumTiles',[8,8],'ClipLimit',K);
end
end
end
```
其中,AHE函数实现了自适应直方图均衡化,ws表示窗口大小;CLAHE函数实现了对比度受限的自适应直方图均衡化,ws表示窗口大小,K表示对比度增强因子。
阅读全文