python 直方图均衡化_彩色图像直方图均衡化Python

我是Opencv的新人

我试着手工做直方图均衡化,不知怎么的我的输出是

this

首先,我将格式转换为YCR\u CB格式,然后将其拆分为y、cr和CB。然后我在y层做了直方图均衡化处理

我的代码是:from __future__ import division

import cv2

import numpy as np

img1 = cv2.imread("sup.jpg")

img2 = cv2.cvtColor(img1,cv2.COLOR_BGR2YCR_CB)

y,cr,cb = cv2.split(img2)

#y = cv2.equalizeHist(y)

x =y

height,width = y.shape

hist = [0]*256

pmf = [0]*256

cdf = [0]*256

levelBaru = [0]*256

cv2.imshow("y before",x)

cv2.waitKey(0)

for i in range(0,height):

for j in range(0,width):

hist[y.item(i,j)] += 1

#hist[y[i,j]] += 1

for i in range(0,256):

#cari pmf

pmf[i] = round(hist[i]/(height*width),4)

print "pmf done"

cdf[0]

你可能感兴趣的:(python,直方图均衡化)