简体   繁体   中英

why no image is displayed on histogram equalization : python

 import numpy as np
 import cv2
 import scipy.misc, math
 from scipy.misc.pilutil import Image

while True:
  img = Image.open('img.jpg').convert(L)
  img1 = scipy.misc.fromimage(img)
  f1 = img1.flatten()
  hist,bins = np.histogram(img1, 256,[0,255])
  cdf = hist.cumsum
  cdf_m = np.ma.masked_equal(cdf,0)
  cdf_m = (cdf_m - cdf_m.min())*255/(cdf_m.max()-cdf_m.min())
  cdf = np.ma.filled(cdf_m,0)
  im2 = cdf[f1]
  im3 = np.reshape(im2,img1.shape)
  im4 = scipy.misc.toimage(img3)
  im4.show()

I am trying to histogram equalize an image. When i run the program, neither an output image is displayed nor an error is shown.

Can anyone tell me where am going wrong

Try:

import numpy as np
import cv2
import scipy.misc, math
from scipy.misc.pilutil import Image

while True:
  img = Image.open('img.jpg').convert(L)
  img1 = scipy.misc.fromimage(img)
  f1 = img1.flatten()
  hist,bins = np.histogram(img1, 256,[0,255])
  cdf = hist.cumsum
  cdf_m = np.ma.masked_equal(cdf,0)
  cdf_m = (cdf_m - cdf_m.min())*255/(cdf_m.max()-cdf_m.min())
  cdf = np.ma.filled(cdf_m,0)
  im2 = cdf[f1]
  im3 = np.reshape(im2,img1.shape)
  im4 = scipy.misc.toimage(im3)
  im4.format = "PNG" # out of paranoia mainly
  im4.show()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM