2.3 MiB
2.3 MiB
import cv2 as cv
import numpy as np
import matplotlib.pyplot as plt
%matplotlib inline
#zadanie 1
park = cv.imread("img/park-to-eq.jpg", cv.IMREAD_COLOR)
plt.figure(figsize=(20,5))
plt.subplot(121)
plt.imshow(park[:,:,::-1])
plt.title("Image")
Text(0.5, 1.0, 'Image')
new_park = park.copy()
new_park[:,:,0] = cv.equalizeHist(new_park[:,:,0])
new_park[:,:,1] = cv.equalizeHist(new_park[:,:,1])
new_park[:,:,2] = cv.equalizeHist(new_park[:,:,2])
plt.figure(figsize=(20,5))
plt.subplot(121)
plt.imshow(new_park[:,:,::-1])
plt.title("Image")
Text(0.5, 1.0, 'Image')
#HSV
park_hsv = cv.cvtColor(park, cv.COLOR_BGR2HSV)
# wystarczy zastosować equalize na kanale V, który odpowiada za jasność
park_hsv[:,:,2] = cv.equalizeHist(park_hsv[:,:,2])
park_rgb = cv.cvtColor(park_hsv, cv.COLOR_HSV2RGB)
plt.figure(figsize=(20,5))
plt.subplot(121)
plt.imshow(park_rgb)
plt.title("Image")
Text(0.5, 1.0, 'Image')
#Zadanie 2
man = cv.imread("img/man-at-desk.jpg", cv.IMREAD_COLOR)
plt.figure(figsize=(30,10))
plt.subplot(121)
plt.imshow(man[:,:,::-1])
plt.title("Image")
Text(0.5, 1.0, 'Image')
man_hsv = cv.cvtColor(man, cv.COLOR_BGR2HSV)
# wystarczy zastosować equalize na kanale V, który odpowiada za jasność
man_hsv[:,:,2] = cv.equalizeHist(man_hsv[:,:,2])
man_rgb = cv.cvtColor(man_hsv, cv.COLOR_HSV2RGB)
plt.figure(figsize=(30,10))
plt.subplot(121)
plt.imshow(man_rgb)
plt.title("Image")
Text(0.5, 1.0, 'Image')
man_new_hsv = cv.cvtColor(man, cv.COLOR_BGR2HSV)
clahe = cv.createCLAHE(clipLimit=2.0, tileGridSize=(5,5))
H, S, V = cv.split(man_new_hsv)
output1_H = clahe.apply(H)
output1_S = clahe.apply(S)
output1_V = clahe.apply(V)
clahe = cv.merge((output1_H, output1_S, output1_V))
final = cv.cvtColor(clahe, cv.COLOR_HSV2RGB)
plt.figure(figsize=(15,10))
plt.subplot(121)
plt.imshow(man[:,:,::-1])
plt.title("Before")
plt.subplot(122)
plt.imshow(final)
plt.title("After")
Text(0.5, 1.0, 'After')
#zadanie 3