自适应直方图均衡化
自适应均衡算法

自适应均衡算法自适应均衡算法是一种常用的数字图像处理算法,它可以有效地提高图像的质量和清晰度。
该算法的核心思想是通过对图像的直方图进行分析和处理,使得图像的亮度和对比度得到均衡,从而达到优化图像质量的目的。
本文将从算法原理、应用场景和优缺点三个方面来介绍自适应均衡算法。
一、算法原理自适应均衡算法的核心思想是将图像的直方图进行分析和处理,使得图像的亮度和对比度得到均衡。
具体来说,该算法将图像分成若干个小区域,对每个小区域的直方图进行均衡化处理,然后将处理后的小区域重新组合成一张完整的图像。
这样做的好处是可以针对不同区域的亮度和对比度进行不同的处理,从而达到更好的均衡效果。
自适应均衡算法的具体步骤如下:1. 将图像分成若干个小区域,每个小区域的大小可以根据实际情况进行调整。
2. 对每个小区域的直方图进行均衡化处理,使得该区域的亮度和对比度得到均衡。
3. 将处理后的小区域重新组合成一张完整的图像。
二、应用场景自适应均衡算法在数字图像处理中有着广泛的应用场景,下面列举几个常见的应用场景:1. 医学图像处理:在医学图像处理中,自适应均衡算法可以用来增强图像的对比度和清晰度,从而更好地显示病变部位。
2. 景观照片处理:在景观照片处理中,自适应均衡算法可以用来增强图像的色彩和对比度,从而使得照片更加美观。
3. 安防监控:在安防监控中,自适应均衡算法可以用来增强图像的亮度和对比度,从而更好地识别出目标物体。
三、优缺点自适应均衡算法有着许多优点,但也存在一些缺点,下面分别进行介绍:1. 优点:(1)能够针对不同区域的亮度和对比度进行不同的处理,从而达到更好的均衡效果。
(2)处理速度较快,适用于实时处理。
(3)算法简单易懂,易于实现。
2. 缺点:(1)容易出现过度增强的情况,导致图像失真。
(2)对于图像中存在的噪声和干扰,自适应均衡算法的效果并不理想。
(3)算法对于图像的分割和区域划分要求较高,需要进行精细的处理。
使用计算机视觉技术进行图像对比度调整的技巧解析

使用计算机视觉技术进行图像对比度调整的技巧解析在数字图像处理中,调整图像对比度是一项常见的任务。
通过增强图像的对比度,可以使图像更加清晰,突出细节,并提高图像质量。
近年来,随着计算机视觉技术的不断发展,使用计算机视觉技术进行图像对比度调整变得更加普遍和便捷。
本文将介绍一些使用计算机视觉技术进行图像对比度调整的技巧,帮助读者更好地理解和应用这些技术。
1. 直方图均衡化直方图均衡化是一种常用的图像增强技术,可以有效地调整图像的对比度。
通过增大图像中较暗像素的亮度值并降低较亮像素的亮度值,直方图均衡化可以拉伸图像中的亮度范围,使得图像更具对比度。
这一技术的基本原理是通过对图像的累积分布函数进行变换,将原始图像的亮度值均匀分布到整个亮度范围内。
2. 自适应直方图均衡化自适应直方图均衡化是对传统直方图均衡化的改进。
传统的直方图均衡化将整个图像的亮度范围均匀拉伸,但可能在某些情况下导致图像过度增强或细节丢失。
自适应直方图均衡化通过将图像分割成不同的区域,并对每个区域分别进行直方图均衡化来避免这些问题。
这样可以更好地保留图像的局部对比度,对于包含不同亮度区域的图像效果更好。
3. 对比度拉伸对比度拉伸是一种简单却有效的图像对比度调整技术。
该方法通过调整图像中各个像素的亮度值来达到增强对比度的目的。
一种常用的对比度拉伸方法是基于百分比的线性拉伸,即将两个百分位点映射到最低和最高亮度值上。
例如,将亮度的0.1%和99.9%分位点映射到0和255上。
这种方法适用于某些场景下,但在某些情况下可能会导致细节的损失。
4. Retinex算法Retinex算法是一种模拟人类视觉系统感知图像的算法。
这种算法可以通过调整图像中的亮度信息来增强对比度。
Retinex算法的原理是基于反射物体的颜色和亮度信息,通过估计图像中的光照分布来提取物体的颜色信息。
通过对于亮度信息的调整,可以增强图像的对比度。
Retinex算法可以在亮度不均匀和光照条件不理想的情况下提供较好的图像增强效果。
人脸识别技术的图像增强方法详解

人脸识别技术的图像增强方法详解人脸识别技术作为一种先进的生物识别技术,已经广泛应用于各个领域,如安全监控、人脸解锁、人脸支付等。
然而,由于环境光线、姿态、表情等因素的影响,人脸图像的质量可能会受到一定的影响,从而降低了识别的准确性。
为了解决这一问题,人们提出了各种图像增强方法,以提高人脸识别的性能。
一、直方图均衡化直方图均衡化是一种常用的图像增强方法,它通过对图像的像素值进行重新分配,使得图像的直方图更加均匀。
在人脸识别中,直方图均衡化可以增强图像的对比度,提高图像的清晰度。
具体而言,直方图均衡化可以通过以下步骤实现:1. 计算图像的直方图,得到各个灰度级的像素数量;2. 计算累积分布函数,得到每个灰度级对应的累积概率;3. 根据累积概率将原始图像的像素值映射到新的灰度级。
直方图均衡化能够有效地增强图像的对比度,使得人脸特征更加明显,从而提高了人脸识别的准确性。
二、自适应直方图均衡化尽管直方图均衡化能够增强图像的对比度,但是它忽略了图像局部的细节信息,可能会导致图像过度增强或细节丢失的问题。
为了解决这一问题,人们提出了自适应直方图均衡化方法。
自适应直方图均衡化将图像分成多个小区域,对每个小区域进行直方图均衡化,从而保留了图像的细节信息。
自适应直方图均衡化的具体步骤如下:1. 将原始图像分成多个小区域;2. 对每个小区域进行直方图均衡化;3. 将均衡化后的小区域合并成最终的增强图像。
自适应直方图均衡化能够更好地保留图像的细节信息,提高了人脸识别的准确性。
三、多尺度Retinex算法多尺度Retinex算法是一种基于图像亮度的增强方法,它通过模拟人眼对亮度的感知来增强图像的细节。
多尺度Retinex算法通过计算图像在不同尺度上的亮度分布,然后将亮度分布与原始图像进行融合,从而得到增强后的图像。
多尺度Retinex算法的具体步骤如下:1. 将原始图像分解成多个尺度的图像;2. 对每个尺度的图像进行Retinex增强,得到亮度分布图像;3. 将亮度分布图像与原始图像进行融合,得到增强后的图像。
色彩还原等级

色彩还原等级
色彩还原等级是指将图像中的色彩信息恢复到原始状态的程度。
在数字图像处理中,由于种种原因,图像的色彩信息可能会丢失或失真。
通过色彩还原技术,可以尽可能准确地还原图像中的色彩信息,使图像看起来更加真实、自然。
色彩还原等级的高低取决于多个因素,包括图像的质量、噪声、亮度和对比度等。
在进行色彩还原时,首先要对图像进行预处理,消除噪声和伪影。
然后,根据图像的特点和需求,选择适当的色彩还原算法进行处理。
常用的色彩还原算法包括直方图均衡化、自适应直方图均衡化和Retinex算法等。
直方图均衡化是一种简单有效的算法,通过对图像的直方图进行变换,使图像的亮度分布均匀,达到增强对比度的效果。
自适应直方图均衡化是对直方图均衡化的改进,可以根据图像的局部特性进行自适应调整。
Retinex算法则是一种基于人眼视觉特性的色彩还原算法,可以更好地模拟人眼对光照的感知。
无论采用哪种算法,色彩还原都需要在保持图像细节的同时,尽可能准确地恢复图像的色彩信息。
在实际应用中,还可以根据具体需求对色彩还原结果进行进一步的调整和优化,以获得更好的效果。
色彩还原等级是对图像色彩还原效果的评估,通过选择合适的色彩还原算法和参数,可以尽可能地恢复图像的色彩信息,使图像更加
真实、自然。
色彩还原技术在数字图像处理中具有广泛的应用前景,可以提高图像的质量和可视化效果,满足人们对图像的需求和期望。
详解OpenCV自适应直方图均衡化的应用

详解OpenCV ⾃适应直⽅图均衡化的应⽤⽬录介绍主要代码⽐较 CLAHE 和直⽅图均衡化介绍在中,我们已经了解的直⽅图均衡化的基本概念,并且可以使⽤ cv2.equalizeHist() 函数执⾏直⽅图均衡。
在本节中,将介绍如何应⽤对⽐度受限的⾃适应直⽅图均衡化 ( Contrast Limited Adaptive Histogram Equalization , CLAHE ) 来均衡图像,CLAHE 是⾃适应直⽅图均衡化( Adaptive Histogram Equalization , AHE )的⼀种变体,区别在于其对⽐度的增⼤是受限的。
图像相对均匀区域中的噪声被 AHE 过度放⼤,⽽ CLAHE 通过限制对⽐度增⼤来解决这个问题。
该算法通过创建原始图像的多个直⽅图,并使⽤这些直⽅图来重新分配图像的亮度,⽤于提⾼图像的对⽐度。
主要代码接下来,将 CLAHE 应⽤于灰度和彩⾊图像。
应⽤ CLAHE 时,有两个重要参数,第⼀个是 clipLimit ,它设置对⽐度限制的阈值,默认值为 40;第⼆个是 tileGridSize ,它设置⾏和列中的 tiles 数量。
应⽤ CLAHE 时,图像被分成称为 tiles (默认为 8 x 8 )的⼩块以执⾏其计算。
将 CLAHE 应⽤于灰度图像,需要使⽤以下代码:123456789101112# 加载图像image = cv2.imread('example.png')gray_image = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)# 灰度图像应⽤ CLAHE clahe = cv2.createCLAHE(clipLimit=2.0)gray_image_clahe = clahe.apply(gray_image)# 使⽤不同 clipLimit 值clahe.setClipLimit(5.0)gray_image_clahe_2 = clahe.apply(gray_image)clahe.setClipLimit(10.0)gray_image_clahe_3 = clahe.apply(gray_image)clahe.setClipLimit(20.0)gray_image_clahe_4 = clahe.apply(gray_image)然后,我们将 CLAHE 应⽤于彩⾊图像,类似于彩⾊图像对⽐度均衡的⽅法,创建四个函数以仅在不同颜⾊空间的亮度通道上使⽤ CLAHE 来均衡化彩⾊图像:1234567891011121314151617def equalize_clahe_color_hsv(img):cla = cv2.createCLAHE(clipLimit=4.0)H, S, V = cv2.split(cv2.cvtColor(img, cv2.COLOR_BGR2HSV))eq_V = cla.apply(V)eq_image = cv2.cvtColor(cv2.merge([H, S, eq_V]), cv2.COLOR_HSV2BGR)return eq_imagedef equalize_clahe_color_lab(img): cla = cv2.createCLAHE(clipLimit=4.0)L, a, b = cv2.split(cv2.cvtColor(img, cv2.COLOR_BGR2Lab)) eq_L = cla.apply(L)eq_image = cv2.cvtColor(cv2.merge([eq_L, a, b]), cv2.COLOR_Lab2BGR)return eq_imagedef equalize_clahe_color_yuv(img): cla = cv2.createCLAHE(clipLimit=4.0)1819202122232425262728293031323334353637383940Y, U, V =cv2.split(cv2.cvtColor(img, cv2.COLOR_BGR2YUV)) eq_Y = cla.apply(Y)eq_image = cv2.cvtColor(cv2.merge([eq_Y, U, V]), cv2.COLOR_YUV2BGR)return eq_imagedef equalize_clahe_color(img):cla = cv2.createCLAHE(clipLimit=4.0)channels = cv2.split(img)eq_channels = []for ch in channels:eq_channels.append(cla.apply(ch))eq_image = cv2.merge(eq_channels)return eq_image# 彩⾊图像应⽤ CLAHEimage_clahe_color = equalize_clahe_color(image)image_clahe_color_lab = equalize_clahe_color_lab(image)image_clahe_color_hsv = equalize_clahe_color_hsv(image)image_clahe_color_yuv = equalize_clahe_color_yuv(image)# 可视化show_img_with_matplotlib(cv2.cvtColor(gray_image, cv2.COLOR_GRAY2BGR), "gray", 1)show_img_with_matplotlib(cv2.cvtColor(gray_image_clahe, cv2.COLOR_GRAY2BGR), "gray CLAHE clipLimit=2.0", 2)show_img_with_matplotlib(cv2.cvtColor(gray_image_clahe_2, cv2.COLOR_GRAY2BGR), "gray CLAHE clipLimit=5.0", 3)# 其他图像的可视化⽅法类似,不再赘述# ...将所有这些函数应⽤于测试图像后⽐较结果,如下图所⽰:在上图中,我们可以看到改变 clipLimit 参数在测试图像上应⽤ CLAHE 后的不同效果,同时也可以看到在不同颜⾊空间( LAB 、HSV 和 YUV )的亮度通道上应⽤ CLAHE 后的不同结果。
内窥镜荧光稳定算法

内窥镜荧光稳定算法是一种用于提高内窥镜图像质量的算法,主要用于减少图像中的噪声、抑制图像的颜色变化和提高图像的对比度。
内窥镜荧光稳定算法的基本原理是通过对图像的亮度、对比度和颜色进行调整,使图像中的荧光信号更加清晰可见。
常用的内窥镜荧光稳定算法包括以下几种:
1. 直方图均衡化:通过对图像的直方图进行调整,使图像的亮度分布更加均匀,从而提高图像的对比度。
2. 自适应直方图均衡化:在直方图均衡化的基础上,结合图像的局部特征,对不同区域的亮度进行不同程度的调整,以避免图像过度增强或失真。
3. 双边滤波:通过对图像的像素进行加权平均,使得图像的噪声得到抑制,同时保留图像的边缘信息。
4. 颜色校正:通过对图像的颜色进行调整,使图像的颜色更加真实,减少颜色的偏差和变化。
5. 图像融合:将多张图像进行融合,以提高图像的清晰度和对比度。
以上是一些常用的内窥镜荧光稳定算法,具体的算法选择和参数设置可以根据实际情况进行调整。
图像增强的方法有哪些

图像增强的方法有哪些
图像增强的方法包括以下几种:
1. 直方图均衡化(Histogram equalization):通过调整图像的像素分布,增强图像的对比度。
2. 自适应直方图均衡化(Adaptive histogram equalization):与直方图均衡化类似,但是对图像的小区域进行局部均衡化,可以更好地保留细节信息。
3. 均值滤波(Mean filter):用图像中像素的平均值替代该像素的值,平滑图像的同时增强细节。
4. 中值滤波(Median filter):用图像中像素的中值替代该像素的值,能够有效去除椒盐噪声,保留图像边缘。
5. 高斯滤波(Gaussian filter):使用高斯函数对图像进行平滑,可以模糊图像的同时去除噪声。
6. 锐化增强(Sharpening):利用锐化算子对图像进行卷积,突出图像的边缘和细节。
7. 退化与恢复(Degradation and restoration):通过建立图像模糊模型和噪
声模型,对退化图像进行恢复。
8. 增强滤波(Enhancement filter):通过设计特定的增强滤波器,对图像进行增强,如Sobel滤波器、Prewitt滤波器等。
9. 超分辨率(Super-resolution):通过使用多帧图像或者其他方法,提高低分辨率图像的细节和清晰度。
以上仅是图像增强的一些常见方法,随着图像处理技术的不断发展,还有很多其他方法可以用于图像增强。
对比度增强的方法

对比度增强的方法对比度增强是数字图像处理中一种常用的图像增强技术,其目的是通过调整图像中不同亮度级的像素值,使图像中的细节更加明显,从而提高图像的视觉质量。
在数字图像中,对比度越高,图像的明暗差异越明显,细节越清晰。
以下是几种常用的对比度增强方法:1.直方图拉伸:直方图拉伸是一种简单且有效的对比度增强方法。
它通过将图像的像素值线性映射到一个更宽的值域范围内,以扩展原始图像的灰度级范围。
这样可以使图像的黑色和白色更加明显,细节更加清晰。
2.直方图均衡化:直方图均衡化是一种通过重新分布图像中像素的灰度级来增强对比度的方法。
通过对图像的累积分布函数进行均衡化,可以使得图像中的灰度级分布更加均匀,从而提高图像的对比度。
但是,直方图均衡化可能会导致图像的整体亮度发生变化,需要进一步处理以保持原始图像的亮度。
3.自适应直方图均衡化:自适应直方图均衡化是一种改进的直方图均衡化方法,可以在不影响图像整体亮度的情况下增强图像的对比度。
它将图像划分为多个小块,在每个小块上进行直方图均衡化,以适应不同区域的亮度变化。
4.对比度拉伸:对比度拉伸是一种通过压缩图像的动态范围来增强对比度的方法。
它将图像的像素值重新映射到一个较小的范围内,以增加图像中各个灰度级之间的差异。
通常可以通过设置一个合适的拉伸参数来控制拉伸的程度。
5.非线性映射:非线性映射是一种通过对图像像素值进行非线性的转换来增强对比度的方法。
常用的非线性映射函数包括对数变换、幂次变换等。
这些函数可以调整图像中较低或较高灰度级的像素值,以增强图像中的细节。
此外,还有一些其他的对比度增强方法,如灰度变换、直方图规定化等,它们都可以通过调整图像像素值的分布来增强对比度。
选择合适的对比度增强方法需要考虑图像的特点以及增强的目的,最终效果的好坏需要通过实验来验证。
数字图像处理算法中的细节增强

数字图像处理算法中的细节增强数字图像处理是指通过计算机算法对数字图像进行处理和改进的过程。
其中,细节增强是一种常见且重要的处理方式,旨在突出图像中的细节信息,提高图像的质量和清晰度。
本文将介绍数字图像处理算法中的细节增强方法以及它们的原理和应用。
一、直方图均衡化(Histogram Equalization)直方图均衡化是一种广泛应用于图像增强的方法。
其基本原理是通过重新分布图像中像素的灰度级,使得图像中的灰度值按照均匀分布的方式出现,从而增加图像的对比度并凸显细节。
具体来说,直方图均衡化分为以下几个步骤:1. 计算图像的直方图,即每个灰度级出现的次数;2. 计算图像的累积直方图,即每个灰度级出现的累积次数;3. 根据累积直方图以及图像的最大最小灰度级,重新分布像素的灰度级;4. 更新图像的像素值,使得图像的灰度级按照均衡化的直方图进行分布。
直方图均衡化的优点是简单易实现,并且适用于大部分的图像。
然而,由于其对整个图像的统计信息进行处理,可能会导致图像的噪声增加和背景细节丢失的问题。
为解决这些问题,后续的算法提出了更加复杂的细节增强方法。
二、自适应直方图均衡化(Adaptive Histogram Equalization,AHE)自适应直方图均衡化是一种改进的直方图均衡化方法,它能针对不同区域的图像进行不同的处理,以保持细节并减少噪声。
其基本原理是将图像分割成许多小的局部区域,并对每个区域进行直方图均衡化。
具体来说,自适应直方图均衡化分为以下几个步骤:1. 将图像分割成大小相等的小区域;2. 对每个小区域进行直方图均衡化,使得每个区域中的灰度级分布均匀;3. 将各个小区域重新合并为原始尺寸的图像。
与传统的直方图均衡化相比,自适应直方图均衡化通过适应不同区域的直方图均衡化保留了更多的细节信息,同时避免了噪声的引入。
然而,自适应直方图均衡化存在一些问题,如对于过亮或过暗的区域处理效果较差。
三、双边滤波(Bilateral Filtering)双边滤波是一种基于图像的空间和灰度相似性的滤波方法,常在图像细节增强中应用。
直方图直方图均衡化增强

直方图均衡化可以改善医学影像的对比度,使医生能够更清晰地观察病变区域,从而提高诊断的准确 性和可靠性。
病理分析
在病理切片分析中,直方图均衡化可以增强细胞核和染色体的细节,有助于病理医生进行更准确的诊 断和分类。
遥感图像增强
土地利用分类
通过直方图均衡化增强遥感图像的对比度,可以更好地区分不同类型的土地利用,如森 林、城市、农田等。
要点二
详细描述
多尺度直方图均衡化的基本思想是将图像分解为多个尺度 的小波系数,每个尺度上的小波系数具有不同的空间分辨 率和频率特性。在每个尺度上进行直方图均衡化,可以增 强图像在该尺度上的细节和边缘信息。通过将多个尺度上 的结果进行融合,可以得到增强后的图像。这种方法能够 更好地处理图像中的高频信息和边缘细节,提高图像的视 觉效果。
联合直方图均衡化
总结词
联合直方图均衡化是一种改进的直方图均衡化方法, 通过联合考虑多个图像或图像的多个通道进行直方图 均衡化,以增强图像的对比度和色彩信息。
详细描述
联合直方图均衡化的基本思想是同时对多个图像或图 像的多个通道进行直方图均衡化。通过联合处理,可 以增强图像的对比度和色彩信息,提高图像的视觉效 果。在实际应用中,可以同时对RGB三个通道进行联 合直方图均衡化,以增强彩色图像的色彩信息;也可 以对相邻帧的图像进行联合直方图均衡化,以提高视 频的清晰度和对比度。
可能会改变原始图像的灰度分布
01
直方图均衡化会改变原始图像的灰度分布,可能导致一些细节
信息的丢失。
对噪声敏感
02
在存在噪声的情况下,直方图均衡化可能会放大噪声,影响增
强效果。
对动态范围较小的图像效果不佳
03
对于动态范围较小的图像,直方图均衡化可能无法显著提高对
【数字图像处理】直方图均衡化

【数字图像处理】直⽅图均衡化全局直⽅图均衡化直⽅图均衡化通过调整图像的直⽅图来增强图像的对⽐度,经常使⽤在医学图像分析中。
例如⼀幅8*8图像像素值如下:对各个像素值进⾏计数:得到累计概率分布:其中均衡化后的像素值计算公式为:前⾯的标题全局直⽅图均衡化,代表着直⽅图在整个图像计算,这样会有⼀个缺点,图像的部分区域会显得过暗或者过亮。
这个时候就需要使⽤⾃适应直⽅图均衡化(Adaptive histogram equalization)。
⾃适应直⽅图均衡化,⾸先将图像分为⼏个部分,然后对每个部分分别计算直⽅图进⾏均衡化,同时对边缘像素进⾏插值处理。
由图中可以看出⾃适应直⽅图均衡化对⾼亮区域的处理要⽐常规的直⽅图均衡化好的多。
1import os2from PIL import Image3from skimage import exposure4import numpy as np5import matplotlib.pyplot as plt678 img = Image.open('/home/vincent/Pictures/work/Unequalized_Hawkes_Bay_NZ.jpg')9 img = np.array(img)10 img_eq = exposure.equalize_hist(img)11 img_adapteq = exposure.equalize_adapthist(img, clip_limit=0.04)1213 plt.figure(0)14 plt.imshow(img)15 plt.title('low contrast image')16 plt.figure(1)17 plt.imshow(img_eq)18 plt.title('high constrast image using normal histogram equalization')19 plt.figure(2)20 plt.imshow(img_adapteq)21 plt.title('high constract image using adaptive histogram euqalization')22 plt.show()。
低光照增强lime算法

低光照增强lime算法
低光照增强是指对于光线较暗的图像进行处理,提高图像的亮度和清晰度。
LIME(Low Light Image Enhancement)算法是
一种常见的低光照增强算法之一。
LIME算法的基本原理是通过对图像进行自适应直方图均衡和
双边滤波来增强图像的亮度和对比度。
具体步骤如下:
1. 自适应直方图均衡化:首先对图像的亮度进行增强,通过调整图像的像素值分布来拉伸图像的动态范围。
这样可以使图像中的细节更加明显。
2. 双边滤波:直方图均衡化会增强图像的噪声,为了减少噪声的影响并保持图像的细节,使用双边滤波来平滑图像。
双边滤波在保持图像边缘的同时,对图像进行平滑。
3. 融合图像:将原始图像与经过直方图均衡化和双边滤波处理后的图像进行融合,以保持图像的细节和结构,并增强图像的亮度和对比度。
LIME算法可以有效地增强低光照图像,并提高图像的可视性。
但是在处理过程中,可能会产生一些副作用,如图像的噪点和伪影。
因此,在实际应用中,需要根据具体情况进行参数调整和后期处理,以达到最佳效果。
卫星图像遥感处理中的图像增强和目标检测算法研究

卫星图像遥感处理中的图像增强和目标检测算法研究图像增强和目标检测是卫星图像遥感处理中的两个关键任务,它们在提高图像质量和提取目标信息方面具有重要意义。
本文将从图像增强和目标检测两个方面进行详细研究,介绍常见的算法和技术,并探讨它们在卫星图像遥感处理中的应用。
一、图像增强算法研究图像增强的目标是改善图像的视觉质量和可读性,使得图像中的细节更加清晰、对比度更强、噪声更少。
主要的图像增强算法包括直方图均衡化、自适应直方图均衡化、灰度拉伸等。
1. 直方图均衡化直方图均衡化是一种常用的图像增强方法,它通过调整图像的灰度直方图来扩展图像的动态范围。
具体而言,直方图均衡化将像素的灰度值按照一定的规则进行映射,使得图像中的亮度分布更加均匀。
这种方法能够增强图像的整体对比度,但可能导致图像的细节丢失。
2. 自适应直方图均衡化自适应直方图均衡化是对直方图均衡化的改进,它将图像分成多个小块,并对每个小块进行直方图均衡化。
这种方法能够在增强图像对比度的同时,保留更多图像的细节信息。
3. 灰度拉伸灰度拉伸是一种通过设置灰度级范围来增强局部对比度的方法。
这种方法通过将图像的灰度范围进行压缩或拉伸,使得图像中的细节更加清晰可见。
二、目标检测算法研究目标检测是卫星图像遥感处理中的关键任务,其目标是自动地在图像中定位和识别感兴趣的目标。
常见的目标检测算法包括基于滑动窗口的方法、基于卷积神经网络(CNN)的方法等。
1. 基于滑动窗口的方法基于滑动窗口的方法是一种经典的目标检测算法,其基本思想是在图像上滑动一个固定大小的窗口,并使用分类器来判断窗口内是否包含目标。
这种方法简单直观,但在实际应用中存在着计算复杂度高、目标尺度变化等问题。
2. 基于卷积神经网络的方法基于卷积神经网络的方法在目标检测领域取得了很大的突破,如今已成为最常用的目标检测算法之一。
这种方法通过在卷积神经网络中引入检测头和回归头,实现对目标的位置和类别的同时预测。
由于神经网络的强大特征提取和表达能力,这种方法在目标检测精度和速度方面都有了显著提高。
对比度受限的自适应直方图均衡化

对比“直方图均衡化、直方图平滑、自适应直方图均衡化、”处 理图像的效果。 提出“对比度受限针对曝光太亮或太暗的图像,其灰度直方图比较集中。为了 调节图像亮度和对比度,直方图均衡化可使原图像的直方图通过灰度 映射函数修正为灰度均匀分布的直方图。
流程: 原直方图—累计分布函数—映射取整—绘制均衡后的直方 图—画出均衡后的图像
b:直方图平滑
有些图像直方图呈锯齿状起伏,一些场合需要将其平滑化 (地质)。
处理方法: 为了保证平滑后的均值和方差保持不变,采用线性规划模型。 将直方图分成K个数据组,分别对每个数据组平滑处理,平滑后峰值 数量明显减少。
对比度的幅度可以定义为灰阶映射函数的斜率,假定均衡化的 滑动窗口大小为M*M,局部映射函数为
cdf(i)为 窗口累计分布函数
255 * cdf (i ) m(t ) M *M
映射函数斜率S为
导数。限定S,对应有最大H(i)。
dm (t ) 255 s H (i) * dt M *M
, H ( i )为 CDF ( i )的
c:自适应直方图均衡化 直方图均衡化对图像所有像素采用相同的映射函数,忽略了 图像的局部特征,将丢失有用信息,对去噪处理和边缘检测带来损失。 自适应:
采用局部法对图像处理,不同局部采用不同不同对比度增强方法。
d:对比度受限直方图均衡化
通过限制局部直方图的高度来限制局部对比度的增强幅度,从而 限制噪声的放大及局部对比度的过增强。
将切去的部分均匀的分布在整个灰阶范围上,使直方图整体上升一个高 度。 可以有效的抑制局部对比度增强及噪声放大,输出会有人为噪声,原因 是灰阶区域直方图剧烈变化。
python库skimage图像直方图均衡化、自适应均衡化、对比度拉伸实现

python库skimage图像直⽅图均衡化、⾃适应均衡化、对⽐度拉伸实现直⽅图全局均衡化from skimage import exposure# Equalizationimg_eq = exposure.equalize_hist(img)直⽅图⾃适应均衡化# Adaptive Equalization# 参数2:Clipping limit, normalized between 0 and 1 (higher values give more contrast).img_adapteq = exposure.equalize_adapthist(img, clip_limit=0.03)直⽅图对⽐度拉伸# Contrast stretchingp2, p98 = np.percentile(img, (2, 98))img_rescale = exposure.rescale_intensity(img, in_range=(p2, p98))实验:直⽅图全局均衡化、⾃适应均衡化、对⽐度拉伸效果对⽐"""======================Histogram Equalization======================This examples enhances an image with low contrast, using a method called*histogram equalization*, which "spreads out the most frequent intensityvalues" in an image. The equalized image has a roughly linear cumulativedistribution function.While histogram equalization has the advantage that it requires no parameters,it sometimes yields unnatural looking images. An alternative method is*contrast stretching*, where the image is rescaled to include all intensitiesthat fall within the 2nd and 98th percentiles."""import matplotlibimport matplotlib.pyplot as pltimport numpy as npfrom skimage import data, img_as_floatfrom skimage import exposurematplotlib.rcParams['font.size'] = 8def plot_img_and_hist(image, axes, bins=256):"""Plot an image along with its histogram and cumulative histogram."""image = img_as_float(image)ax_img, ax_hist = axes# 共⽤x轴ax_cdf = ax_hist.twinx()# Display imageax_img.imshow(image, cmap=plt.cm.gray)ax_img.set_axis_off()# Display histogramax_hist.hist(image.ravel(), bins=bins, histtype='step', color='black')ax_hist.ticklabel_format(axis='y', style='scientific', scilimits=(0, 0))ax_hist.set_xlabel('Pixel intensity')ax_hist.set_xlim(0, 1)ax_hist.set_yticks([])# Display cumulative distributionimg_cdf, bins = exposure.cumulative_distribution(image, bins)ax_cdf.plot(bins, img_cdf, 'r')# 设置右侧坐标轴为空ax_cdf.set_yticks([])return ax_img, ax_hist, ax_cdf# Load an example imageimg = data.moon()# Contrast stretchingp2, p98 = np.percentile(img, (2, 98))img_rescale = exposure.rescale_intensity(img, in_range=(p2, p98))# Equalizationimg_eq = exposure.equalize_hist(img)# Adaptive Equalization# 参数2:Clipping limit, normalized between 0 and 1 (higher values give more contrast). img_adapteq = exposure.equalize_adapthist(img, clip_limit=0.03)# Display resultsfig = plt.figure(figsize=(8, 5))axes = np.zeros((2, 4), dtype=np.object)axes[0, 0] = fig.add_subplot(2, 4, 1)for i in range(1, 4):axes[0, i] = fig.add_subplot(2, 4, 1+i, sharex=axes[0,0], sharey=axes[0,0])for i in range(0, 4):axes[1, i] = fig.add_subplot(2, 4, 5+i)ax_img, ax_hist, ax_cdf = plot_img_and_hist(img, axes[:, 0])ax_img.set_title('Low contrast image')y_min, y_max = ax_hist.get_ylim()ax_hist.set_ylabel('Number of pixels')# 左侧y轴范围为0到y_max,5个刻度ax_hist.set_yticks(np.linspace(0, y_max, 5))ax_img, ax_hist, ax_cdf = plot_img_and_hist(img_rescale, axes[:, 1])ax_img.set_title('Contrast stretching')ax_img, ax_hist, ax_cdf = plot_img_and_hist(img_eq, axes[:, 2])ax_img.set_title('Histogram equalization')ax_img, ax_hist, ax_cdf = plot_img_and_hist(img_adapteq, axes[:, 3])ax_img.set_title('Adaptive equalization')ax_cdf.set_ylabel('Fraction of total intensity')# 右侧y轴范围为0到1,5个刻度ax_cdf.set_yticks(np.linspace(0, 1, 5))# prevent overlap of y-axis labelsfig.tight_layout()plt.show()。
增强图像对比度的方法

增强图像对比度的方法增强图像对比度是指通过一系列图像处理操作,使图像中不同区域的亮度值之间的差异更加明显,以提高图像的视觉效果和可读性。
下面是一些常用的增强图像对比度的方法:1. 直方图均衡化:直方图均衡化是一种常见的增强图像对比度的方法。
它通过调整图像的灰度值分布,使得图像中各个灰度级别的像素点分布更加均匀,从而增强图像的对比度。
具体步骤如下:(1)计算图像的直方图,统计每个灰度级别的像素个数。
(2)计算累积直方图,即将每个灰度级别的像素个数累积起来,得到累积灰度级个数。
(3)根据累积直方图和原始图像的灰度级别,计算调整后的灰度级别,并将其应用到原始图像上,得到均衡化后的图像。
直方图均衡化可以有效增强图像的对比度,但有时也会导致细节丢失和噪声增加。
2. 自适应直方图均衡化:自适应直方图均衡化是对传统直方图均衡化的改进方法。
传统直方图均衡化是对整个图像进行处理,很难同时对亮度变化较大的区域和亮度变化较小的区域进行适当的增强。
自适应直方图均衡化则将图像分成许多小的区域,并对每个区域分别进行直方图均衡化,从而提高了增强效果。
具体步骤如下:(1)将图像划分成小的区域。
(2)对每个区域进行直方图均衡化。
(3)将均衡化后的区域拼接起来,得到增强后的图像。
自适应直方图均衡化可以在增强图像对比度的同时,保留图像的细节信息。
3. 对比度拉伸:对比度拉伸是一种简单有效的增强图像对比度的方法。
它通过对图像的像素值进行线性拉伸,将原始图像中像素值的范围映射到新的范围之内,从而增强图像的对比度。
具体步骤如下:(1)计算原始图像中的最小像素值和最大像素值。
(2)通过线性映射将原始图像中的像素值范围映射到新的范围之内。
对比度拉伸可以简单快速地增强图像的对比度,但有时会导致图像的灰度失去平衡,使得整体图像过亮或过暗。
4. 线性拉伸:线性拉伸是对比度拉伸的一种改进方法。
它通过定义一个合适的斜率和截距,将原始图像的像素值进行线性转换,从而增强图像的对比度。
histeq函数

histeq函数在数字图像处理中,直方图均衡(histogram equalization)是一种图像增强技术,常常用于增强清晰度和对比度。
它的核心是一个函数,即histeq函数。
这个函数的作用是对一幅图像进行直方图均衡化,使得图像像素灰度值分布更加均匀,有效地提高了图像质量。
histeq函数的实现可以分为两类:全局直方图均衡化和自适应直方图均衡化。
全局直方图均衡化全局直方图均衡化是在整幅图像基础上进行均衡化处理的。
该算法在处理过程中没有考虑图片的局部特性,因此结果仅仅是对图像的全局增强。
其具体步骤如下:1. 统计图像中每个灰度级的像素个数,得到原始直方图。
2. 对原始直方图进行归一化处理,得到累计直方图。
3. 根据累计直方图调整图像亮度,得到均衡化后的图像。
自适应直方图均衡化自适应直方图均衡化是一种更高级的直方图均衡化算法,该算法考虑了图像的局部特性,在每个区域内计算直方图并进行均衡化处理。
自适应直方图均衡化算法的具体步骤如下:1. 将原始图像分成若干个不重叠的小区域。
2. 在每个小区域中分别计算原始直方图,并根据累计直方图对像素强度进行调整得到均衡化后的图像。
3. 将每个小区域的像素重新组合成最终图像。
自适应直方图均衡化算法比全局直方图均衡化更加适应图像局部特性,相较而言,其对于被曝光不均匀的照片应用更为有效。
在使用histeq函数进行图像增强时,需要注意以下几点:1. 均衡化会增加图像的对比度,但风景照片等具有自然纹理的图像可能会受到影响。
2. 过度增强可能会造成过曝,使得图片看起来偏白或失真。
3. histeq函数处理的图像中可能出现灰度级过多或太少的情况。
总结histeq函数是一种图像增强的关键算法,它通过直方图均衡化的方式对图像进行有效的处理,增强了图像的清晰度和对比度,提高了图像质量。
在使用过程中,需要根据实际情况选择不同的算法,并注意控制增强的程度以避免对图像造成过度损害。
自适应直方图均衡化三

自适应直方图均衡化三function out = adathisteq(varargin)%ADATHISTEQ Contrast-limited Adative Histogram Equalization (CLAHE). % ADATHISTEQ enhances the contrast of images by transforming the % values in the intensity image I. Unlike HISTEQ, it oerates on small % data regions (tiles), rather than the entire image. Each tile's % contrast is enhanced, so that the histogram of the outut region % aroximately matches the secified histogram. The neighboring tiles % are then combined using bilinear interolation in order to eliminate % artificially induced boundaries. The contrast, esecially% in homogeneous areas, can be limited in order to avoid amlifying the % noise which might be resent in the image.%% J = ADATHISTEQ(I) erforms CLAHE on the intensity image I. %% J = ADATHISTEQ(I,ARAM1,VAL1,ARAM2,VAL2...) sets various arameters. % arameter names can be abbreviated, and case does not matter. Each % string arameter is followed by a value as indicated below:%% 'NumTiles' Two-element vector of ositive integers:[M N]. % [M N] secifies the number of tile rowsand % columns. Both M and N must be at least2. % The total number of image tiles is equal toM*N. %% Default: [8 8].%% 'CliLimit' Real scalar from 0 to 1.% 'CliLimit' limits contrast enhancement. Higher numbers% result in more contrast.%% Default: 0.01.%% 'NBins' ositive integer scalar.% Sets number of bins for the histogram used in building a % contrast enhancing transformation. Higher values result % in greater dynamic range at the cost of slower rocessing % seed.%% Default: 256.%% 'Range' One of the strings: 'original'or 'full'.% Controls the range of the outut image data. If'Range'% is set to 'original', the range is limited to % [min(I(:)) max(I(:))]. Otherwise, by default, or when% 'Range' is set to 'full', the full range of the outut% image class is used (e.g. [0 255] for uint8).%% Default: 'full'.%% 'Distribution' Distribution can be one of three strings:'uniform',% 'rayleigh', 'exonential'.% Sets desired histogram shae for the image tiles, by % secifying a distribution tye.%% Default: 'uniform'.%% 'Alha' Nonnegative real scalar.% 'Alha' is a distribution arameter, whichcan be sulied% when 'Dist' is set to either'rayleigh' or 'exonential'.%% Default: 0.4.%% Notes% -----% - 'NumTiles' secify the number of rectangular contextual regions (tiles)% into which the image is divided. The contrast transform function is % calculated for each of these regions individually. The otimal number of % tiles deends on the tye of the inut image, and it is best determined % through exerimentation.%% - The 'CliLimit' is a contrast factor that reventsover-saturation of the % image secifically in homogeneous areas. These areas are characterized% by a high eak in the histogram of the articular image tile due to many % ixels falling inside the same gray level range. Without the cli limit,% the adative histogram equalization technique could roduceresults that, % in some cases, are worse than the original image.%% - ADATHISTEQ can use Uniform, Rayleigh, or Exonential distribution as % the basis for creating the contrast transform function. The distribution % that should be used deends on the tye of the inut image.% For examle, underwater imagery aears to look more natural when the % Rayleigh distribution is used.%% Class Suort% -------------% Intensity image I can be uint8, uint16, int16, double, or single.% The outut image J has the same class as I.%% Examle 1% ---------% Aly Contrast-Limited Adative Histogram Equalization to an% image and dislay the results.%% I = imread('tire.tif');% A =adathisteq(I,'cliLimit',0.02,'Distribution','rayleigh'); % figure, imshow(I);% figure, imshow(A);%% Examle 2% ---------%% Aly Contrast-Limited Adative Histogram Equalization to a color% hotograh.%% [X MA] = imread('shadow.tif');% RGB = ind2rgb(X,MA); % convert indexed image to truecolor format % cform2lab = makecform('srgb2lab');% LAB = alycform(RGB, cform2lab); %convert image to L*a*b color sace % L = LAB(:,:,1)/100; % scale the values to range from 0 to 1 % LAB(:,:,1) = adathisteq(L,'NumTiles',[88],'CliLimit',0.005)*100;% cform2srgb = makecform('lab2srgb');% J = alycform(LAB, cform2srgb); %convert back to RGB% figure, imshow(RGB); %dislay the results% figure, imshow(J);%% See also HISTEQ.% Coyright 1993-2010 The MathWorks, Inc.% $Revision: 1.1.6.12 $ $Date: 2011/08/09 17:48:54 $% References:% Karel Zuiderveld, "Contrast Limited Adative Histogram Equalization",% Grahics Gems IV, . 474-485, code: . 479-484%% Hanumant Singh, Woods Hole Oceanograhic Institution, ersonal % communication%--------------------------- The algorithm ----------------------------------%% 1. Obtain all the inuts:% * image% * number of regions inrow and column directions% * number of bins for the histograms used in building image transform % function (dynamic range)% * cli limit for contrast limiting (normalized from 0 to 1)% * other miscellaneous otions% 2. re-rocess the inuts:% * determine real cli limit from the normalized value% * if necessary, ad the image before slitting it into regions% 3. rocess each contextual region (tile) thus roducing gray level maings % * extract a single image region% * make a histogram for this region using the secified number of bins % * cli the histogram using cli limit% * create a maing (transformation function) for this region% 4. Interolate gray level maings in order to assemble final CLAHE image % * extract cluster of four neighboring maing functions % * rocess image region artly overlaing each of the maing tiles% * extract a single ixel, aly four maings to that ixel, and% interolate between the results to obtain the outut ixel; reeat% over the entire image%% See code for further details.%%-----------------------------------------------------------------------------[I, selectedRange, fullRange, numTiles, dimTile, cliLimit, numBins, ... noadRect, distribution, alha, int16ClassChange] = arseInuts(varargin{:});tileMaings = makeTileMaings(I, numTiles, dimTile, numBins, cliLimit, ... selectedRange, fullRange, distribution, alha);%Synthesize the outut image based on the individual tile maings.out = makeClaheImage(I, tileMaings, numTiles, selectedRange, numBins,... dimTile);if int16ClassChange% Change uint16 back to int16 so outut has same class as inut. out = uint16toint16(out);endif ~isemty(noadRect) %do we need to remove adding?out = out(noadRect.ulRow:noadRect.lrRow, ...noadRect.ulCol:noadRect.lrCol);end%-----------------------------------------------------------------------------function tileMaings = ...makeTileMaings(I, numTiles, dimTile, numBins, cliLimit,...selectedRange, fullRange, distribution, alha)numixInTile = rod(dimTile);tileMaings = cell(numTiles);% extract and rocess each tileimgCol = 1;for col=1:numTiles(2),imgRow = 1;for row=1:numTiles(1),tile = I(imgRow:imgRow+dimTile(1)-1,imgCol:imgCol+dimTile(2)-1);% for seed, call MEX file directly thus avoiding costly% inut arsing of imhisttileHist = imhistc(tile, numBins, 1, fullRange(2));tileHist = cliHistogram(tileHist, cliLimit, numBins);tileMaing = makeMaing(tileHist, selectedRange, fullRange, ...numixInTile, distribution, alha);% assemble individual tile maings by storing them in a cell array;tileMaings{row,col} = tileMaing;imgRow = imgRow + dimTile(1);endimgCol = imgCol + dimTile(2); % move to the next column of tilesend%-----------------------------------------------------------------------------% Calculate the equalized looku table (maing) based on cumulating the inut % histogram. Note: looku table is rescaled in the selectedRange [Min..Max].function maing = makeMaing(imgHist, selectedRange, fullRange, ... numixInTile, distribution, alha)histSum = cumsum(imgHist);valSread = selectedRange(2) - selectedRange(1);switch distributioncase 'uniform',scale = valSread/numixInTile;maing = min(selectedRange(1) + histSum*scale,...selectedRange(2)); %limit to maxcase 'rayleigh', % suitable for underwater imagery% df = (t./alha^2).*ex(-t.^2/(2*alha^2))*U(t)% cdf = 1-ex(-t.^2./(2*alha^2))hconst = 2*alha^2;vmax = 1 - ex(-1/hconst);val = vmax*(histSum/numixInTile);val(val>=1) = 1-es; % avoid log(0)tem = sqrt(-hconst*log(1-val));maing = min(selectedRange(1)+tem*valSread,...selectedRange(2)); %limit to maxcase 'exonential',% df = alha*ex(-alha*t)*U(t)% cdf = 1-ex(-alha*t)vmax = 1 - ex(-alha);val = (vmax*histSum/numixInTile);val(val>=1) = 1-es;tem = -1/alha*log(1-val);maing = min(selectedRange(1)+tem*valSread,selectedRange(2)); otherwise,error(message('images:adathisteq:distributionTye')) %shouldnever get hereend%rescale the result to be between 0 and 1 for later use by the GRAYXFORM %rivate mex functionmaing = maing/fullRange(2);%-----------------------------------------------------------------------------% This function clis the histogram according to the cliLimit and % redistributes clied ixels across bins below the cliLimitfunction imgHist = cliHistogram(imgHist, cliLimit, numBins)% total number of ixels overflowing cli limit in each bintotalExcess = sum(max(imgHist - cliLimit,0));% cli the histogram and redistribute the excess ixels in each bin avgBinIncr = floor(totalExcess/numBins);uerLimit = cliLimit - avgBinIncr; % bins larger than this will be % set to cliLimit% this loo should seed u the oeration by utting multile ixels% into the "obvious" laces firstfor k=1:numBinsif imgHist(k) > cliLimitimgHist(k) = cliLimit;elseif imgHist(k) > uerLimit % high bin counttotalExcess = totalExcess - (cliLimit - imgHist(k));imgHist(k) = cliLimit;elsetotalExcess = totalExcess - avgBinIncr;imgHist(k) = imgHist(k) + avgBinIncr;endendend% this loos redistributes the remaining ixels, one ixel at a time k = 1;while (totalExcess ~= 0)%kee increasing the ste as fewer and fewer ixels remain for%the redistribution (sread them evenly)steSize = max(floor(numBins/totalExcess),1);for m=k:steSize:numBinsif imgHist(m) < cliLimitimgHist(m) = imgHist(m)+1;totalExcess = totalExcess - 1; %reduce excessif totalExcess == 0break;endendendk = k+1; %revent from always lacing the ixels in bin #1if k > numBins % start over if numBins was reachedk = 1;endend%-----------------------------------------------------------------------------% This function interolates between neighboring tile maings to roduce a % new maing in order to remove artificially induced tile borders.% Otherwise, these borders would become quite visible. The resulting % maing is alied to the inut image thus roducing a CLAHE rocessed % image.function claheI = makeClaheImage(I, tileMaings, numTiles, selectedRange,... numBins, dimTile)%initialize the outut image to zeros (reserve the class of the inut image) claheI = I;claheI(:) = 0;%comute the LUT for looking u original image values in the tile maings, %which we created earlierif ~(isa(I,'double') || isa(I,'single'))k = selectedRange(1)+1 : selectedRange(2)+1;aLut = zeros(length(k),1);aLut(k) = (k-1)-selectedRange(1);aLut = aLut/(selectedRange(2)-selectedRange(1));else% rema from 0..1 to 0..numBins-1if numBins ~= 1binSte = 1/(numBins-1);start = ceil(selectedRange(1)/binSte);sto = floor(selectedRange(2)/binSte);k = start+1:sto+1;aLut(k) = 0:1/(length(k)-1):1;elseaLut(1) = 0; %in case someone secifies numBins = 1, which is just silly endendimgTileRow=1;for k=1:numTiles(1)+1if k == 1 %secial case: to rowimgTileNumRows = dimTile(1)/2; %always divisible by 2 because of adding maTileRows = [1 1];elseif k == numTiles(1)+1 %secial case: bottom rowimgTileNumRows = dimTile(1)/2;maTileRows = [numTiles(1) numTiles(1)];else %default valuesimgTileNumRows = dimTile(1);maTileRows = [k-1, k]; %[uerRow lowerRow] endend% loo over columns of the tileMaings cell array imgTileCol=1;for l=1:numTiles(2)+1if l == 1 %secial case: left column imgTileNumCols = dimTile(2)/2;maTileCols = [1, 1];elseif l == numTiles(2)+1 % secial case: right column imgTileNumCols = dimTile(2)/2;maTileCols = [numTiles(2), numTiles(2)];else %default valuesimgTileNumCols = dimTile(2);maTileCols = [l-1, l]; % right leftendend% Extract four tile maingsulMaTile = tileMaings{maTileRows(1), maTileCols(1)};urMaTile = tileMaings{maTileRows(1), maTileCols(2)};blMaTile = tileMaings{maTileRows(2), maTileCols(1)};brMaTile = tileMaings{maTileRows(2), maTileCols(2)};% Calculate the new greylevel assignments of ixels% within a submatrix of the image secified by imgTileIdx. This % is done by a bilinear interolation between four different maings % in order to eliminate boundary artifacts.normFactor = imgTileNumRows*imgTileNumCols; %normalization factor imgTileIdx = {imgTileRow:imgTileRow+imgTileNumRows-1, ...imgTileCol:imgTileCol+imgTileNumCols-1};imgixVals = grayxform(I(imgTileIdx{1},imgTileIdx{2}), aLut);% calculate the weights used for linear interolation between the % four maingsrowW = remat((0:imgTileNumRows-1)',1,imgTileNumCols); colW = remat(0:imgTileNumCols-1,imgTileNumRows,1);rowRevW = remat((imgTileNumRows:-1:1)',1,imgTileNumCols); colRevW = remat(imgTileNumCols:-1:1,imgTileNumRows,1);claheI(imgTileIdx{1}, imgTileIdx{2}) = ...(rowRevW .* (colRevW .* double(grayxform(imgixVals,ulMaTile)) + ... colW .* double(grayxform(imgixVals,urMaTile)))+ ...rowW .* (colRevW .* double(grayxform(imgixVals,blMaTile)) + ... colW .* double(grayxform(imgixVals,brMaTile)))).../normFactor;imgTileCol = imgTileCol + imgTileNumCols;end %over tile colsimgTileRow = imgTileRow + imgTileNumRows;end %over tile rows%-----------------------------------------------------------------------------function [I, selectedRange, fullRange, numTiles, dimTile, cliLimit,...numBins, noadRect, distribution, alha, ...int16ClassChange] = arseInuts(varargin)narginchk(1,13);I = varargin{1};validateattributes(I, {'uint8', 'uint16','double', 'int16', 'single'}, ...{'real', '2d', 'nonsarse','nonemty'}, ... mfilename, 'I', 1);% convert int16 to uint16if isa(I,'int16')I = int16touint16(I);int16ClassChange = true;elseint16ClassChange = false;endif any(size(I) < 2)error(message('images:adathisteq:inutImageT ooSmall')) end%Other otions%%%%%%%%%%%%%%%Set the defaultsdistribution = 'uniform';alha = 0.4;if isa(I, 'double') || isa(I,'single')fullRange = [0 1];elsefullRange(1) = I(1); %coy class of the inut image fullRange(1:2) = [-Inf Inf]; %will be clied to min and max fullRange = double(fullRange);endselectedRange = fullRange;%Set the default to 256 bins regardless of the data tye;%the user can override this value at any timenumBins = 256;normCliLimit = 0.01;numTiles = [8 8];checkAlha = false;validStrings ={'NumTiles','CliLimit','NBins','Distributio n',...'Alha','Range'};if nargin > 1done = false;idx = 2;while ~doneinut = varargin{idx};inutStr = validatestring(inut,validStrings,mfilename,'ARAM',idx);idx = idx+1; %advance index to oint to the VAL ortion of the inutif idx > narginerror(message('images:adathisteq:missingValue', inutStr))endswitch inutStrcase 'NumTiles'numTiles = varargin{idx};validateattributes(numTiles, {'double'}, {'real','vector', ...'integer', 'finite','ositive'},...mfilename, inutStr, idx);if (any(size(numTiles) ~= [1,2]))error(message('images:adathisteq:invalidNumTilesVector', inutStr)) endif any(numTiles < 2)error(message('images:adathisteq:invalidNumTilesValue', inutStr)) endcase 'CliLimit'normCliLimit = varargin{idx};validateattributes(normCliLimit, {'double'}, ...{'scalar','real','nonnegative'},...mfilename, inutStr, idx);if normCliLimit > 1error(message('images:adathisteq:invalidCliLimit', inutStr)) endcase 'NBins'numBins = varargin{idx};validateattributes(numBins, {'double'},{'scalar','real','integer',...'ositive'}, mfilename, 'NBins', idx);case 'Distribution'validDist ={'rayleigh','exonential','uniform'}; distribution = validatestring(varargin{idx}, validDist, mfilename,...'Distribution', idx);case 'Alha'alha = varargin{idx};validateattributes(alha,{'double'},{'scalar','real',...'nonnan','ositive','finite'},...mfilename, 'Alha',idx);checkAlha = true;case 'Range'validRangeStrings = {'original','full'};rangeStr = validatestring(varargin{idx}, validRangeStrings,mfilename,...'Range',idx);if strmatch(rangeStr,'original')selectedRange = double([min(I(:)), max(I(:))]);endotherwiseerror(message('images:adathisteq:inutString')) %should never get here endif idx >= nargindone = true;endidx=idx+1;endend%% re-rocess the inuts%%%%%%%%%%%%%%%%%%%%%%%%%%dimI = size(I);dimTile = dimI ./ numTiles;%check if tile size is reasonableif any(dimTile < 1)error(message('images:adathisteq:inutImageT ooSmallT oSlit', num2str( numTiles )))endif checkAlhaif strcm(distribution,'uniform')error(message('images:adathisteq:alhaShouldNotBeSecified', distribution))endend%check if the image needs to be added; ad if necessary;%adding occurs if any dimension of a single tile is an odd number%and/or when image dimensions are not divisible by the selected%number of tilesrowDiv = mod(dimI(1),numTiles(1)) == 0;colDiv = mod(dimI(2),numTiles(2)) == 0;if rowDiv &am;&am; colDivrowEven = mod(dimTile(1),2) == 0;colEven = mod(dimTile(2),2) == 0;endnoadRect = [];if ~(rowDiv &am;&am; colDiv &am;&am; rowEven &am;&am; colEven) adRow = 0;adCol = 0;if ~rowDivrowTileDim = floor(dimI(1)/numTiles(1)) + 1;adRow = rowTileDim*numTiles(1) - dimI(1);elserowTileDim = dimI(1)/numTiles(1);endif ~colDivcolTileDim = floor(dimI(2)/numTiles(2)) + 1;adCol = colTileDim*numTiles(2) - dimI(2);elsecolTileDim = dimI(2)/numTiles(2);end%check if tile dimensions are even numbersrowEven = mod(rowTileDim,2) == 0;colEven = mod(colTileDim,2) == 0;if ~rowEvenadRow = adRow+numTiles(1);endif ~colEvenadCol = adCol+numTiles(2);endadRowre = floor(adRow/2);adRowost = ceil(adRow/2);adColre = floor(adCol/2);adColost = ceil(adCol/2);I = adarray(I,[adRowre adColre ],'symmetric','re');I = adarray(I,[adRowost adColost],'symmetric','ost');%UL corner (Row, Col), LR corner (Row, Col)noadRect.ulRow = adRowre+1;noadRect.ulCol = adColre+1;noadRect.lrRow = adRowre+dimI(1);noadRect.lrCol = adColre+dimI(2);end%redefine this variable to include the addingdimI = size(I);%size of the single tiledimTile = dimI ./ numTiles;%comute actual cli limit from the normalized value entered by theuser %maximum value of normCliLimit=1 results in standard AHE, i.e. no cliing; %the minimum value minCliLimit would uniformly distribute the image ixels %across the entire histogram, which would result in the lowest ossible %contrast valuenumixInTile = rod(dimTile);minCliLimit = ceil(numixInTile/numBins);cliLimit = minCliLimit + round(normCliLimit*(numixInTile-minCliLimit));%-----------------------------------------------------------------------------。
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
% in homogeneous areas, can be limited in order to avoid amplifying the
% noise which might be present in the image.
% when 'Dist' is set to either 'rayleigh' or 'exponential'.
%
% Default: 0.4.
%
% Notes
% -----
% - 'NumTiles' specify the number of rectangular contextual regions (tiles)
%
% Class Support
% -------------
% Intensity image I can be uint8, uint16, int16, double, or single.
% The output image J has the same class as I.
% that should be used depends on the type of the input image.
% For example, underwater imagery appears to look more natural when the
% Rayleigh distribution is used.
% cform2lab = makecform('srgb2lab');
% LAB = applycform(RGB, cform2lab); %convert image to L*a*b color space
% L = LAB(:,:,1)/100; % scale the values to range from 0 to 1
% pixels falling inside the same gray level range. Without the clip limit,
% the adaptive histogram equalization technique could produce results that,
% 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
%
% Example 1
% ---------
% Apply Contrast-Limited Adaptive Histogram Equalization to an
% image and display the results.
%
% I = imread('tire.tif');
function out = adapthisteq(varargin)
%ADAPTHISTEQ Contrast-limited Adaptive Histogram Equalization (CLAHE).
% ADAPTHISTEQ enhances the contrast of images by transforming the
% result in more contrast.
%
% Default: 0.01.
%
% 'NBins' Positive integer scalar.
% Sets number of bins for the histogram used in building a
% contrast enhancing transformation. Higher values result
% in greater dynamic range at the cost of slower processing
%
% Default: 'uniform'.
%
% 'Alpha' Nonnegative real scalar.
% 'Alpha' is a distribution parameter, which can be supplied
%
% Apply Contrast-Limited Adaptive Histogram Equalization to a color
% photograph.
%
% [X MAP] = imread('shadow.tif');
% RGB = ind2rgb(X,MAP); % convert indexed image to truecolor format
% approximately matches the specified histogram. The neighboring tiles
% are then combined using bilinear interpolation in order to eliminate
% A = adapthisteq(I,'clipLimit',0.02,'Distribution','rayleigh');
% figure, imshow(I);
% figure, imshow(A);
%
% Example 2
% ---------
%
% J = ADAPTHISTEQ(I) Performs CLAHE on the intensity image I.
%
% J = ADAPTHISTEQ(I,PARAM1,VAL1,PARAM2,VAL2...) sets various parameters.
% tiles depends on the type of the input image, and it is best determined
% through experimentation.
%
% - The 'ClipLimit' is a contrast factor that prevents over-saturation of the
% image class is used (e.g. [0 255] for uint8).
%
% Default: 'full'.
%
% 'Distribution' Distribution can be one of three strings: 'uniform',
% Parameter names can be abbreviated, and case does not matter. Each
% string parameter is followed by a value as indicated below:
%
% 'NumTiles' Two-element vector of positive integers: [M N].
% is set to 'original', the range is limited to
% [min(I(:)) max(I(:))]. Otherwise, by default, or when
% 'Range' is set to 'full', the full range of the output
% 'rayleigh', 'exponential'.
% Sets desired histogram shape for the image tiles, by
% specifying a distribution type.
% speed.
%
% De39;Range' One of the strings: 'original' or 'full'.
% Controls the range of the output image data. If 'Range'
% into which the image is divided. The contrast transform function is
% calculated for each of these regions individually. The optimal number of
% in some cases, are worse than the original image.
%
% - ADAPTHISTEQ can use Uniform, Rayleigh, or Exponential distribution as
% the basis for creating the contrast transform function. The distribution