Initial commit with project files
This commit is contained in:
22
2_Bildbearbeitung/ü10/README.md
Normal file
22
2_Bildbearbeitung/ü10/README.md
Normal file
@@ -0,0 +1,22 @@
|
||||
# Übung 10: (Contrast Limited) Adaptive Histogramm Equalization
|
||||
|
||||
In dieser Übung soll die Adaptive Histogramm Equalization und die Contrast Limited Adaptive Histogramm Equalization
|
||||
verwendet werden, um den Kontrast in einem Bild zu erhöhen.
|
||||
|
||||
## a) Adaptive Histogramm Equalization
|
||||
|
||||
Wenden Sie die adaptive Histogramm Equalization auf das Bild an, welches in dem Skript [a.py](a.py)
|
||||
geladen wird. Adaptieren Sie für eine Region von 50x50 Pixel. Die Lösung ist in der Datei [l_a.py](l_a.py) zu finden!
|
||||
|
||||
## b) Contrast Limited Adaptive Histogramm Equalization
|
||||
|
||||
Wenden Sie die Kontrast-limitierte adaptive Histogramm Equalization auf das Bild an, welches in dem Skript [b.py](b.py)
|
||||
geladen wird. Sie können ein selbst definiertes Clip-Limit definieren.
|
||||
Adaptieren Sie für eine Region von 50x50 Pixel. Die Lösung ist in der Datei [l_b.py](l_b.py) zu finden!
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
15
2_Bildbearbeitung/ü10/a.py
Normal file
15
2_Bildbearbeitung/ü10/a.py
Normal file
@@ -0,0 +1,15 @@
|
||||
import cv2
|
||||
import numpy as np
|
||||
|
||||
img = cv2.imread("../../data/car.png", cv2.IMREAD_GRAYSCALE)
|
||||
img = cv2.resize(img, (500, 500))
|
||||
# Do some preprocessing
|
||||
img = img.astype(float)
|
||||
img = 50 + (105 * img / 255)
|
||||
cv2.imshow("Original", img.astype(np.uint8))
|
||||
|
||||
# Implement AHE
|
||||
|
||||
|
||||
cv2.waitKey(0)
|
||||
|
||||
15
2_Bildbearbeitung/ü10/b.py
Normal file
15
2_Bildbearbeitung/ü10/b.py
Normal file
@@ -0,0 +1,15 @@
|
||||
import cv2
|
||||
import numpy as np
|
||||
|
||||
img = cv2.imread("../../data/car.png", cv2.IMREAD_GRAYSCALE)
|
||||
img = cv2.resize(img, (500, 500))
|
||||
# Do some preprocessing
|
||||
img = img.astype(float)
|
||||
img = 50 + (105 * img / 255)
|
||||
cv2.imshow("Original", img.astype(np.uint8))
|
||||
|
||||
# Implement CLAHE
|
||||
|
||||
|
||||
cv2.waitKey(0)
|
||||
|
||||
25
2_Bildbearbeitung/ü10/l_a.py
Normal file
25
2_Bildbearbeitung/ü10/l_a.py
Normal file
@@ -0,0 +1,25 @@
|
||||
import cv2
|
||||
import numpy as np
|
||||
|
||||
img = cv2.imread("../../data/car.png", cv2.IMREAD_GRAYSCALE)
|
||||
img = cv2.resize(img, (500, 500))
|
||||
# Do some preprocessing
|
||||
img = img.astype(float)
|
||||
img = 50 + (105 * img / 255)
|
||||
cv2.imshow("Original", img.astype(np.uint8))
|
||||
|
||||
# Implement AHE
|
||||
new_image = np.zeros_like(img)
|
||||
height, width = img.shape
|
||||
for x in range(width):
|
||||
for y in range(height):
|
||||
x1, x2 = np.maximum(0, x - 25), np.minimum(x + 25, height)
|
||||
y1, y2 = np.maximum(0, y - 25), np.minimum(y + 25, height)
|
||||
hist, values = np.histogram(img[y1:y2, x1:x2], bins=256, range=(0, 256))
|
||||
cum_hist = np.cumsum(hist)
|
||||
v = round(img[y, x])
|
||||
new_image[y, x] = 255 * cum_hist[v] / cum_hist[255]
|
||||
cv2.imshow("AHE", new_image.astype(np.uint8))
|
||||
|
||||
cv2.waitKey(0)
|
||||
|
||||
31
2_Bildbearbeitung/ü10/l_b.py
Normal file
31
2_Bildbearbeitung/ü10/l_b.py
Normal file
@@ -0,0 +1,31 @@
|
||||
import cv2
|
||||
import numpy as np
|
||||
|
||||
img = cv2.imread("../../data/car.png", cv2.IMREAD_GRAYSCALE)
|
||||
img = cv2.resize(img, (500, 500))
|
||||
# Do some preprocessing
|
||||
img = img.astype(float)
|
||||
img = 50 + (105 * img / 255)
|
||||
cv2.imshow("Original", img.astype(np.uint8))
|
||||
|
||||
# Implement CLAHE
|
||||
new_image = np.zeros_like(img)
|
||||
height, width = img.shape
|
||||
for x in range(width):
|
||||
for y in range(height):
|
||||
x1, x2 = np.maximum(0, x - 25), np.minimum(x + 25, height)
|
||||
y1, y2 = np.maximum(0, y - 25), np.minimum(y + 25, height)
|
||||
hist, values = np.histogram(img[y1:y2, x1:x2], bins=256, range=(0, 256))
|
||||
clip_limit = 0.6 * round(np.max(hist))
|
||||
higher_values = hist >= clip_limit
|
||||
sum_of_higher_values = np.sum(hist[higher_values] - clip_limit)
|
||||
hist = np.minimum(hist, clip_limit)
|
||||
hist = hist + round(sum_of_higher_values / 256)
|
||||
cum_hist = np.cumsum(hist)
|
||||
v = round(img[y, x])
|
||||
new_image[y, x] = 255 * cum_hist[v] / cum_hist[255]
|
||||
|
||||
cv2.imshow("CLAHE", new_image.astype(np.uint8))
|
||||
|
||||
cv2.waitKey(0)
|
||||
|
||||
Reference in New Issue
Block a user