summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--02_HelperFunctions.py13
-rw-r--r--openCVTools.py9
-rw-r--r--pyvenv.cfg3
3 files changed, 17 insertions, 8 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)
diff --git a/openCVTools.py b/openCVTools.py
index 484c3fa..d808dea 100644
--- a/openCVTools.py
+++ b/openCVTools.py
@@ -25,7 +25,7 @@ def imageStats(img):
Returns a few image statistics
'''
s = img.shape
- return f'Width: {s[1]}, Height: {s[0]}, Channels: {s[2]}'
+ return "Width: {}, Height: {}, Channels: {}, Type: {}".format(s[1], s[0], s[2] if len(s) >= 3 else 1, img[0][0][0].dtype if len(s) >= 3 else img[0][0].dtype)
@@ -37,9 +37,12 @@ def showImage(title, originalImg):
print(imageStats(originalImg))
img = originalImg.copy()
- img = img[:,:,::-1]
plt.figure(title)
- plt.imshow(img)
+ if len(img.shape) >= 3:
+ img = img[:,:,::-1]
+ plt.imshow(img)
+ else:
+ plt.imshow(img, cmap="gray")
plt.show()
diff --git a/pyvenv.cfg b/pyvenv.cfg
deleted file mode 100644
index 8810f2d..0000000
--- a/pyvenv.cfg
+++ /dev/null
@@ -1,3 +0,0 @@
-home = /usr/bin
-include-system-site-packages = false
-version = 3.10.8