图像处理---CLAHE(限制对比度自适应直方图均衡)算法MATLAB代码

function out = myCLAHE(I)

%ADAPTHISTEQ Contrast-limited Adaptive Histogram Equalization (CLAHE).
%   ADAPTHISTEQ enhances the contrast of images by transforming the
%   values in the intensity image I.  Unlike HISTEQ, it operates on small
%   data regions (tiles), rather than the entire image. Each tile's 
%   contrast is enhanced, so that the histogram of the output region
%   approximately matches the specified histogram. The neighboring tiles 
%   are then combined using bilinear interpolation in order to eliminate
%   artificially induced boundaries.  The contrast, especially
%   in homogeneous areas, can be limited in order to avoid amplifying the
%   noise which might be present in the image.

%--------------------------- The algorithm ----------------------------------
%
%  1. Obtain all the inputs: 
%    * image
%    * number of regions in row and column directions
%    * number of bins for the histograms used in building image transform
%      function (dynamic range)
%    * clip limit for contrast limiting (normalized from 0 to 1)
%    * other miscellaneous options
%  2. Pre-process the inputs:  
%    * determine real clip limit from the normalized value
%    * if necessary, pad the image before splitting it into regions
%  3. Process each contextual region (tile) thus producing gray level mappings
%    * extract a single image region
%    * make a histogram for this region using the specified number of bins
%    * clip the histogram using clip limit
%    * create a mapping (transformation function) for this region
%  4. Interpolate gray level mappings in order to assemble final CLAHE image
%    * extract cluster of four neighboring mapping functions
%    * process image region partly overlapping each of the mapping tiles
%    * extract a single pixel, apply four mappings to that pixel, and 
%      interpolate between the results to obtain the output pixel; repeat
%      over the entire image
%
%  See code for further details.
%
%-----------------------------------------------------------------------------

dimI = size(I);% 图像大小

% 'NumTiles'  Two-element vector
  • 1
    点赞
  • 38
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
以下是基于Lab模型的有限对比自适应直方图均衡化的MATLAB代码: ```matlab % 读入图像 img = imread('lena.png'); % 将RGB图像转换到Lab颜色空间 lab_img = rgb2lab(img); % 定义块大小和限制对比度因子 block_size = 16; % 块大小 clip_limit = 0.01; % 限制对比度因子 % 计算图像大小 [rows, cols, ~] = size(lab_img); % 计算每个块的数量 num_blocks_row = ceil(rows/block_size); num_blocks_col = ceil(cols/block_size); % 初始化输出图像 out_img = zeros(size(lab_img)); % 循环遍历每个块并进行CLAHE处理 for i = 1:num_blocks_row for j = 1:num_blocks_col % 计算当前块的位置 row_start = (i-1)*block_size+1; row_end = min(i*block_size, rows); col_start = (j-1)*block_size+1; col_end = min(j*block_size, cols); % 获取当前块 block = lab_img(row_start:row_end, col_start:col_end, :); % 将当前块转换为灰度图像 gray_block = block(:,:,1); % 对当前块进行有限对比自适应直方图均衡化 eq_block = adapthisteq(gray_block, 'ClipLimit', clip_limit, 'NumTiles', [8 8]); % 将均衡化的块复制回输出图像中 out_img(row_start:row_end, col_start:col_end, 1) = eq_block; out_img(row_start:row_end, col_start:col_end, 2:3) = block(:,:,2:3); end end % 将输出图像转换回RGB颜色空间 out_img = lab2rgb(out_img); % 显示原图和处理后的图像 figure; subplot(1,2,1); imshow(img); title('Original Image'); subplot(1,2,2); imshow(out_img); title('CLAHE with Lab Color Space'); ``` 请注意,以上代码仅演示了如何使用有限对比自适应直方图均衡化(CLAHE)处理基于Lab颜色空间的图像。如果需要使用其他颜色空间或自定义算法,则需要进行相应的更改。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值