Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import cv2
- import numpy as np
- from matplotlib import pyplot as plt
- def histo_eq(img, img_name):
- """Histogram equalization"""
- # convert from RGB color-space to YCrCb
- plt.hist(img.flatten(), 256, [0, 256], color='r')
- plt.xlim([0, 256])
- plt.show()
- ycrcb_img = cv2.cvtColor(img, cv2.COLOR_BGR2YCrCb)
- # equalize the histogram of the Y channel
- ycrcb_img[:, :, 0] = cv2.equalizeHist(ycrcb_img[:, :, 0])
- # convert back to RGB color-space from YCrCb
- equalized_img = cv2.cvtColor(ycrcb_img, cv2.COLOR_YCrCb2BGR)
- plt.hist(equalized_img.flatten(), 256, [0, 256], color='r')
- plt.xlim([0, 256])
- plt.show()
- output_path = f'EditedImages/histo_equalization_{img_name}'
- cv2.imwrite(output_path, equalized_img)
- return equalized_img, output_path
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement