我正在使用 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_size
、clip_limit
和 nbins
的默认值时,您可以简单地编写:
X_train_eq = skimage.exposure.equalize_adapthist(X_train)
关于python - 无法均衡图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43566679/