summaryrefslogtreecommitdiff
path: root/02_HelperFunctions.py
diff options
context:
space:
mode:
Diffstat (limited to '02_HelperFunctions.py')
-rw-r--r--02_HelperFunctions.py13
1 files changed, 11 insertions, 2 deletions
diff --git a/02_HelperFunctions.py b/02_HelperFunctions.py
index 1ef0944..7cbe076 100644
--- a/02_HelperFunctions.py
+++ b/02_HelperFunctions.py
@@ -9,6 +9,13 @@ import matplotlib.pyplot as plt
def REPLACE_THIS(input): return input
+def grayscale(img):
+ for x in img:
+ for y in img[x]:
+ i = 0
+ for c in img[x][y]:
+ i =+ c
+ img[x][y] = i
# load image
imgOriginal = cvt.safeLoad('images/hummingbird_from_pixabay.png')
@@ -20,7 +27,7 @@ cvt.showImage("Original image", imgOriginal)
Konvertieren Sie das Bild in ein 1-Kanal Schwarzweiß(Grauton)-Bild.
Passen Sie die Funktionen `imageStats(..)` und `showImage(..)` so an, dass sie sowohl für Grau- als auch Farbbilder korrekt funktionieren.
'''
-imgGray = REPLACE_THIS(imgOriginal)
+imgGray = cv.cvtColor(imgOriginal, cv.COLOR_BGR2GRAY)
cvt.showImage("Grayscale image", imgGray)
@@ -28,7 +35,7 @@ cvt.showImage("Grayscale image", imgGray)
Konvertieren Sie das originale Bild von seinem Stndarddatentyp (`uint8` pro Farbkanal) in `float` und zeigen Sie es an.
Voraussichtlich wird das Bild nahezu weiß sein. Versuchen Sie herauszufinden woran das liegt und passen Sie das Bild entsprechend an.
'''
-img = REPLACE_THIS(imgOriginal)
+img = imgOriginal.astype(np.float64) / 255
print("Floating point image:")
cvt.showImage("Floating point image", img)
@@ -42,6 +49,8 @@ Versuchen Sie dazu den Slicing Operator aus Python zu nutzen.
# ???
#
+img = imgOriginal.copy()
+img[int(img.shape[0] / 2) - 109:int(img.shape[0] / 2) + 110,int(img.shape[1] / 2) - 54:int(img.shape[1] / 2) + 55] = (0, 0, 255)
cvt.showImage("Red box", img)