Reputation: 129
So this is my code. The variable img is the original image. The variable eq is the equalized image.
from matplotlib.pyplot import imread, imshow, show, subplot, title, get_cmap, hist
from skimage.exposure import equalize_hist
img = imread('images/city.tif')
eq = equalize_hist(img)
subplot(221); imshow(img, cmap=get_cmap('gray')); title('Original')
subplot(222); hist(img.flatten(), 256, range=(0,256)); title('Histogram of origianl')
subplot(223); imshow(eq, cmap=get_cmap('gray')); title('Histogram Equalized')
subplot(224); hist(eq.flatten(), 256, range=(0,256));
show()
Now when I run, the code, I get the histogram of the original just fine. But the histogram of the equalized is incorrect. This is all of my output
What am I doing wrong ?!?!
EDIT: The builtin matlab commands from the answer works fine for the particular image
Upvotes: 0
Views: 5023
Reputation: 111856
It looks like it's converting the image from uint8
format (integer values between 0 and 255 inclusive) to a float32
or float64
format (floating point values between 0 and 1 inclusive). Try eq = np.asarray(equalize_hist(img) * 255, dtype='uint8')
.
Upvotes: 4