Initial commit with project files

This commit is contained in:
tobias committed 2025-06-27 14:34:11 +02:00
commit 7ea3207e63
310 files changed
+9331

No files matched your search

+14
View File
@@ -0,0 +1,14 @@
# Übung 9: Kantendetektion
Sie möchten die Kanten des Kopfhörers in dem folgenden Bild detektieren:
![](../../data/headphones.jpg)
## a) Morphologische Operationen
Finden Sie die Kanten, indem Sie das Bild zuerst mit einem geeigneten Schwellwert binarisieren. Verwenden Sie
dann einer der beiden morphologischen Operationen Dilatation oder Erodieren. Wenden Sie dann auf das
Binärbild und morphologisch modifizierte Binärbild eine Subtraktion an und visualisieren Sie die so gefundenen
Kanten in dem originalen Bild.
Die Lösung befindet sich in Datei [l_a.py](l_a.py).
+31
View File
@@ -0,0 +1,31 @@
import numpy as np
import cv2
# Load image
original_img = cv2.imread("../../data/headphones.jpg")
original_img = cv2.resize(original_img, (int(original_img.shape[1]/ 2), int(original_img.shape[0] / 2)))
img = cv2.cvtColor(original_img, cv2.COLOR_BGR2GRAY)
cv2.imshow("original_img", original_img)
# Binary image
threshold = 80
binary_mask = np.copy(img)
binary_mask[img < threshold] = 1
binary_mask[img >= threshold] = 0
cv2.imshow("binary_mask", binary_mask.astype(np.float32))
# Morphing
kernel = np.ones((9, 9))
eroded_mask = cv2.erode(binary_mask, kernel, iterations=1)
cv2.imshow("eroded_mask", eroded_mask.astype(np.float32))
# Subtraction
edges = binary_mask - eroded_mask
cv2.imshow("edges", edges.astype(np.float32))
# Modify original image
original_img[:, :, 2] = np.maximum(original_img[:, :, 2], edges * 255)
cv2.imshow("modified_image", original_img)
cv2.waitKey(0)