【问题标题】:histogram equalization skimage直方图均衡skimage
【发布时间】:2017-11-05 09:36:06
【问题描述】:

我试图从一些图像中获取一些静态数据,当我尝试执行直方图均衡时,我感到困惑。

因为我试过这个:

img = io.imread(file);
img = exposure.equalize_hist(img);

我收到警告warn("This might be a color image. The histogram will be "

然后我尝试像这样在每个通道中执行均衡:

img = io.imread(file);
#img = exposure.equalize_hist(img);    
height, width = len(img), len(img[0]);
r1 = [];
g1 = [];
b1 = [];
for i in range(height):
    for j in range(width): 
        pixel = img[i, j];
        r1.append(pixel[0]);
        g1.append(pixel[1]);
        b1.append(pixel[2]);    
r = exposure.equalize_hist(r1);        
g = exposure.equalize_hist(g1);
b = exposure.equalize_hist(b1);

我得到了错误

AttributeError: 'list' object has no attribute 'shape'

那么我应该如何在带有颜色的图像中进行直方图均衡,如果我想在 HSV 或 CIELAB 中的图像中进行,是不是也一样?! histogram equalization

【问题讨论】:

    标签: python image-processing rgb scikit-image


    【解决方案1】:

    分别均衡每个通道:

    from skimage import io, exposure
    
    
    img = io.imread(img_path)
    
    for channel in range(img.shape[2]):  # equalizing each channel
        img[:, :, channel] = exposure.equalize_hist(img[:, :, channel])
    

    这是因为img[:, :, channel] 已经为您提供了equalize_hist 支持的二维图像数组,因此您无需创建三个列表(顺便说一下,这可能效率很低)。该代码假设您确实有一个图像(3d 数组),其通道在最后一维上(如果您使用 skimage.io.imread 加载它就是这种情况)。

    此外,它应该与 RGB、实验室的 HSV 相同(skimage 转换将保持通道在最后一个维度上)。例如img = color.rgb2hsv(img)img = color.rgb2lab(img)

    如果您加载灰度图像(已经是二维数组),那么您的注释行应该可以工作(您可以使用简单的 if 条件处理这两种情况)。

    只是别的:你可以去掉分号。

    【讨论】:

    • 我想我得到了,但现在我在 img 上得到了奇怪的值,在 img[0] 之前我有 [[179 138 172] [179 136 164] ..., [168 105 134] [ 173 112 143]],现在我得到了全零:[[0 0 0] [0 0 0] [0 0 0] ...,[0 0 0] [0 0 0] [0 0 0]]。对吗?
    • 或许,最好转成HSV,在V通道上操作。此外,在保留数据方面,重新调整强度通常比直方图均衡更好。
    猜你喜欢
    • 1970-01-01
    • 2017-05-17
    • 1970-01-01
    • 2020-11-01
    • 2013-12-03
    • 2016-11-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多