Initial commit with project files
This commit is contained in:
24
3_Signalorientierte_Bildverarbeitung/ü6/README.md
Normal file
24
3_Signalorientierte_Bildverarbeitung/ü6/README.md
Normal file
@@ -0,0 +1,24 @@
|
||||
# Übung 6: Unitäre Transformation
|
||||
|
||||
In dem Skript [a.py](a.py) wird das Bild von Lena eingeladen.
|
||||
|
||||

|
||||
|
||||
## Aufgabe a) Haar-Transformation
|
||||
Das Bild soll in die hohen tiefen Frequenzen mithilfe der Haar-Transformation zerlegt werden.
|
||||
Erstellen Sie dafür eine Haar-Koeffizientnmatrix der Größe 512x512 mit der Berechnungsvorschrift
|
||||
|
||||
<img src="https://latex.codecogs.com/svg.image?H^{(N)}_{ij}:=\begin{cases}\frac{1}{\sqrt{2}},&space;&&space;\text{if}\&space;i\leq&space;\frac{N}{2},&space;j\in&space;\{2i-1,2i&space;\}&space;&space;\\\frac{1}{\sqrt{2}},&space;&&space;\text{if}\&space;i>\frac{N}{2},&space;j=2(i-\frac{N}{2})-1&space;\\-\frac{1}{\sqrt{2}},&space;&&space;\text{if}\&space;i>\frac{N}{2},&space;j=2(i-\frac{N}{2})\end{cases}" title="" />
|
||||
|
||||
und wenden Sie diese auf das Bild mithilfe von
|
||||
|
||||
<img src="https://latex.codecogs.com/svg.image?I'=HI">
|
||||
|
||||
an. Zeigen Sie das Bild, und geben Sie einige interessante Koeffizienten aus H an. Prüfen Sie Ihre Berechnungen,
|
||||
indem Sie die Rücktransformation mithilfe von
|
||||
|
||||
<img src="https://latex.codecogs.com/svg.image?I=H^T(HI)">
|
||||
|
||||
anwenden und prüfen, ob Änderungen im Bild vorhanden sind.
|
||||
|
||||
Sie finden die Musterlösung in der Datei [l_a.py](l_a.py).
|
||||
33
3_Signalorientierte_Bildverarbeitung/ü6/a.py
Normal file
33
3_Signalorientierte_Bildverarbeitung/ü6/a.py
Normal file
@@ -0,0 +1,33 @@
|
||||
import cv2
|
||||
import numpy as np
|
||||
|
||||
normal = cv2.imread("../../data/lena.png", cv2.IMREAD_GRAYSCALE)
|
||||
|
||||
|
||||
def valid_rows(N):
|
||||
n = np.log2(N)
|
||||
n = np.ceil(n)
|
||||
N = np.power(2, n)
|
||||
return N
|
||||
|
||||
|
||||
def create_H(m, N):
|
||||
...
|
||||
|
||||
''' Reshape to valid resolution '''
|
||||
N, m = normal.shape
|
||||
new_N = valid_rows(N)
|
||||
print("Original Resolution:", m, "x", N)
|
||||
print("New Resolution:", m, "x", new_N)
|
||||
if N != new_N:
|
||||
_ = np.zeros((new_N, m))
|
||||
_[:N, :m] = normal
|
||||
normal = _
|
||||
|
||||
|
||||
|
||||
|
||||
''' Show images '''
|
||||
cv2.imshow("normal", normal)
|
||||
|
||||
cv2.waitKey()
|
||||
60
3_Signalorientierte_Bildverarbeitung/ü6/l_a.py
Normal file
60
3_Signalorientierte_Bildverarbeitung/ü6/l_a.py
Normal file
@@ -0,0 +1,60 @@
|
||||
import cv2
|
||||
import numpy as np
|
||||
|
||||
normal = cv2.imread("../../data/lena.png", cv2.IMREAD_GRAYSCALE)
|
||||
|
||||
|
||||
def valid_rows(N):
|
||||
n = np.log2(N)
|
||||
n = np.ceil(n)
|
||||
N = np.power(2, n)
|
||||
return N
|
||||
|
||||
|
||||
def create_H(m, N):
|
||||
"""
|
||||
m: Columns
|
||||
n: Rows
|
||||
"""
|
||||
H = np.zeros((int(N), int(m)))
|
||||
for i in range(1, int(N) + 1):
|
||||
for j in range(1, int(m) + 1):
|
||||
if i <= (N/2):
|
||||
if j == (2*i -1) or j == 2*i:
|
||||
H[i-1,j-1] = 1 / np.sqrt(2)
|
||||
else:
|
||||
#print(j, i)
|
||||
if j == (2 * (i - N/2) - 1):
|
||||
H[i-1,j-1] = 1 / np.sqrt(2)
|
||||
elif j == (2 * (i - N/2)):
|
||||
H[i-1,j-1] = -1 / np.sqrt(2)
|
||||
return H
|
||||
|
||||
''' Reshape to valid resolution '''
|
||||
N, m = normal.shape
|
||||
new_N = valid_rows(N)
|
||||
print("Original Resolution:", m, "x", N)
|
||||
print("New Resolution:", m, "x", new_N)
|
||||
if N != new_N:
|
||||
_ = np.zeros((new_N, m))
|
||||
_[:N, :m] = normal
|
||||
normal = _
|
||||
|
||||
''' Get Haar-Matrix '''
|
||||
H = create_H(m, new_N)
|
||||
print(H[0:5, 0:5])
|
||||
print(H[256:261, 0:5])
|
||||
|
||||
''' Filter with HxI'''
|
||||
haar = np.matmul(H, normal)
|
||||
|
||||
''' Invert Filter '''
|
||||
haar_inv = np.matmul(np.transpose(H), haar)
|
||||
|
||||
''' Show images '''
|
||||
cv2.imshow("normal", normal)
|
||||
cv2.imshow("haar", haar / 255)
|
||||
cv2.imshow("haar_inv", haar_inv / 255)
|
||||
print("Difference:", np.sum(np.abs(normal-haar_inv)))
|
||||
|
||||
cv2.waitKey()
|
||||
Reference in New Issue
Block a user