I am trying to work on a code for increasing the contrast on grayscale images to make them clearer. I can't seem to get this code to work. I am trying to get the distribution frequency of each value (without using any modules aside from cv2) in the pixel and get the cumulative distribution frequency so I can then change the value using the equation below. Any idea what is wrong with my code?
import cv2
img=cv2.imread(raw_input())
shape=img.shape
row=shape[0]
col=shape[1]
def df(img): #to make a histogram (count distribution frequency)
values=[]
occurances=[]
for i in range (len(img)):
for j in img[i]:
values.append(j)
if j in values:
count +=3
occurances.append(count)
return occurances
def cdf (img): #cumulative distribution frequency
values2=[]
for i in values:
j=0
i=i+j
j+1
values2.append(i)
return values2
def h(img): #equation for the new value of each pixel
h=((cdf(img)-1)/((row*col)-1))*255
return h
newimage=cv2.imwrite('a.png')
This is an example of what I'm trying to do.
Thank you in advance.