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()
我正在尝试对图像进行直方图均衡。当我运行程序时,既不显示输出图像也不显示错误。
谁能告诉我哪里出错了
答案 0 :(得分:0)
尝试:
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()