rachuism
rachuism

Reputation: 193

Cannot equalize images

I'm using the library skimage in Python for increasing the contrast of my images. My images are in RGB in a list called X_train whose image shape is: (32x32x3).

First I convert it to [0, 1], then from RGB to HSV and then I use the method from the library:

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, )

The thing is that I obtain this error:

/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)

Does anybody know what could be my mistake?

Upvotes: 2

Views: 463

Answers (1)

Tonechas
Tonechas

Reputation: 13733

According to scikit-image documentation, you don't need to rescale the images to 0..1 and convert them from RGB to 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.

So, as you are using the default values for keyword arguments kernel_size, clip_limit and nbins, you could simply write:

X_train_eq = skimage.exposure.equalize_adapthist(X_train)

Upvotes: 2

Related Questions