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,13 @@
# Übung 8: Vereinigung und Querschnitt
Betrachten Sie die folgenden Binärbilder:
| Objekt 1 | Objekt 2 |
| -------- | -------- |
| ![](data/a.png) | ![](data/b.png) |
## a) Vereinigung
Zeichnen Sie die Vereinigung der beiden Objekte.
Die Lösung befindet sich in Datei [l_a.py](l_a.py).

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.2 KiB

66
5_Bildanalyse/ü8/l_a.py Normal file
View File

@@ -0,0 +1,66 @@
import numpy as np
import cv2
obj1 = np.asarray([
[0, 0, 0, 0, 0, 0, 0, 0],
[0, 1, 1, 1, 1, 1, 0, 0],
[0, 1, 1, 0, 1, 1, 0, 0],
[0, 1, 1, 1, 1, 1, 0, 0],
[0, 0, 1, 1, 1, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0],
])
obj2 = np.asarray([
[0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 1, 0, 0, 0],
[0, 0, 0, 1, 1, 0, 0, 0],
[0, 0, 0, 1, 1, 0, 0, 0],
[0, 0, 0, 1, 1, 1, 0, 0],
[0, 0, 0, 0, 1, 1, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0],
])
# obj1 = np.ones((5, 5))
# obj2 = np.ones((5, 5))
union = np.maximum(obj1, obj2)
# Visualize images
# Resize image
obj1 = np.repeat(obj1, 50, axis=1)
obj1 = np.repeat(obj1, 50, axis=0)
obj2 = np.repeat(obj2, 50, axis=1)
obj2 = np.repeat(obj2, 50, axis=0)
union = np.repeat(union, 50, axis=1)
union = np.repeat(union, 50, axis=0)
# Add seperators
obj1[0::2, ::50] = 1
obj1[1::2, ::50] = 0
obj1[::50, 0::2] = 1
obj1[::50, 1::2] = 0
obj2[0::2, ::50] = 1
obj2[1::2, ::50] = 0
obj2[::50, 0::2] = 1
obj2[::50, 1::2] = 0
union[0::2, ::50] = 1
union[1::2, ::50] = 0
union[::50, 0::2] = 1
union[::50, 1::2] = 0
# Show image
obj1 = obj1.astype(np.float64)
obj2 = obj2.astype(np.float64)
union = union.astype(np.float64)
cv2.imshow("obj1", obj1)
cv2.imshow("obj2", obj2)
cv2.imshow("union", union)
cv2.imwrite("data/white.png", obj1 * 255)
cv2.waitKey(0)

63
5_Bildanalyse/ü8/l_b.py Normal file
View File

@@ -0,0 +1,63 @@
import numpy as np
import cv2
obj1 = np.asarray([
[0, 0, 0, 0, 0, 0, 0, 0],
[0, 1, 1, 1, 1, 1, 0, 0],
[0, 1, 1, 0, 1, 1, 0, 0],
[0, 1, 1, 1, 1, 1, 0, 0],
[0, 0, 1, 1, 1, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0],
])
obj2 = np.asarray([
[0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 1, 0, 0, 0],
[0, 0, 0, 1, 1, 0, 0, 0],
[0, 0, 0, 1, 1, 0, 0, 0],
[0, 0, 0, 1, 1, 1, 0, 0],
[0, 0, 0, 0, 1, 1, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0],
])
intersection = obj1 * obj2
# Visualize images
# Resize image
obj1 = np.repeat(obj1, 50, axis=1)
obj1 = np.repeat(obj1, 50, axis=0)
obj2 = np.repeat(obj2, 50, axis=1)
obj2 = np.repeat(obj2, 50, axis=0)
intersection = np.repeat(intersection, 50, axis=1)
intersection = np.repeat(intersection, 50, axis=0)
# Add seperators
obj1[0::2, ::50] = 1
obj1[1::2, ::50] = 0
obj1[::50, 0::2] = 1
obj1[::50, 1::2] = 0
obj2[0::2, ::50] = 1
obj2[1::2, ::50] = 0
obj2[::50, 0::2] = 1
obj2[::50, 1::2] = 0
intersection[0::2, ::50] = 1
intersection[1::2, ::50] = 0
intersection[::50, 0::2] = 1
intersection[::50, 1::2] = 0
# Show image
obj1 = obj1.astype(np.float64)
obj2 = obj2.astype(np.float64)
intersection = intersection.astype(np.float64)
cv2.imshow("obj1", obj1)
cv2.imshow("obj2", obj2)
cv2.imshow("intersection", intersection)
cv2.waitKey(0)