Initial commit with project files
This commit is contained in:
21
5_Bildanalyse/ü2/README.md
Normal file
21
5_Bildanalyse/ü2/README.md
Normal 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.
|
||||
|
||||

|
||||
|
||||
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
22
5_Bildanalyse/ü2/d.py
Normal 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)
|
||||
|
||||
BIN
5_Bildanalyse/ü2/data/dilatation.png
Normal file
BIN
5_Bildanalyse/ü2/data/dilatation.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 40 KiB |
BIN
5_Bildanalyse/ü2/data/erosion.png
Normal file
BIN
5_Bildanalyse/ü2/data/erosion.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 42 KiB |
BIN
5_Bildanalyse/ü2/data/morph.png
Normal file
BIN
5_Bildanalyse/ü2/data/morph.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 22 KiB |
20
5_Bildanalyse/ü2/l_a.md
Normal file
20
5_Bildanalyse/ü2/l_a.md
Normal 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.
|
||||
|
||||

|
||||
|
||||
|
||||
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.
|
||||
|
||||

|
||||
26
5_Bildanalyse/ü2/l_b.md
Normal file
26
5_Bildanalyse/ü2/l_b.md
Normal 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
10
5_Bildanalyse/ü2/l_c.md
Normal 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
35
5_Bildanalyse/ü2/l_d.py
Normal 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)
|
||||
Reference in New Issue
Block a user