Search code examples
image-processingpython-imaging-libraryscikit-image

when equalizing images, skimage adds entropy and changes histogram when saving the images, how to preserve the equalized image?


I've got the following image:

And I'm doing the following

  • First I read an image img = skimage.io.imread('original.jpg') that has the following histogram:
    histogram from the original image
  • Then, after applying he_img = skimage.exposure.equalize_hist(a), I get the following histogram:
    equalized original image
  • but when I save, then load and see the histogram of that image I get the following:
    skimage.io.imsave(fname = 'he.jpg', arr= he_img)
    saved = skimage.io.imread('he.jpg')
    loaded image with HE

What else do I need to add to my process in order to being able to save the equalized image?


Solution

  • The problem with this was that I was using JPG. JPG uses lossy compression to save images, adding noise to the image affecting to the equalization and increassing the images entropy.

    To solve this I tried PNG that is a lossless compression format for storing images. The code for this is:

    img = skimage.io.imread('original.jpg')
    hist_equalized_img = skimage.exposure.equalize_hist(img)
    skimage.io.imsave(fname = 'he.png', arr= hist_equalized_img)