#https://www.youtube.com/watch?v=eNBZI-qYhpg
#https://www.math.uci.edu/icamp/courses/math77c/demos/hist_eq.pdf
#https://en.wikipedia.org/wiki/Histogram_equalization

import numpy as np
import cv2 as cv
from matplotlib import pyplot as plt
# img = cv.imread('Resources/histogram.jpg',0)
# hist,bins = np.histogram(img.flatten(),256,[0,256])
# cdf = hist.cumsum()
# cdf_normalized = cdf * float(hist.max()) / cdf.max()
# plt.plot(cdf_normalized, color = 'b')
# plt.hist(img.flatten(),256,[0,256], color = 'r')
# plt.xlim([0,256])
# plt.legend(('cdf','histogram'), loc = 'upper left')
# plt.show()


# 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).astype('uint8')

# img2 = cdf[img]

#histograms equalization in opencv
#https://www.youtube.com/watch?v=jWShMEhMZI4
#https://en.wikipedia.org/wiki/Bilinear_interpolation#:~:text=In%20mathematics%2C%20bilinear%20interpolation%20is,again%20in%20the%20other%20direction.
img = cv.imread('Resources/histogram.jpg',0)
cv.imshow('windows', img)
equ = cv.equalizeHist(img)
res = np.hstack((img,equ)) #stacking images side-by-side
# cv.imshow('res', res)
plt.imshow(res,cmap = 'gray')
plt.show()
#https://www.youtube.com/watch?v=eNBZI-qYhpg
#https://www.math.uci.edu/icamp/courses/math77c/demos/hist_eq.pdf
#https://en.wikipedia.org/wiki/Histogram_equalization

import numpy as np
import cv2 as cv
from matplotlib import pyplot as plt
# img = cv.imread('Resources/histogram.jpg',0)
# hist,bins = np.histogram(img.flatten(),256,[0,256])
# cdf = hist.cumsum()
# cdf_normalized = cdf * float(hist.max()) / cdf.max()
# plt.plot(cdf_normalized, color = 'b')
# plt.hist(img.flatten(),256,[0,256], color = 'r')
# plt.xlim([0,256])
# plt.legend(('cdf','histogram'), loc = 'upper left')
# plt.show()


# 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).astype('uint8')

# img2 = cdf[img]

#histograms equalization in opencv
#https://www.youtube.com/watch?v=jWShMEhMZI4
#https://en.wikipedia.org/wiki/Bilinear_interpolation#:~:text=In%20mathematics%2C%20bilinear%20interpolation%20is,again%20in%20the%20other%20direction.
img = cv.imread('Resources/histogram.jpg',0)
cv.imshow('windows', img)
equ = cv.equalizeHist(img)
res = np.hstack((img,equ)) #stacking images side-by-side
# cv.imshow('res', res)
plt.imshow(res,cmap = 'gray')
plt.show()
#https://www.youtube.com/watch?v=eNBZI-qYhpg #https://www.math.uci.edu/icamp/courses/math77c/demos/hist_eq.pdf #https://en.wikipedia.org/wiki/Histogram_equalization # img = cv.imread('Resources/histogram.jpg',0) # hist,bins = np.histogram(img.flatten(),256,[0,256]) # cdf = hist.cumsum() # cdf_normalized = cdf * float(hist.max()) / cdf.max() # plt.plot(cdf_normalized, color = 'b') # plt.hist(img.flatten(),256,[0,256], color = 'r') # plt.xlim([0,256]) # plt.legend(('cdf','histogram'), loc = 'upper left') # plt.show() # 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).astype('uint8') # img2 = cdf[img] #histograms equalization in opencv #https://www.youtube.com/watch?v=jWShMEhMZI4 #https://en.wikipedia.org/wiki/Bilinear_interpolation#:~:text=In%20mathematics%2C%20bilinear%20interpolation%20is,again%20in%20the%20other%20direction. #stacking images side-by-side # cv.imshow('res', res)