Initial commit with project files
This commit is contained in:
25
4_Farbrepräsentationen/ü4/README.md
Normal file
25
4_Farbrepräsentationen/ü4/README.md
Normal file
@@ -0,0 +1,25 @@
|
||||
# Übung 4: Weißabgleich
|
||||
|
||||
Bei Digitalaufnahmen lässt sich über Bildverarbeitungssoftware der Weißabgleich zu einem gewissen
|
||||
Grad per Software korrigieren. Dazu skaliert man die relativen Luminanzen der Kanäle Rot,
|
||||
Grün und Blau. Die Skalierung wird über eine Multiplikation mit der folgenden Diagonalmatrix
|
||||
realisiert.
|
||||
|
||||
<p align="center">
|
||||
<img src="https://latex.codecogs.com/svg.image?\begin{bmatrix}&space;R&space;\\G&space;\\B&space;\\\end{bmatrix}&space;=&space;\begin{bmatrix}&space;r_w&space;&&space;0&space;&&space;0\\&space;0&g_w&space;&0&space;\\0&0&b_w&space;\\\end{bmatrix}&space;\cdot\begin{bmatrix}&space;R'&space;\\G'&space;\\B'&space;\\\end{bmatrix}&space;" title="\begin{bmatrix} R \\G \\B \\\end{bmatrix} = \begin{bmatrix} r_w & 0 & 0\\ 0&g_w &0 \\0&0&b_w \\\end{bmatrix} \cdot\begin{bmatrix} R' \\G' \\B' \\\end{bmatrix} " />
|
||||
</p>
|
||||
|
||||
Das Problem ist nun die Parameter für den optimalen Weißpunkt zu wählen.
|
||||
|
||||
## Aufgabe a)
|
||||
|
||||
Laden Sie das Bild [../../data/obst.png](../../data/obst.png) und geben Sie er aus. Führen Sie danach den Weißabgleich durch.
|
||||
Wählen Sie als Parameter Werte, sodass die Farbwerte des Pixels an Stelle x=127 y=146 den Farbwert (255, 255, 255) haben.
|
||||
Zeigen Sie ebenfalls das abgeglichene Bild an. Die Musterlösung findet sich in der Datei [l_a.py](l_a.py).
|
||||
|
||||

|
||||
|
||||
## Aufgabe b)
|
||||
|
||||
Führen Sie den Weißabgleich auf Ihrem Webcam-Stream durch. Sie können die Parameter frei wählen und variieren.
|
||||
Die Musterlösung findet sich in der Datei [l_b.py](l_b.py).
|
||||
19
4_Farbrepräsentationen/ü4/l_a.py
Normal file
19
4_Farbrepräsentationen/ü4/l_a.py
Normal file
@@ -0,0 +1,19 @@
|
||||
import cv2
|
||||
import numpy as np
|
||||
|
||||
img = cv2.imread("../../data/model.png")
|
||||
|
||||
#white_balancing_factor = np.asarray([[[1, 1, 1]]])
|
||||
white_balancing_factor = 255 / img[146, 127].astype(np.float32)
|
||||
white_balancing_factor = np.expand_dims(white_balancing_factor, 0)
|
||||
white_balancing_factor = np.expand_dims(white_balancing_factor, 1)
|
||||
|
||||
img_balanced = img * white_balancing_factor
|
||||
img_balanced = np.clip(img_balanced, 0, 255)
|
||||
img_balanced = img_balanced.astype(np.uint8)
|
||||
|
||||
cv2.imshow("Normal", img)
|
||||
cv2.imshow("Abgeglichen", img_balanced)
|
||||
|
||||
cv2.waitKey()
|
||||
|
||||
16
4_Farbrepräsentationen/ü4/l_b.py
Normal file
16
4_Farbrepräsentationen/ü4/l_b.py
Normal file
@@ -0,0 +1,16 @@
|
||||
import cv2
|
||||
import numpy as np
|
||||
|
||||
white_balancing_factor = np.asarray([[[0.5, 0.3, 0.95]]])
|
||||
|
||||
cap = cv2.VideoCapture(0)
|
||||
|
||||
while True:
|
||||
ret, img = cap.read()
|
||||
img_balanced = img * white_balancing_factor
|
||||
img_balanced = np.clip(img_balanced, 0, 255)
|
||||
img_balanced = img_balanced.astype(np.uint8)
|
||||
cv2.imshow("Normal", img)
|
||||
cv2.imshow("Abgeglichen", img_balanced)
|
||||
cv2.waitKey(1)
|
||||
|
||||
Reference in New Issue
Block a user