-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3729652
commit db1e7fa
Showing
9 changed files
with
369 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,6 +16,7 @@ scipy==1.9.3 | |
notebook | ||
twine | ||
pytest | ||
pytest-qt==4.4.0 | ||
sphinx | ||
nbsphinx | ||
sphinx_gallery | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
# Author: Matt Clifford <[email protected]> | ||
# License: BSD 3-Clause License | ||
|
||
import pytest | ||
from PyQt6 import QtTest, QtWidgets, QtCore | ||
from pytestqt.plugin import QtBot, _close_widgets | ||
import IQM_Vis | ||
import threading | ||
|
||
|
||
def get_UI(): | ||
app = IQM_Vis.make_UI(test=True) | ||
return app | ||
|
||
|
||
# building and closing function of UI for testing | ||
@pytest.fixture | ||
def build_IQM_Vis(): | ||
|
||
test_window = get_UI() | ||
qtbotbis = QtBot(test_window.window) | ||
|
||
yield test_window, qtbotbis | ||
|
||
# need to handle the closing dialog | ||
def handle_dialog(): | ||
messagebox = QtWidgets.QApplication.activeWindow() | ||
yes_button = messagebox.button( | ||
QtWidgets.QMessageBox.StandardButton.Yes) | ||
qtbotbis.mouseClick( | ||
yes_button, QtCore.Qt.MouseButton.LeftButton, delay=1) | ||
|
||
QtCore.QTimer.singleShot(100, handle_dialog) | ||
|
||
# test_window.window.quit() | ||
test_window.window.main.close() | ||
|
||
|
||
def test_build_1(build_IQM_Vis): | ||
test_window, _ = build_IQM_Vis | ||
assert test_window.showing == True | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
# Author: Matt Clifford <[email protected]> | ||
# License: BSD 3-Clause License | ||
|
||
import pytest | ||
from PyQt6 import QtTest, QtWidgets, QtCore | ||
from pytestqt.plugin import QtBot, _close_widgets | ||
import IQM_Vis | ||
|
||
|
||
def get_UI(): | ||
image1 = IQM_Vis.examples.images.IMAGE1 | ||
image2 = IQM_Vis.examples.images.IMAGE2 | ||
images = [image1, image2] | ||
print(f'Images files: {images}') | ||
|
||
MAE = IQM_Vis.IQMs.MAE() | ||
MSE = IQM_Vis.IQMs.MSE() | ||
SSIM = IQM_Vis.IQMs.SSIM() | ||
|
||
metrics = {'MAE': MAE, | ||
'MSE': MSE, | ||
'1-SSIM': SSIM} | ||
|
||
MSE_image = IQM_Vis.IQMs.MSE(return_image=True) | ||
SSIM_image = IQM_Vis.IQMs.SSIM(return_image=True) | ||
metric_images = {'MSE': MSE_image, | ||
'1-SSIM': SSIM_image} | ||
|
||
rotation = IQM_Vis.transforms.rotation | ||
blur = IQM_Vis.transforms.blur | ||
brightness = IQM_Vis.transforms.brightness | ||
jpeg_compression = IQM_Vis.transforms.jpeg_compression | ||
|
||
transformations = { | ||
# normal input | ||
'rotation': {'min': -180, 'max': 180, 'function': rotation}, | ||
# only odd ints since it's a kernel | ||
'blur': {'min': 1, 'max': 41, 'function': blur, 'normalise': 'odd'}, | ||
# float values | ||
'brightness': {'min': -1.0, 'max': 1.0, 'function': brightness}, | ||
# non zero inital value | ||
'jpg comp.': {'min': 1, 'max': 100, 'function': jpeg_compression, 'init_value': 100}, | ||
} | ||
|
||
test_app = IQM_Vis.make_UI(transformations=transformations, | ||
image_list=images, | ||
metrics=metrics, | ||
metric_images=metric_images, | ||
test=True) | ||
return test_app | ||
|
||
|
||
# building and closing function of UI for testing | ||
@pytest.fixture | ||
def build_IQM_Vis(): | ||
|
||
test_window = get_UI() | ||
qtbotbis = QtBot(test_window.window) | ||
|
||
yield test_window, qtbotbis | ||
|
||
# need to handle the closing dialog | ||
def handle_dialog(): | ||
messagebox = QtWidgets.QApplication.activeWindow() | ||
yes_button = messagebox.button( | ||
QtWidgets.QMessageBox.StandardButton.Yes) | ||
qtbotbis.mouseClick( | ||
yes_button, QtCore.Qt.MouseButton.LeftButton, delay=1) | ||
|
||
QtCore.QTimer.singleShot(100, handle_dialog) | ||
|
||
# test_window.window.quit() | ||
test_window.window.main.close() | ||
|
||
|
||
def test_build_2(build_IQM_Vis): | ||
test_window, _ = build_IQM_Vis | ||
assert test_window.showing == True | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
# Author: Matt Clifford <[email protected]> | ||
# License: BSD 3-Clause License | ||
|
||
import numpy as np | ||
import pytest | ||
from PyQt6 import QtTest, QtWidgets, QtCore | ||
from pytestqt.plugin import QtBot | ||
import IQM_Vis | ||
|
||
def custom_MAE_function(im_ref, im_comp, **kwargs): | ||
L1 = np.abs(im_ref - im_comp) | ||
return L1.mean() | ||
|
||
|
||
class custom_MAE_class: | ||
def __init__(self, att=0): | ||
self.att = att | ||
|
||
def __call__(self, im_ref, im_comp, **kwargs): | ||
L1 = np.abs(im_ref - im_comp) | ||
return L1.mean() | ||
|
||
|
||
def dummy_args(im_ref, im_comp, param1=0, **kwargs): | ||
# now we can use param here | ||
score = custom_MAE_function(im_ref, im_comp) | ||
return score + param1 | ||
|
||
|
||
def custom_brightness(image, value=0): | ||
return np.clip(image + value, 0, 1) | ||
|
||
|
||
def get_UI(): | ||
metrics = {'MAE function': custom_MAE_function, | ||
'MAE class': custom_MAE_class(), | ||
'dummy args': dummy_args} | ||
params = {'param1': {'min': -1.0, 'max': 1.0, 'init_value': 0}} | ||
transformations = {'brightness': {'min': -1.0, | ||
'max': 1.0, 'function': custom_brightness}} | ||
|
||
images = ['/home/matt/datasets/kodak/kodim01.png', | ||
'/home/matt/datasets/kodak/kodim02.png'] | ||
|
||
test_app = IQM_Vis.make_UI(transformations=transformations, | ||
image_list=images, | ||
metrics=metrics, | ||
metric_params=params, | ||
test=True) | ||
return test_app | ||
|
||
|
||
# building and closing function of UI for testing | ||
@pytest.fixture | ||
def build_IQM_Vis(): | ||
|
||
test_window = get_UI() | ||
qtbotbis = QtBot(test_window.window) | ||
|
||
yield test_window, qtbotbis | ||
|
||
# need to handle the closing dialog | ||
def handle_dialog(): | ||
messagebox = QtWidgets.QApplication.activeWindow() | ||
yes_button = messagebox.button( | ||
QtWidgets.QMessageBox.StandardButton.Yes) | ||
qtbotbis.mouseClick( | ||
yes_button, QtCore.Qt.MouseButton.LeftButton, delay=1) | ||
|
||
QtCore.QTimer.singleShot(100, handle_dialog) | ||
|
||
# test_window.window.quit() | ||
test_window.window.main.close() | ||
|
||
|
||
@pytest.fixture | ||
def test_build_3(build_IQM_Vis): | ||
test_window, _ = build_IQM_Vis | ||
assert test_window.showing == True | ||
|
||
|
||
def test_3(test_build_3): | ||
return |
Oops, something went wrong.