双直方图均衡化

以下论述来自https://blog.csdn.net/weixin_39830846/article/details/89314413

是由 KIM 提出的.

是一种基于图象均值来分割输入图像,得到两幅子图,一幅是像素值小于或等于均值的样本集,另一幅是像素值大于均值的样本集。分别独立的进行直方图均衡化。

作用:增强图像对比度的同时,保持输入图像的平均亮度。

参考文献:Brightness Preserving Bi-Histogram Equalization,BBHE

提取了一下该增强算法的主要原理:


----------------------------------------------------------------------分割线-------------------------------------------------------

百度的都是matlab版本的,故自己写了个c++版本

先上效果图:

可以看到还是有一个提升的,但由于图像问题,提升不是这么明显

未经修改的核心代码如下:

void bbhe(uint8 *img, int width, int height)
{
	int Xm, Xmin = 1e9, Xmax=0;
	int len = width * height;
	int sl[256] = { 0 }, su[256] = { 0 };
	double pl[256] = { 0 }, pu[256] = { 0 };
	double cl[256] = { 0 }, cu[256] = { 0 };
	int nl, nu;
	nl = nu = 0;
	getInfo(img,width,height,&Xm,&Xmin,&Xmax);

	for (int i = 0; i < len; ++i)
	{
		if (img[i] <= Xm)
		{
			sl[img[i]]++;
			nl++;
		}
		else su[img[i]]++,nu++;
	}
	for (int i = 0; i < 256; ++i)
	{
		pl[i] = 1.0*sl[i] / nl;
		pu[i] = 1.0*su[i] / nu;
		
	}
	for (int i = 0; i < 256; ++i)
	{
		if (i == 0) {
			cl[i] = pl[i];
			cu[i] = pu[i];
		}
		else {
			cl[i] = pl[i] + cl[i - 1];
			cu[i] = pu[i] + cu[i - 1];
		}
	}

	for (int i = 0; i < Xm; ++i)
		cl[i] = Xmin + cl[i]*(Xm - Xmin);

	for (int i = Xm; i < 256; ++i)
		cu[i] = Xm+1 + cu[i]*(Xmax - Xm - 1);

	for (int i = 0; i < len; ++i)
	{
		if (img[i] <= Xm)img[i] = cl[img[i]];
		else img[i] = cu[img[i]];
	}
}

 

  • 3
    点赞
  • 17
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
下面是直方图均衡化的MATLAB代码: ```matlab function [out, H] = bhisteq(in, ref) % Bilateral Histogram Equalization % Usage: [out, H] = bhisteq(in, ref); % where: in = input image % ref = reference image % out = output image % H = the histogram of the reference image % % Author: Jun Zhang % Date: 2021-05-05 % Convert both images to gray scale if size(in,3)==3 in = rgb2gray(in); end if size(ref,3)==3 ref = rgb2gray(ref); end % Compute the histogram of the reference image Hr = imhist(ref); % Compute the cumulative histogram of the reference image cumHr = cumsum(Hr); % Compute the normalized cumulative histogram of the reference image cumHr_norm = cumHr / numel(ref); % Compute the histogram of the input image Hi = imhist(in); % Compute the cumulative histogram of the input image cumHi = cumsum(Hi); % Compute the normalized cumulative histogram of the input image cumHi_norm = cumHi / numel(in); % Initialize the output image out = zeros(size(in)); % Apply the bilateral histogram equalization for i = 1:256 % Compute the index j for which cumHr_norm(j) is closest to cumHi_norm(i) [~,j] = min(abs(cumHr_norm-cumHi_norm(i))); % Compute the lookup table LUT(i) = j-1; end % Apply the lookup table to the input image for i = 1:numel(in) out(i) = LUT(in(i)+1); end % Compute the histogram of the output image H = imhist(out); % Normalize the histogram of the output image H = H / numel(out); % Display the histogram of the reference image and the output image figure; subplot(2,1,1), bar(Hr), title('Histogram of Reference Image'); subplot(2,1,2), bar(H), title('Histogram of Output Image'); end ``` 说明: 该代码实现了直方图均衡化算法,使用的是参考图像的直方图来对输入图像进行均衡化。该算法的基本思想是将输入图像的直方图映射到参考图像的直方图上,从而实现对输入图像的均衡化。算法的具体实现步骤为: 1. 将输入图像和参考图像转换为灰度图像。 2. 计算参考图像的直方图和累积直方图。 3. 对输入图像进行直方图均衡化,并计算输入图像的直方图和累积直方图。 4. 对于输入图像的每一个像素值,找到参考图像中累积直方图最接近的像素值,并将其作为映射表的输出值。 5. 使用映射表来对输入图像进行均衡化。 该代码的输入参数为输入图像和参考图像,输出参数为均衡化后的图像和参考图像的直方图。注意,该代码使用的是 MATLAB 自带的 imhist 函数来计算直方图。因此,在使用该代码之前,需要确保 MATLAB 已经安装并配置好。
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值