python - 无法均衡图像

标签 python numpy image-processing matplotlib scikit-image

我正在使用 Python 中的 skimage 库来增加图像的对比度。 我的图像采用 RGB 格式,位于名为 X_train 的列表中,其图像形状为:(32x32x3)。

首先,我将其转换为 [0, 1],然后从 RGB 转换为 HSV,然后使用库中的方法:

X_train = X_train/256
X_train_hsv = matplotlib.colors.rgb_to_hsv(X_train)
X_train_eq = skimage.exposure.equalize_adapthist(X_train_hsv, kernel_size=None,
                                                 clip_limit=0.01, nbins=256, )

问题是我收到此错误:

/home/carnd/anaconda3/envs/carnd-term1/lib/python3.5/site-packages/skimage/exposure/_adapthist.py in interpolate(image, xslice, yslice, mapLU, mapRU, mapLB, mapRB, lut)

        333                  int(xslice[0]):int(xslice[-1] + 1)]
        334     im_slice = lut[view]
    --> 335     new = ((y_inv_coef * (x_inv_coef * mapLU[im_slice]
        336                           + x_coef * mapRU[im_slice])
        337             + y_coef * (x_inv_coef * mapLB[im_slice]

ValueError: operands could not be broadcast together with shapes (2175,2) (2175,2,32,3)

有人知道我可能犯了什么错误吗?

最佳答案

根据scikit-image documentation ,您不需要将图像重新缩放为 0..1 并将其从 RGB 转换为 HSV:

Notes

  • For color images, the following steps are performed:

    • The image is converted to HSV color space
    • The CLAHE algorithm is run on the V (Value) channel
    • The image is converted back to RGB space and returned
  • For RGBA images, the original alpha channel is removed.

因此,当您使用关键字参数 kernel_sizeclip_limitnbins 的默认值时,您可以简单地编写:

X_train_eq = skimage.exposure.equalize_adapthist(X_train)

关于python - 无法均衡图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43566679/

相关文章:

python - 计算 numpy 数组中每个二维数组的平均值

访问数组某些部分的 Pythonic 方式

python - Numpy复杂的数据结构

python - python 上的直方图高斯拟合似乎不对。我可以改变什么来改善贴合度?

python - 使用 Python 库的多元多重回归

c# - 如何将常用图像格式保存到DICOM?

java - 使用 zxing 库读取多个条形码

python - 如何使用opencv填充整个内部轮廓

python3 - 就地编辑 YAML 文件中的值

python - 如何使用 Pycharm Community 运行功能文件