Initial commit with project files
This commit is contained in:
40
Sandkasten/fft.py
Normal file
40
Sandkasten/fft.py
Normal file
@@ -0,0 +1,40 @@
|
||||
import cv2
|
||||
import numpy as np
|
||||
from matplotlib import pyplot as plt
|
||||
|
||||
|
||||
images = ["data/1.png", "data/2.png", "data/3.png", "data/4.png", "data/5.png"]
|
||||
|
||||
lena = cv2.imread(images[0])
|
||||
|
||||
lena = cv2.cvtColor(lena, cv2.COLOR_BGR2GRAY)
|
||||
|
||||
grauwerte, beugungen = list(), list()
|
||||
for image in images:
|
||||
image = cv2.imread(image)
|
||||
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
|
||||
grauwerte.append(gray)
|
||||
f = np.fft.fft2(gray) # Fouriertransformation
|
||||
fshift = np.fft.fftshift(f) # Umsortieren
|
||||
FT = np.abs(fshift)
|
||||
FT = np.log(np.abs(fshift)) # mit log() wird der Kontrast angehoben
|
||||
beugungen.append(FT)
|
||||
|
||||
i = 0
|
||||
for gray, FT in zip(grauwerte, beugungen):
|
||||
i += 1
|
||||
plt.figure(figsize=(12, 12))
|
||||
plt.subplot(121)
|
||||
plt.xticks([]), plt.yticks([])
|
||||
plt.imshow(gray, cmap = 'gray')
|
||||
plt.title('Lena')
|
||||
|
||||
plt.subplot(122)
|
||||
plt.xticks([]), plt.yticks([])
|
||||
plt.imshow(FT, cmap=plt.cm.gray)
|
||||
plt.title('Fouriertransformierte von Lena')
|
||||
#plt.show()
|
||||
FT = np.round( 255 * (FT + np.min(FT)) / (np.abs(np.max(FT)) + np.abs(np.min(FT))))
|
||||
cv2.imwrite(f"/home/kaiser/Schreibtisch/ownCloud/Vorlesung/DigitaleBildverarbeitung/Klausuren/Klausur_WS2021/images/fft/{i}_grau.png", gray)
|
||||
cv2.imwrite(f"/home/kaiser/Schreibtisch/ownCloud/Vorlesung/DigitaleBildverarbeitung/Klausuren/Klausur_WS2021/images/fft/{i}_fft.png", FT)
|
||||
#print(np.max(FT), np.min(FT))
|
||||
29
Sandkasten/flaschen_transformation.py
Normal file
29
Sandkasten/flaschen_transformation.py
Normal file
@@ -0,0 +1,29 @@
|
||||
import cv2
|
||||
import numpy as np
|
||||
import math
|
||||
|
||||
|
||||
img = cv2.imread("data/flasche.jpeg")
|
||||
img = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
|
||||
x, y = 300, 270
|
||||
img = img[y:y+900, x:x+900]
|
||||
img = cv2.resize(img, (300, 300))
|
||||
rows, cols = img.shape
|
||||
print(rows, cols)
|
||||
alpha = np.pi / 4
|
||||
M1 = np.float32([
|
||||
[np.cos(alpha), -np.sin(alpha), 150],
|
||||
[np.sin(alpha), np.cos(alpha), 0]
|
||||
])
|
||||
|
||||
|
||||
dst1 = cv2.warpAffine(img, M1 ,(cols,rows))
|
||||
|
||||
|
||||
cv2.imshow("A", img)
|
||||
cv2.imshow("1", dst1)
|
||||
|
||||
cv2.waitKey(0)
|
||||
|
||||
#cv2.imwrite("/home/kaiser/Schreibtisch/ownCloud/Vorlesung/DigitaleBildverarbeitung/Klausuren/Klausur_WS2021/images/flasche_original.png", img)
|
||||
#cv2.imwrite("/home/kaiser/Schreibtisch/ownCloud/Vorlesung/DigitaleBildverarbeitung/Klausuren/Klausur_WS2021/images/flasche_rotated.png", dst1)
|
||||
35
Sandkasten/gray_image.py
Normal file
35
Sandkasten/gray_image.py
Normal file
@@ -0,0 +1,35 @@
|
||||
import cv2
|
||||
import numpy as np
|
||||
from matplotlib import pyplot as plt
|
||||
|
||||
|
||||
a = [
|
||||
[220, 0, 150, 3, 100, 0],
|
||||
[0, 250, 3, 160, 0, 100],
|
||||
[150, 0, 203, 0, 165, 5],
|
||||
[2, 145, 5, 205, 0, 150],
|
||||
[99, 0, 150, 0, 255, 2],
|
||||
[1, 105, 0, 160, 0, 250],
|
||||
]
|
||||
|
||||
b = [
|
||||
[0, 1, 0, 0, 0, 0],
|
||||
[1, 0, 1, 0, 0, 0],
|
||||
[0, 1, 0, 1, 0, 0],
|
||||
[0, 0, 1, 0, 1, 0],
|
||||
[0, 0, 0, 1, 0, 1],
|
||||
[0, 0, 0, 0, 1, 0],
|
||||
]
|
||||
|
||||
|
||||
a = np.array(a, dtype=np.uint8)
|
||||
a = cv2.resize(a, (200,200), interpolation=cv2.INTER_NEAREST)
|
||||
b = np.array(b, dtype=np.uint8)
|
||||
b = 255 * b
|
||||
b = cv2.resize(b, (200,200), interpolation=cv2.INTER_NEAREST)
|
||||
|
||||
cv2.imshow("A", b)
|
||||
cv2.waitKey(0)
|
||||
|
||||
cv2.imwrite("/home/kaiser/Schreibtisch/ownCloud/Vorlesung/DigitaleBildverarbeitung/Klausuren/Klausur_WS2021/images/filter_chess.png", a)
|
||||
cv2.imwrite("/home/kaiser/Schreibtisch/ownCloud/Vorlesung/DigitaleBildverarbeitung/Klausuren/Klausur_WS2021/images/filter_chess_final.png", b)
|
||||
40
Sandkasten/transformations.py
Normal file
40
Sandkasten/transformations.py
Normal file
@@ -0,0 +1,40 @@
|
||||
import cv2
|
||||
import numpy as np
|
||||
|
||||
|
||||
img = cv2.imread("data/flower.jpeg")
|
||||
img = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
|
||||
rows, cols = img.shape
|
||||
|
||||
M1 = np.float32([
|
||||
[1, 0, 0],
|
||||
[0, -1, rows]
|
||||
])
|
||||
|
||||
M2 = np.float32([
|
||||
[-1, 0, cols],
|
||||
[0, 1, 0]
|
||||
])
|
||||
|
||||
M3 = np.float32([
|
||||
[2, 0, -int(cols/2)],
|
||||
[0, 2, -int(rows/2)]
|
||||
])
|
||||
|
||||
|
||||
dst1 = cv2.warpAffine(img, M1 ,(cols,rows))
|
||||
dst2 = cv2.warpAffine(img, M2 ,(cols,rows))
|
||||
dst3 = cv2.warpAffine(img, M3 ,(cols,rows))
|
||||
|
||||
|
||||
cv2.imshow("A", img)
|
||||
cv2.imshow("1", dst1)
|
||||
cv2.imshow("2", dst2)
|
||||
cv2.imshow("3", dst3)
|
||||
|
||||
cv2.waitKey(0)
|
||||
|
||||
cv2.imwrite("/home/kaiser/Schreibtisch/ownCloud/Vorlesung/DigitaleBildverarbeitung/Klausuren/Klausur_WS2021/images/flower_original.png", img)
|
||||
cv2.imwrite("/home/kaiser/Schreibtisch/ownCloud/Vorlesung/DigitaleBildverarbeitung/Klausuren/Klausur_WS2021/images/flower_1.png", dst1)
|
||||
cv2.imwrite("/home/kaiser/Schreibtisch/ownCloud/Vorlesung/DigitaleBildverarbeitung/Klausuren/Klausur_WS2021/images/flower_2.png", dst2)
|
||||
cv2.imwrite("/home/kaiser/Schreibtisch/ownCloud/Vorlesung/DigitaleBildverarbeitung/Klausuren/Klausur_WS2021/images/flower_3.png", dst3)
|
||||
Reference in New Issue
Block a user