非常教程

Scikit image参考手册

显露 | exposure

exposure

skimage.exposure.adjust_gamma(image, …)

Performs Gamma Correction on the input image.

skimage.exposure.adjust_log(image, gain, inv)

Performs Logarithmic correction on the input image.

skimage.exposure.adjust_sigmoid(image, …)

Performs Sigmoid Correction on the input image.

skimage.exposure.cumulative_distribution(image)

Return cumulative distribution function (cdf) for the given image.

skimage.exposure.equalize_adapthist(image, …)

Contrast Limited Adaptive Histogram Equalization (CLAHE).

skimage.exposure.equalize_hist(image, …)

Return image after histogram equalization.

skimage.exposure.histogram(image, nbins)

Return histogram of image.

skimage.exposure.is_low_contrast(image, …)

Detemine if an image is low contrast.

skimage.exposure.rescale_intensity(image, …)

Return image after stretching or shrinking its intensity levels.

skimage.exposure.exposure

adjust_gamma

skimage.exposure.adjust_gamma(image, gamma=1, gain=1)[source]

对输入图像执行Gamma校正。

也称为幂律变换。该函数在将O = I**gamma每个像素缩放到范围0到1之后根据等式按照像素方式转换输入图像。

参数:

图像:ndarray输入图像。gamma:float非负实数。默认值为1. gain:float恒定乘数。默认值是1。

返回:

出:ndarray Gamma校正输出图像。

另请参阅

adjust_log

注意

对于gamma大于1的情况,直方图会向左移动,输出图像会比输入图像更暗。

对于小于1的伽玛,直方图将向右移动,输出图像将比输入图像亮。

参考

R114

http://en.wikipedia.org/wiki/Gamma_correction

例子

>>> from skimage import data, exposure, img_as_float
>>> image = img_as_float(data.moon())
>>> gamma_corrected = exposure.adjust_gamma(image, 2)
>>> # Output is darker for gamma > 1
>>> image.mean() > gamma_corrected.mean()
True

adjust_log

skimage.exposure.adjust_log(image, gain=1, inv=False)[source]

对输入图像执行对数校正。

O = gain*log(1 + I)在将每个像素缩放到0到1范围之后,该函数按照公式将输入图像按像素方式进行变换。对于反对数校正,公式为O = gain*(2**I - 1)

参数:

图像:ndarray输入图像。增益:浮动恒定乘数。默认值为1. inv:float如果为True,则执行反对数校正,否则校正将为对数。默认为False。

返回:

out:对数对数校正后的输出图像。

另请参阅

adjust_gamma

参考

R115

http://www.ece.ucsb.edu/Faculty/Manjunath/courses/ece178W03/EnhancePart1.pdf

adjust_sigmoid

skimage.exposure.adjust_sigmoid(image, cutoff=0.5, gain=10, inv=False)[source]

对输入图像执行Sigmoid校正。

也称为对比度调整。该函数在将O = 1/(1 + exp*(gain*(cutoff - I)))每个像素缩放到范围0到1之后根据等式按照像素方式转换输入图像。

参数:

图像:ndarray输入图像。cutoff:float切断在水平方向上移动特性曲线的S形函数。默认值是0.5。gain:float S指数函数的指数函数中的常数乘数。默认值为10. inv:bool如果为True,则返回负S形修正。默认为False。

返回:

out:ndarray Sigmoid修正输出图像。

另请参阅

adjust_gamma

参考

R116

Gustav J. Braun, “Image Lightness Rescaling Using Sigmoidal Contrast Enhancement Functions”, http://www.cis.rit.edu/fairchild/PDFs/PAP07.pdf

cumulative_distribution

skimage.exposure.cumulative_distribution(image, nbins=256)[source]

返回给定图像的累积分布函数(cdf)。

参数:

图像:阵列图像数组。nbins:int图像直方图的bin数。

返回:

img_cdf:数组累积分布函数的值。bin_centers:数组中心。

另请参阅

histogram

参考

R117

http://en.wikipedia.org/wiki/Cumulative_distribution_function

例子

>>> from skimage import data, exposure, img_as_float
>>> image = img_as_float(data.camera())
>>> hi = exposure.histogram(image)
>>> cdf = exposure.cumulative_distribution(image)
>>> np.alltrue(cdf[0] == np.cumsum(hi[0])/float(image.size))
True

equalize_adapthist

skimage.exposure.equalize_adapthist(image, kernel_size=None, clip_limit=0.01, nbins=256, **kwargs)[source]

对比度有限自适应直方图均衡化(CLAHE)。

用于局部对比度增强的算法,其使用在图像的不同图块区域上计算的直方图。因此即使在比大多数图像更暗或更亮的区域,也可以增强局部细节。

参数:

图像:(M,N,C)ndarray输入图像。kernel_size:整数或类似列表,可选定义算法中使用的上下文区域的形状。如果传递了迭代,它必须具有与image.ndim相同数量的元素(不带颜色通道)。如果是整数,它会广播到每个图像尺寸。默认情况下,kernel_size是1/8宽度的图像高度的1/8。clip_limit:float,可选的剪切限制,在0和1之间进行归一化(较高的值可提供更大的对比度)。nbins:int,可选直方图(“数据范围”)的灰色区域数量。

返回:

out:(M,N,C)ndarray均衡图像。

另请参阅

equalize_hist, rescale_intensity

注意

  • 对于彩色图像,执行以下步骤:
    • 图像被转换为​​HSV色彩空间
    • CLAHE算法在V(Value)通道上运行
    • 图像被转换回RGB空间并返回
  • 对于RGBA图像,原始的alpha通道被删除。

参考

R118

http://tog.acm.org/resources/GraphicsGems/

R119

https://en.wikipedia.org/wiki/CLAHE#CLAHE

equalize_hist

skimage.exposure.equalize_hist(image, nbins=256, mask=None)[source]

在直方图均衡之后返回图像。

参数:

图像:阵列图像数组。nbins:int,可选图像直方图的bin数。注意:整数图像忽略此参数,每个整数都是它自己的bin。掩码:bools的ndarray或0和1s,可选与图像形状相同的阵列。只有使用mask == True的点才会用于均衡,这将应用于整个图像。

返回:

out:float数组直方图均衡之后的图像数组。

注意

此函数经作者许可从[R120]改编而来。

参考

R120

(1, 2) http://www.janeriksolem.net/2009/06/histogram-equalization-with-python-and.html

R121

http://en.wikipedia.org/wiki/Histogram_equalization

histogram

skimage.exposure.histogram(image, nbins=256)[source]

返回图像的直方图。

numpy.histogram此不同的是,这个函数返回仓的中心,并且不会重定整型数组。对于整数数组,每个整数值都有自己的bin,这可以提高速度和强度分辨率。

在平坦图像上计算直方图:对于彩色图像,应在每个通道上分别使用该函数以获得每个颜色通道的直方图。

参数:

image:数组输入图像。nbins:int用于计算直方图的bin数。整数数组被忽略。

返回:

hist:数组直方图的值。bin_centers:数组在容器中心的值。

另请参阅

cumulative_distribution

示例

>>> from skimage import data, exposure, img_as_float
>>> image = img_as_float(data.camera())
>>> np.histogram(image, bins=2)
(array([107432, 154712]), array([ 0. ,  0.5,  1. ]))
>>> exposure.histogram(image, nbins=2)
(array([107432, 154712]), array([ 0.25,  0.75]))

is_low_contrast

skimage.exposure.is_low_contrast(image, fraction_threshold=0.05, lower_percentile=1, upper_percentile=99, method='linear')[source]

确定图像是否低对比度。

参数:

image:像数组一样被测试的图像。fraction_threshold:float,可选低对比度分数阈值。当图像的亮度范围小于其数据类型的全部范围的这一部分时,图像被认为是低对比度。R122 lower_bound:float,可选在计算图像对比度时忽略低于此百分位数的值。upper_bound:float,可选当计算图像对比度时,忽略高于此百分位数的值。方法:str,可选对比度确定方法。目前唯一可用的选项是“线性”。

返回:

out:bool当图像被确定为低对比度时为真。

参考

R122

(1, 2) http://scikit-image.org/docs/dev/user_guide/data_types.html

例子

>>> image = np.linspace(0, 0.04, 100)
>>> is_low_contrast(image)
True
>>> image[-1] = 1
>>> is_low_contrast(image)
True
>>> is_low_contrast(image, upper_percentile=100)
False

rescale_intensity

skimage.exposure.rescale_intensity(image, in_range='image', out_range='dtype')[source]

在拉伸或收缩强度水平后返回图像。

的输入和输出,所述的所期望的强度范围in_rangeout_range分别用于拉伸或收缩的输入图像的强度范围。看下面的例子。

参数:

图像:阵列图像数组。in_range,out_range:str或2-tuple输入和输出图像的最小和最大亮度值。下面列举了这个参数的可能值。'image'使用图像最小/最大值作为强度范围。'dtype'使用图像的dtype的最小/最大值作为强度范围。dtype-name使用基于所需dtype的强度范围。在DTYPE_RANGE中必须是有效的密钥。2元组使用range_values作为明确的最小/最大强度。

返回:

out:重新调整其强度后重新排列Image阵列。该图像与输入图像是相同的dtype。

另请参阅

equalize_hist

例子

默认情况下,输入图像的最小/最大强度被拉伸到图像的dtype允许的限制,因为in_range默认为'image'并且out_range默认为'dtype':

>>> image = np.array([51, 102, 153], dtype=np.uint8)
>>> rescale_intensity(image)
array([  0, 127, 255], dtype=uint8)

意外地将图像dtype从uint8转换为float会很容易:

>>> 1.0 * image
array([  51.,  102.,  153.])

使用rescale_intensity重新调整到合适的范围浮法dtypes:

>>> image_float = 1.0 * image
>>> rescale_intensity(image_float)
array([ 0. ,  0.5,  1. ])

要保持原稿的低对比度,请使用in_range参数:

>>> rescale_intensity(image_float, in_range=(0, 255))
array([ 0.2,  0.4,  0.6])

如果最小/最大值in_range大于/小于最小/最大图像强度,则剪切强度级别:

>>> rescale_intensity(image_float, in_range=(0, 102))
array([ 0.5,  1. ,  1. ])

如果您有带有符号整数的图像,但想要将图像重新缩放到正范围,请使用out_range参数:

>>> image = np.array([-10, 0, 10], dtype=np.int8)
>>> rescale_intensity(image, out_range=(0, 127))
array([  0,  63, 127], dtype=int8)

显露 | exposure相关

Scikit image

Scikit-image 是用于图像处理的 Python 包,使用原生的 NumPy 数组作为图像对象。

主页 http://scikit-image.org/
源码 https://github.com/scikit-image/scikit-image
发布版本 0.13.1