|
|
@@ -2,12 +2,13 @@ import numpy as np |
|
|
|
import cv2
|
|
|
|
import sys
|
|
|
|
|
|
|
|
|
|
|
|
def createGammaLookup():
|
|
|
|
return np.array([removeGammaCorrection(i) for i in np.arange(0, 256)]).astype("float64")
|
|
|
|
|
|
|
|
|
|
|
|
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):
|
|
|
@@ -86,52 +87,52 @@ class Dyschromasie: |
|
|
|
|
|
|
|
return self.sim_image
|
|
|
|
|
|
|
|
def daltonize(self):
|
|
|
|
|
|
|
|
script_dir = sys.path[0]
|
|
|
|
path = script_dir[:-4] + r'Beispielbilder\Fall_trees.jpg'
|
|
|
|
image = cv2.cvtColor(cv2.imread(path), cv2.COLOR_BGR2RGB)
|
|
|
|
|
|
|
|
rows, cols, kanaele = image.shape
|
|
|
|
err2mod = np.array([[0, 0, 0], [0.7, 1, 0], [0.7, 0, 1]])
|
|
|
|
simulated_image = self.Simulate()
|
|
|
|
|
|
|
|
p = Dyschromasie(image, rows, cols, kanaele, 1, 'p')
|
|
|
|
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]))
|
|
|
|
|
|
|
|
simulated_image = p.Simulate()
|
|
|
|
ERR = np.zeros_like(image).astype('int32')
|
|
|
|
|
|
|
|
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]))
|
|
|
|
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)
|
|
|
|
|
|
|
|
ERR = np.zeros_like(image).astype('int64')
|
|
|
|
dtpn = np.copy(image).astype('int32')
|
|
|
|
|
|
|
|
err2mod = np.array([[0,0,0],[0.7,1,0],[0.7,0,1]])
|
|
|
|
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):
|
|
|
|
err = E[i,j,:3]
|
|
|
|
ERR[i,j,:3] = np.dot(err2mod, err)
|
|
|
|
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])
|
|
|
|
|
|
|
|
dtpn = np.copy(image).astype('int64')
|
|
|
|
result = dtpn.astype('uint8')
|
|
|
|
|
|
|
|
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]))
|
|
|
|
dalt = Dyschromasie(result, self.rows, self.cols, self.kanaele, self.sim_faktor, self.sim_kind)
|
|
|
|
return dalt.Simulate()
|
|
|
|
|
|
|
|
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')
|
|
|
|
script_dir = sys.path[0]
|
|
|
|
path = script_dir[:-4] + r'Beispielbilder\rot-gruen-schwaeche-test-bild.jpg'
|
|
|
|
image = cv2.cvtColor(cv2.imread(path), cv2.COLOR_BGR2RGB)
|
|
|
|
|
|
|
|
dalt = Dyschromasie(result,rows,cols, kanaele, 1, 'p')
|
|
|
|
dalt_p = dalt.Simulate()
|
|
|
|
rows, cols, kanaele = image.shape
|
|
|
|
|
|
|
|
cv2.imshow('Dalt_Img', cv2.cvtColor(dalt_p, cv2.COLOR_RGB2BGR))
|
|
|
|
dalt = Dyschromasie(image, rows, cols, kanaele, 1, 'p')
|
|
|
|
cv2.imshow('Dalt_Img', cv2.cvtColor(dalt.daltonize(), cv2.COLOR_RGB2BGR))
|
|
|
|
cv2.waitKey(0) |