comparison #3

Merged
s444498 merged 4 commits from comparison into main 2023-01-29 23:02:14 +01:00
3 changed files with 9 additions and 3 deletions
Showing only changes of commit 16e03179ee - Show all commits

View File

@ -1,6 +1,6 @@
import cv2 import cv2
import numpy as np import numpy as np
from skimage.metrics import structural_similarity
def histogram_comparison(data_a: np.ndarray, data_b: np.ndarray) -> dict: def histogram_comparison(data_a: np.ndarray, data_b: np.ndarray) -> dict:
hsv_a = cv2.cvtColor(data_a, cv2.COLOR_BGR2HSV) hsv_a = cv2.cvtColor(data_a, cv2.COLOR_BGR2HSV)
@ -23,3 +23,7 @@ def histogram_comparison(data_a: np.ndarray, data_b: np.ndarray) -> dict:
'intersection': cv2.compareHist(hist_a, hist_b, 2), 'intersection': cv2.compareHist(hist_a, hist_b, 2),
'bhattacharyya-distance': cv2.compareHist(hist_a, hist_b, 3), 'bhattacharyya-distance': cv2.compareHist(hist_a, hist_b, 3),
} }
def structural_similarity_index(data_a: np.ndarray, data_b: np.ndarray) -> float:
return structural_similarity(cv2.cvtColor(data_a, cv2.COLOR_BGR2GRAY), cv2.cvtColor(data_b, cv2.COLOR_BGR2GRAY))

View File

@ -3,7 +3,7 @@ import cv2
import numpy as np import numpy as np
import matplotlib.pyplot as plt import matplotlib.pyplot as plt
from comparisons import histogram_comparison from comparisons import histogram_comparison, structural_similarity_index
# Allows imports from the style transfer submodule # Allows imports from the style transfer submodule
sys.path.append('DCT-Net') sys.path.append('DCT-Net')
@ -44,6 +44,7 @@ def compare_with_anime_characters(data: np.ndarray) -> int:
data_rescaled = cv2.resize(data, example_face.shape[:2]) data_rescaled = cv2.resize(data, example_face.shape[:2])
plot_two_images(example_face, data_rescaled) plot_two_images(example_face, data_rescaled)
print(histogram_comparison(data_rescaled, example_face)) print(histogram_comparison(data_rescaled, example_face))
print(f'structural-similarity: {structural_similarity_index(data_rescaled, example_face)}')
def transfer_to_anime(img: np.ndarray): def transfer_to_anime(img: np.ndarray):

View File

@ -7,4 +7,5 @@ beautifulsoup4==4.11.1
lxml==4.9.2 lxml==4.9.2
opencv-python==4.7.0.68 opencv-python==4.7.0.68
torch==1.13.1 torch==1.13.1
matplotlib==3.6.3 matplotlib==3.6.3
scikit-image==0.19.3