Initial commit with project files
This commit is contained in:
29
5_Bildanalyse/ü11/README.md
Normal file
29
5_Bildanalyse/ü11/README.md
Normal file
@@ -0,0 +1,29 @@
|
||||
# Übung 11: Objekt Klassifikation
|
||||
|
||||
In dieser Aufgabe sollen Sie einen Algorithmus für die Klassifikation von bereits segmentierten Objekten schreiben.
|
||||
Dabei sollen Sie jedem der 6 folgenden Bilder eine Klasse zuordnen. Die Möglichen Klassen sind dabei
|
||||
|
||||
- Mensch
|
||||
- Ball
|
||||
- Fenster
|
||||
|
||||
|  |  |  |
|
||||
| ---------- | -------- | ----- |
|
||||
|  |  |  |
|
||||
|
||||
|
||||
## a) Erzeugung von Merkmalen
|
||||
|
||||
Erstellen Sie enige Merkmale, welche Größe oder Form der Objekte quantitativ beschreiben. Achten Sie darauf,
|
||||
dass die Merkmale möglichst diskriminativ sind, sodass sie zur Unterscheidung in die verschiedenen Klassen genutzt
|
||||
werden können.
|
||||
|
||||
|
||||
Bitte führen Sie für die Bearbeitung der Aufgabe das Skript [a.py](a.py) fort.
|
||||
Die Lösung befindet sich in Datei [l_a.py](l_a.py).
|
||||
|
||||
## b) Klassifikation von Merkmalen
|
||||
Erstellen Sie nun qualitative Regeln mit den in Aufgabe a) erstellen Merkmalen, um die Elemente in den Bildern zu
|
||||
klassifizieren. Sie brauchen dabei nicht programmieren, sondern lediglich Regeln für die Klassifizierung erstellen.
|
||||
|
||||
Eine mögliche Lösung befindet sich in Datei [l_b.md](l_b.md).
|
||||
20
5_Bildanalyse/ü11/a.py
Normal file
20
5_Bildanalyse/ü11/a.py
Normal file
@@ -0,0 +1,20 @@
|
||||
import numpy as np
|
||||
import cv2
|
||||
|
||||
|
||||
''' Load images '''
|
||||
img1 = cv2.imread("data/mensch.png", cv2.IMREAD_GRAYSCALE)
|
||||
img2 = cv2.imread("data/mensch2.png", cv2.IMREAD_GRAYSCALE)
|
||||
img3 = cv2.imread("data/kasten.png", cv2.IMREAD_GRAYSCALE)
|
||||
img4 = cv2.imread("data/kasten2.png", cv2.IMREAD_GRAYSCALE)
|
||||
img5 = cv2.imread("data/ball.png", cv2.IMREAD_GRAYSCALE)
|
||||
img6 = cv2.imread("data/ball2.png", cv2.IMREAD_GRAYSCALE)
|
||||
|
||||
''' Define features '''
|
||||
|
||||
|
||||
''' Show parameter '''
|
||||
for name, img in [("img1", img1), ("img2", img2), ("img3", img3), ("img4", img4), ("img5", img5), ("img6", img6)]:
|
||||
print("Image:", name)
|
||||
print(" feature =", ...)
|
||||
|
||||
BIN
5_Bildanalyse/ü11/data/ball.png
Normal file
BIN
5_Bildanalyse/ü11/data/ball.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 527 B |
BIN
5_Bildanalyse/ü11/data/ball2.png
Normal file
BIN
5_Bildanalyse/ü11/data/ball2.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 925 B |
BIN
5_Bildanalyse/ü11/data/kasten.png
Normal file
BIN
5_Bildanalyse/ü11/data/kasten.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 830 B |
BIN
5_Bildanalyse/ü11/data/kasten2.png
Normal file
BIN
5_Bildanalyse/ü11/data/kasten2.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 782 B |
BIN
5_Bildanalyse/ü11/data/mensch.png
Normal file
BIN
5_Bildanalyse/ü11/data/mensch.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.3 KiB |
BIN
5_Bildanalyse/ü11/data/mensch2.png
Normal file
BIN
5_Bildanalyse/ü11/data/mensch2.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.0 KiB |
60
5_Bildanalyse/ü11/l_a.py
Normal file
60
5_Bildanalyse/ü11/l_a.py
Normal file
@@ -0,0 +1,60 @@
|
||||
import numpy as np
|
||||
import cv2
|
||||
|
||||
''' Load images '''
|
||||
img1 = cv2.imread("data/mensch.png", cv2.IMREAD_GRAYSCALE)
|
||||
img2 = cv2.imread("data/mensch2.png", cv2.IMREAD_GRAYSCALE)
|
||||
img3 = cv2.imread("data/kasten.png", cv2.IMREAD_GRAYSCALE)
|
||||
img4 = cv2.imread("data/kasten2.png", cv2.IMREAD_GRAYSCALE)
|
||||
img5 = cv2.imread("data/ball.png", cv2.IMREAD_GRAYSCALE)
|
||||
img6 = cv2.imread("data/ball2.png", cv2.IMREAD_GRAYSCALE)
|
||||
|
||||
''' Define features '''
|
||||
|
||||
|
||||
def height_and_width(img):
|
||||
rows, cols = np.where(img != 0)
|
||||
x1, x2, y1, y2 = np.min(cols), np.max(cols), np.min(rows), np.max(rows)
|
||||
h = y2 - y1
|
||||
w = x2 - x1
|
||||
return h, w
|
||||
|
||||
|
||||
def height_over_width(w, h):
|
||||
return h / w
|
||||
|
||||
|
||||
def perimeter(img):
|
||||
kernel = np.asarray([[0, 1, 0], [1, 1, 1], [0, 1, 0]], dtype=np.uint8)
|
||||
small_img = cv2.erode(img, kernel)
|
||||
edges = img - small_img
|
||||
peri = np.sum(edges / np.max(edges))
|
||||
return peri
|
||||
|
||||
|
||||
def area(img):
|
||||
return np.sum(img / np.max(img))
|
||||
|
||||
|
||||
def roundness(perimeter, area, h, w):
|
||||
# (2 pi r) / (pi r^2) = perimeter / area = 2 / r for round objects
|
||||
# r = h / 2 = w / 2
|
||||
r = 0.5 * (h / 2 + w / 2)
|
||||
round = r * perimeter / (2 * area)
|
||||
return round
|
||||
|
||||
|
||||
''' Show parameter '''
|
||||
for name, img in [("img1", img1), ("img2", img2), ("img3", img3), ("img4", img4), ("img5", img5), ("img6", img6)]:
|
||||
print("Image:", name)
|
||||
object_height, object_width = height_and_width(img)
|
||||
print(" h =", object_height)
|
||||
print(" w =", object_width)
|
||||
object_height_over_width = height_over_width(object_width, object_height)
|
||||
print(" height_over_width =", object_height_over_width)
|
||||
object_perimeter = perimeter(img)
|
||||
print(" perimeter =", object_perimeter)
|
||||
object_area = area(img)
|
||||
print(" area =", object_area)
|
||||
object_roundness = roundness(object_perimeter, object_area, object_height, object_width)
|
||||
print(" roundness =", object_roundness)
|
||||
60
5_Bildanalyse/ü11/l_b.md
Normal file
60
5_Bildanalyse/ü11/l_b.md
Normal file
@@ -0,0 +1,60 @@
|
||||
# Lösung b): Klassifikation von Merkmalen
|
||||
|
||||
Basierend auf den Merkmalen in Teilaufgabe a) können einige Regelen für die Klassifikation von Objekten erstellt werden.
|
||||
Diese Lösung ist eine von vielen möglichen Lösungen und bezieht sich auf die Ausgabe aus Aufgabe a):
|
||||
|
||||
````shell
|
||||
Image: img1
|
||||
h = 119
|
||||
w = 60
|
||||
height_over_width = 1.9833333333333334
|
||||
perimeter = 535.0
|
||||
area = 2925.0
|
||||
roundness = 4.092521367521368
|
||||
Image: img2
|
||||
h = 96
|
||||
w = 53
|
||||
height_over_width = 1.8113207547169812
|
||||
perimeter = 494.0
|
||||
area = 1981.0
|
||||
roundness = 4.6444977284199895
|
||||
Image: img3
|
||||
h = 98
|
||||
w = 117
|
||||
height_over_width = 0.8376068376068376
|
||||
perimeter = 1120.0
|
||||
area = 2489.0
|
||||
roundness = 12.093210124548012
|
||||
Image: img4
|
||||
h = 73
|
||||
w = 56
|
||||
height_over_width = 1.3035714285714286
|
||||
perimeter = 631.0
|
||||
area = 884.0
|
||||
roundness = 11.510039592760181
|
||||
Image: img5
|
||||
h = 48
|
||||
w = 50
|
||||
height_over_width = 0.96
|
||||
perimeter = 140.0
|
||||
area = 1960.0
|
||||
roundness = 0.875
|
||||
Image: img6
|
||||
h = 49
|
||||
w = 56
|
||||
height_over_width = 0.875
|
||||
perimeter = 382.0
|
||||
area = 2111.0
|
||||
roundness = 2.3750592136428232
|
||||
|
||||
Process finished with exit code 0
|
||||
|
||||
````
|
||||
|
||||
- **Menschen** sind im stehenden Zustand ca. doppelt so hoch wie breit. Daher sollte bei einem Menschen *height_over_width* ca. 2 sein. Zusätzlich sollte die *roundness* deutlich ungleich 1 sein.
|
||||
- **Bälle** sind unabhängig von ihrer Größe rund. Die *roundness* sollte daher in der Nähe von 1 liegen.
|
||||
- **Fenster** haben meistens aufgrund der "Kacheln" eine geringe Fläche, verglichen zu dem Umfang.
|
||||
|
||||
|
||||
Diese Regeln müssen nicht auf jedes Objekt zutreffen. Sie sollen lediglich veranschaulichen, wie Regeln für einen Klassifikator
|
||||
aus Merkmalen erstellt werden können.
|
||||
Reference in New Issue
Block a user