Bilinear Interpolation Adaptive Histogram Equalization matlab代码实现
时间: 2024-01-11 14:02:17 浏览: 103
以下是Bilinear Interpolation Adaptive Histogram Equalization的Matlab代码实现:
```matlab
function [outImg] = bilinearAdapthisteq(inImg, numTiles, clipLimit)
% Bilinear Interpolation Adaptive Histogram Equalization
% inImg: input image
% numTiles: number of tiles (default: 8x8)
% clipLimit: clipping limit (default: 0.01)
% outImg: output image
if nargin < 2
numTiles = [8 8];
end
if nargin < 3
clipLimit = 0.01;
end
inImg = double(inImg);
[h, w] = size(inImg);
tileH = floor(h / numTiles(1));
tileW = floor(w / numTiles(2));
outImg = zeros(h, w);
for i = 1:numTiles(1)
rowStart = (i - 1) * tileH + 1;
rowEnd = min(rowStart + tileH - 1, h);
rowSize = rowEnd - rowStart + 1;
for j = 1:numTiles(2)
colStart = (j - 1) * tileW + 1;
colEnd = min(colStart + tileW - 1, w);
colSize = colEnd - colStart + 1;
tile = inImg(rowStart:rowEnd, colStart:colEnd);
% histogram equalization
tileHist = histcounts(tile(:), 256);
tileHistCum = cumsum(tileHist) / sum(tileHist);
tileHistNew = max(0, floor(tileHistCum(tile(:)) * 255));
% clip histogram
tileHistNewClip = tileHistNew;
tileHistNewClip(tileHistNewClip > clipLimit * rowSize * colSize) = clipLimit * rowSize * colSize;
% bilinear interpolation
tileBilinear = interp2((0:255)', repmat([0 255], 256, 1), [tileHistNewClip; tileHistNewClip], tile, 'linear');
tileBilinear(isnan(tileBilinear)) = 0;
outImg(rowStart:rowEnd, colStart:colEnd) = tileBilinear;
end
end
outImg = uint8(outImg);
```
该函数的输入为原始图像、瓦片数量和剪切限制。输出为进行Bilinear Interpolation Adaptive Histogram Equalization后的图像。在实现中,将原始图像分成多个瓦片,对每个瓦片进行直方图均衡化。然后,通过双线性插值将直方图映射应用于每个像素。最后,将所有瓦片重新组合为一幅图像。
阅读全文