Initial commit with project files

This commit is contained in:
2025-06-27 14:34:11 +02:00
commit 7ea3207e63
310 changed files with 9331 additions and 0 deletions

View File

@@ -0,0 +1,21 @@
# Übung 2: Morphologische Operatoren
In dieser Übung werden die morphologischen Operatoren *Dilatation* und *Erosion* behandelt.
## Aufgabe a)
Geben Sie die Definition der Dilatation und der Erosion an! Die Lösung findet sich in [l_a.md](l_a.md).
## Aufgabe b)
Geben Sie die Definition von *Opening* und *Closing* als Funktion von Dilatation und der Erosion an! Die Lösung findet sich in [l_b.md](l_b.md).
## Aufgabe c)
Wenn ein Binärbild nach einer Erosion an einer Position (x, y) den Wert 1 hat, muss dann
das ursprüngliche Bild ebenfalls an der Stelle (x, y) den Wert 1 haben? Die Lösung findet sich in [l_c.md](l_c.md).
## Aufgabe d)
Gegeben seien folgendes Binärbild (links) und Strukturelement (rechts, Ursprung in der Mitte).
Berechnen Sie das Ergebnisbild nach dem Ausführen einer Opening-Operation.
![data/morph.png](data/morph.png)
Das Binärbild finden Sie in der Datei [d.py](d.py). Die dazugehörige Musterlösung in der Datei [l_d.py](l_d.py).

22
5_Bildanalyse/ü2/d.py Normal file
View File

@@ -0,0 +1,22 @@
import cv2
import numpy as np
I = np.asarray([
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 1, 1, 0, 1, 1, 0, 1, 0],
[0, 1, 0, 1, 1, 0, 1, 1, 1, 0],
[0, 0, 1, 0, 0, 0, 0, 1, 1, 0],
[0, 0, 1, 0, 0, 1, 0, 0, 1, 0],
[0, 0, 1, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 1, 0, 0, 0, 0, 1, 0],
[0, 0, 0, 1, 1, 1, 0, 1, 1, 0],
[0, 1, 0, 1, 1, 1, 0, 1, 1, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
], dtype=np.uint8)
s = np.asarray([
[0, 1, 0],
[0, 1, 1],
[0, 0, 0],
], dtype=np.uint8)

Binary file not shown.

After

Width:  |  Height:  |  Size: 40 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 42 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 22 KiB

20
5_Bildanalyse/ü2/l_a.md Normal file
View File

@@ -0,0 +1,20 @@
# Musterlösung Aufgabe a)
Die beiden Basisoperatoren in der morphologischen Filterung sind die dualen Filter Erosion
(Verkleinerung, Ausdünnung) und Dilatation (Vergrößerung, Aufblähung).
Bei einer Dilatation (lat: dilaterare: ausbreiten, dehnen) werden Hintergrundpixel, die bestimmte
Voraussetzungen erfüllen, in den Vordergrund aufgenommen. Eine bestimmte Pixelposition (Ankerpunkt)
wird auf 1 gesetzt (also dem Vordergrund zugeordnet), falls das Strukturelement mindestens
ein Pixel mit Wert 1 des Bildes überdeckt.
![data/dilatation.png](data/dilatation.png)
Die der Dilatation entgegengesetzte Operation nennt man Erosion (lat: erodere = abnagen). Diese
Operation verkleinert die Segmente, indem bestimmte Segmentpixel dem Hintergrund beigeordnet
werden. Hier wird der Ankerpunkt auf 0 gesetzt (also dem Hintergrund zugeordnet), falls das
Strukturelement mindestens ein Pixel des Binärbildes mit den Wert 0 überdeckt. Andernfalls wird
der Ankerpunkt auf 1 gesetzt.
![data/erosion.png](data/erosion.png)

26
5_Bildanalyse/ü2/l_b.md Normal file
View File

@@ -0,0 +1,26 @@
# Musterlösung Aufgabe b)
**Erosion:**
<p align="center">
<img src="https://latex.codecogs.com/svg.image?A&space;\ominus&space;b" title="A \ominus b" />
</p>
**Dilatation:**
<p align="center">
<img src="https://latex.codecogs.com/svg.image?A&space;\oplus&space;b" title="A \oplus b" />
</p>
**Opening:**
<p align="center">
<img src="https://latex.codecogs.com/svg.image?(A&space;\ominus&space;b)\oplus&space;b" title="(A \ominus b)\oplus b" />
</p>
**Closing:**
<p align="center">
<img src="https://latex.codecogs.com/svg.image?(A&space;\oplus&space;b)\ominus&space;b" title="(A \oplus b)\ominus b" />
</p>

10
5_Bildanalyse/ü2/l_c.md Normal file
View File

@@ -0,0 +1,10 @@
# Musterlösung Aufgabe c)
Antwort: Nein!
Beweis:
Verwendet man als Strukturelement zum Beispiel
<p align="center">
<img src="https://latex.codecogs.com/svg.image?\begin{bmatrix}&space;0&&space;1&space;&&space;0&space;\\&space;1&&space;0&space;&&space;1&space;\\&space;0&&space;1&space;&&space;0&space;\\\end{bmatrix}" title="\begin{bmatrix} 0& 1 & 0 \\ 1& 0 & 1 \\ 0& 1 & 0 \\\end{bmatrix}" />
</p>
so kann die Erosion zusätzliche
Binärpixel erzeugen, welche nicht im Ursprungsbild waren.

35
5_Bildanalyse/ü2/l_d.py Normal file
View File

@@ -0,0 +1,35 @@
import cv2
import numpy as np
I = np.asarray([
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 1, 1, 0, 1, 1, 0, 1, 0],
[0, 1, 0, 1, 1, 0, 1, 1, 1, 0],
[0, 0, 1, 0, 0, 0, 0, 1, 1, 0],
[0, 0, 1, 0, 0, 1, 0, 0, 1, 0],
[0, 0, 1, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 1, 0, 0, 0, 0, 1, 0],
[0, 0, 0, 1, 1, 1, 0, 1, 1, 0],
[0, 1, 0, 1, 1, 1, 0, 1, 1, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
], dtype=np.uint8)
s = np.asarray([
[0, 1, 0],
[0, 1, 1],
[0, 0, 0],
], dtype=np.uint8)
I_new = cv2.erode(I, s)
I_new = cv2.dilate(I_new, s)
# Resize image
I = np.repeat(I, 50, axis=1)
I = np.repeat(I, 50, axis=0)
I_new = np.repeat(I_new, 50, axis=1)
I_new = np.repeat(I_new, 50, axis=0)
cv2.imshow("Original", I * 255)
cv2.imshow("Opening", I_new * 255)
cv2.waitKey(0)