Daltonization in die Klasse eingefügt
Funktion der Daltonization in die Klasse Dyschromasie eingefügt.
This commit is contained in:
parent
638fadeb28
commit
8498500c68
@ -2,12 +2,13 @@ import numpy as np
|
|||||||
import cv2
|
import cv2
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
|
|
||||||
def createGammaLookup():
|
def createGammaLookup():
|
||||||
return np.array([removeGammaCorrection(i) for i in np.arange(0, 256)]).astype("float64")
|
return np.array([removeGammaCorrection(i) for i in np.arange(0, 256)]).astype("float64")
|
||||||
|
|
||||||
|
|
||||||
def createReverseGammaLookup():
|
def createReverseGammaLookup():
|
||||||
return np.array([applyGammaCorrection(i/255) for i in np.arange(0.0, 256.0)]).astype("uint8")
|
return np.array([applyGammaCorrection(i / 255) for i in np.arange(0.0, 256.0)]).astype("uint8")
|
||||||
|
|
||||||
|
|
||||||
def removeGammaCorrection(v):
|
def removeGammaCorrection(v):
|
||||||
@ -86,52 +87,52 @@ class Dyschromasie:
|
|||||||
|
|
||||||
return self.sim_image
|
return self.sim_image
|
||||||
|
|
||||||
|
def daltonize(self):
|
||||||
|
|
||||||
|
err2mod = np.array([[0, 0, 0], [0.7, 1, 0], [0.7, 0, 1]])
|
||||||
|
simulated_image = self.Simulate()
|
||||||
|
|
||||||
|
E = np.copy(simulated_image).astype('int32')
|
||||||
|
for i in range(self.rows):
|
||||||
|
for j in range(self.cols):
|
||||||
|
for x in range(3):
|
||||||
|
E[i, j, x] = abs(int(self.img_mat[i, j, x]) - int(simulated_image[i, j, x]))
|
||||||
|
|
||||||
|
ERR = np.zeros_like(image).astype('int32')
|
||||||
|
|
||||||
|
for i in range(self.rows):
|
||||||
|
for j in range(self.cols):
|
||||||
|
err = E[i, j, :3]
|
||||||
|
ERR[i, j, :3] = np.dot(err2mod, err)
|
||||||
|
|
||||||
|
dtpn = np.copy(image).astype('int32')
|
||||||
|
|
||||||
|
for i in range(self.rows):
|
||||||
|
for j in range(self.cols):
|
||||||
|
for x in range(3):
|
||||||
|
dtpn[i, j, x] = abs(int(ERR[i, j, x]) + int(image[i, j, x]))
|
||||||
|
|
||||||
|
for i in range(rows):
|
||||||
|
for j in range(cols):
|
||||||
|
dtpn[i, j, 0] = max(0, dtpn[i, j, 0])
|
||||||
|
dtpn[i, j, 0] = min(255, dtpn[i, j, 0])
|
||||||
|
dtpn[i, j, 1] = max(0, dtpn[i, j, 1])
|
||||||
|
dtpn[i, j, 1] = min(255, dtpn[i, j, 1])
|
||||||
|
dtpn[i, j, 2] = max(0, dtpn[i, j, 2])
|
||||||
|
dtpn[i, j, 2] = min(255, dtpn[i, j, 2])
|
||||||
|
|
||||||
|
result = dtpn.astype('uint8')
|
||||||
|
|
||||||
|
dalt = Dyschromasie(result, self.rows, self.cols, self.kanaele, self.sim_faktor, self.sim_kind)
|
||||||
|
return dalt.Simulate()
|
||||||
|
|
||||||
|
|
||||||
script_dir = sys.path[0]
|
script_dir = sys.path[0]
|
||||||
path = script_dir[:-4] + r'Beispielbilder\Fall_trees.jpg'
|
path = script_dir[:-4] + r'Beispielbilder\rot-gruen-schwaeche-test-bild.jpg'
|
||||||
image = cv2.cvtColor(cv2.imread(path), cv2.COLOR_BGR2RGB)
|
image = cv2.cvtColor(cv2.imread(path), cv2.COLOR_BGR2RGB)
|
||||||
|
|
||||||
rows, cols, kanaele = image.shape
|
rows, cols, kanaele = image.shape
|
||||||
|
|
||||||
p = Dyschromasie(image, rows, cols, kanaele, 1, 'p')
|
dalt = Dyschromasie(image, rows, cols, kanaele, 1, 'p')
|
||||||
|
cv2.imshow('Dalt_Img', cv2.cvtColor(dalt.daltonize(), cv2.COLOR_RGB2BGR))
|
||||||
simulated_image = p.Simulate()
|
|
||||||
|
|
||||||
E = np.copy(simulated_image).astype('int64')
|
|
||||||
for i in range(rows):
|
|
||||||
for j in range(cols):
|
|
||||||
for x in range(3):
|
|
||||||
E[i, j, x] = abs(int(image[i, j, x]) - int(simulated_image[i, j, x]))
|
|
||||||
|
|
||||||
ERR = np.zeros_like(image).astype('int64')
|
|
||||||
|
|
||||||
err2mod = np.array([[0,0,0],[0.7,1,0],[0.7,0,1]])
|
|
||||||
|
|
||||||
for i in range(rows):
|
|
||||||
for j in range(cols):
|
|
||||||
err = E[i,j,:3]
|
|
||||||
ERR[i,j,:3] = np.dot(err2mod, err)
|
|
||||||
|
|
||||||
dtpn = np.copy(image).astype('int64')
|
|
||||||
|
|
||||||
for i in range(rows):
|
|
||||||
for j in range(cols):
|
|
||||||
for x in range(3):
|
|
||||||
dtpn[i, j, x] = abs(int(ERR[i, j, x]) + int(image[i, j, x]))
|
|
||||||
|
|
||||||
for i in range(rows):
|
|
||||||
for j in range(cols):
|
|
||||||
dtpn[i, j, 0] = max(0, dtpn[i, j, 0])
|
|
||||||
dtpn[i, j, 0] = min(255, dtpn[i, j, 0])
|
|
||||||
dtpn[i, j, 1] = max(0, dtpn[i, j, 1])
|
|
||||||
dtpn[i, j, 1] = min(255, dtpn[i, j, 1])
|
|
||||||
dtpn[i, j, 2] = max(0, dtpn[i, j, 2])
|
|
||||||
dtpn[i, j, 2] = min(255, dtpn[i, j, 2])
|
|
||||||
|
|
||||||
result = dtpn.astype('uint8')
|
|
||||||
|
|
||||||
dalt = Dyschromasie(result,rows,cols, kanaele, 1, 'p')
|
|
||||||
dalt_p = dalt.Simulate()
|
|
||||||
|
|
||||||
cv2.imshow('Dalt_Img', cv2.cvtColor(dalt_p, cv2.COLOR_RGB2BGR))
|
|
||||||
cv2.waitKey(0)
|
cv2.waitKey(0)
|
Loading…
x
Reference in New Issue
Block a user