Skip to content

Commit

Permalink
Merge branch 'demo'
Browse files Browse the repository at this point in the history
  • Loading branch information
mattclifford1 committed Oct 9, 2023
2 parents 4215141 + 2836d76 commit 6323e3e
Show file tree
Hide file tree
Showing 41 changed files with 443 additions and 164 deletions.
10 changes: 9 additions & 1 deletion IQM_Vis/UI/layout.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,16 @@ def _init_generic_layout(self):
for key in self.sliders['transforms']:
tran_layout = QHBoxLayout()
tran_layout.addWidget(self.widget_controls['slider'][key]['label'])
tran_layout.addWidget(self.widget_controls['slider'][key]['data'])
tran_layout.addWidget(self.widget_controls['slider'][key]['value'])
_min = QHBoxLayout()
_min.addWidget(self.sliders['transforms'][key]['min_edit'])
_min.addStretch(0)
tran_layout.addLayout(_min)
tran_layout.addWidget(self.widget_controls['slider'][key]['data'])
_max = QHBoxLayout()
_max.addWidget(self.sliders['transforms'][key]['max_edit'])
_max.addStretch(0)
tran_layout.addLayout(_max)
image_controls.addLayout(tran_layout)
image_controls.addStretch()
reset_button = QHBoxLayout()
Expand Down
49 changes: 41 additions & 8 deletions IQM_Vis/UI/widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import numpy as np
from PyQt6.QtWidgets import QPushButton, QLabel, QSlider, QCheckBox, QComboBox, QLineEdit
from PyQt6.QtGui import QIntValidator, QDoubleValidator, QPalette
from PyQt6.QtGui import QIntValidator, QDoubleValidator
from PyQt6.QtCore import Qt, pyqtSlot

import IQM_Vis
Expand Down Expand Up @@ -216,20 +216,46 @@ def _init_sliders(self, sliders_dict, info_dict, param_group):
sliders_dict[key]['function'] = info_item['function']
if 'init_value' not in info_item.keys():
info_item['init_value'] = 0
sliders_dict[key]['init_value_store'] = info_item['init_value']
if 'values' in info_item.keys():
sliders_dict[key]['values'] = info_item['values']
else:
if 'num_values' not in info_item.keys():
info_item['num_values'] = 41 # make default value for steps in slider range
sliders_dict[key]['values'] = np.linspace(info_item['min'], info_item['max'], info_item['num_values'])
# see if we need to make odd numbers (for use with kernel sizes)
if 'normalise' in info_item.keys():
if info_item['normalise'] == 'odd':
sliders_dict[key]['values'] = np.round(sliders_dict[key]['values'])
sliders_dict[key]['values'] = sliders_dict[key]['values'][sliders_dict[key]['values']%2 == 1]
info_item['num_values'] = len(sliders_dict[key]['values'])
# get ind of the initial value to set the slider at
sliders_dict[key]['init_ind'] = np.searchsorted(sliders_dict[key]['values'], info_item['init_value'], side='left')
# store for if min/max changed later
sliders_dict[key]['normalise'] = info_item['normalise']
self.make_slider_range(sliders_dict, key, info_item['min'], info_item['max'], info_item['num_values'])

# store num steps used
sliders_dict[key]['default_num_steps'] = len(sliders_dict[key]['values'])
# make min/max inputs
sliders_dict[key]['min_edit'] = QLineEdit()
# sliders_dict[key]['min_edit'].setStretch(0)
sliders_dict[key]['min_edit'].setValidator(QDoubleValidator())
sliders_dict[key]['min_edit'].setText(f"{min(sliders_dict[key]['values'])}")
sliders_dict[key]['min_edit'].editingFinished.connect(partial(self.edit_slider_vals, sliders_dict, key, info_item))
sliders_dict[key]['min_edit'].editingFinished.connect(partial(self.generic_value_change, key, param_group))
sliders_dict[key]['min_edit'].editingFinished.connect(self.display_images)
sliders_dict[key]['max_edit'] = QLineEdit()
sliders_dict[key]['max_edit'].setValidator(QDoubleValidator())
sliders_dict[key]['max_edit'].setText(f"{max(sliders_dict[key]['values'])}")
sliders_dict[key]['max_edit'].editingFinished.connect(partial(self.edit_slider_vals, sliders_dict, key, info_item))
sliders_dict[key]['max_edit'].editingFinished.connect(partial(self.generic_value_change, key, param_group))
sliders_dict[key]['max_edit'].editingFinished.connect(self.display_images)

def make_slider_range(self, sliders_dict, key, _min, _max, num_steps=None):
if num_steps == None:
num_steps = sliders_dict[key]['default_num_steps']
sliders_dict[key]['values'] = np.linspace(_min, _max, num_steps)
# see if we need to make odd numbers (for use with kernel sizes)
if 'normalise' in sliders_dict[key].keys():
if sliders_dict[key]['normalise'] == 'odd':
sliders_dict[key]['values'] = np.round(sliders_dict[key]['values'])
sliders_dict[key]['values'] = sliders_dict[key]['values'][sliders_dict[key]['values']%2 == 1]
# get ind of the initial value to set the slider at
sliders_dict[key]['init_ind'] = np.searchsorted(sliders_dict[key]['values'], sliders_dict[key]['init_value_store'], side='left')

def _init_image_settings(self):
self.widget_settings = {}
Expand Down Expand Up @@ -340,6 +366,13 @@ def generic_value_change(self, key, param_group):
self.params_from_sliders[param_group][key] = self.sliders[param_group][key]['values'][index]
self.display_slider_num(key, param_group) # display the new value ont UI

def edit_slider_vals(self, sliders_dict, key, info_item):
_min = float(sliders_dict[key]['min_edit'].text())
_max = float(sliders_dict[key]['max_edit'].text())
self.make_slider_range(sliders_dict, key, _min, _max)
info_item['min'] = _min
info_item['max'] = _max

def display_slider_num(self, key, param_group, disp_len=5):
# display the updated value
value_str = str(self.params_from_sliders[param_group][key])
Expand Down
31 changes: 31 additions & 0 deletions IQM_Vis/examples/new_api.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
''' KODAK dataset '''
import os
import glob
import IQM_Vis

def run():
# file_path = os.path.dirname(os.path.abspath(__file__))
# dir = os.path.join(file_path, 'KODAK-dataset')

dir = os.path.join(os.path.expanduser('~'), 'Desktop', 'demo')
image_list = glob.glob(os.path.join(dir, '*'))
# remove and folders
image_list = [f for f in image_list if os.path.isfile(f)]
image_list.sort()

metrs = IQM_Vis.metrics.get_all_metrics()
metrs.pop('1-MS_SSIM')

metr_ims = IQM_Vis.metrics.get_all_metric_images()
metr_ims.pop('MSE')

IQM_Vis.make_UI(transformations=IQM_Vis.transformations.get_all_transforms(),
image_list=image_list,
metrics=metrs,
metric_images=metr_ims,
restrict_options=3
)
IQM_Vis.make_UI()

if __name__ == '__main__':
run()
8 changes: 8 additions & 0 deletions IQM_Vis/ui_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import IQM_Vis
from IQM_Vis.UI.main import make_app
from IQM_Vis.utils import image_utils
from IQM_Vis.examples.images import DEFAULT_IMAGES
import matplotlib
matplotlib.use("Qt5Agg")
except ImportError:
Expand All @@ -24,13 +25,20 @@ class make_UI:
def __init__(self,
data_store=None,
transformations=None,
image_list: list=DEFAULT_IMAGES,
metrics: dict={},
metric_images: dict={},
metrics_info_format: str='graph',
metrics_avg_graph: bool=True,
metric_params: dict={},
default_save_dir=IQM_Vis.utils.save_utils.DEFAULT_SAVE_DIR,
restrict_options=None,
num_steps_range=11,
debug=False):
if data_store == None:
data_store = IQM_Vis.dataset_holder(image_list,
metrics,
metric_images)
self.data_store = data_store
self.transformations = transformations
self.metrics_info_format = metrics_info_format
Expand Down
8 changes: 8 additions & 0 deletions docs/IQM_Vis.examples.rst
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,14 @@ IQM\_Vis.examples.multiple module
:undoc-members:
:show-inheritance:

IQM\_Vis.examples.new\_api module
---------------------------------

.. automodule:: IQM_Vis.examples.new_api
:members:
:undoc-members:
:show-inheritance:

IQM\_Vis.examples.simple module
-------------------------------

Expand Down
Binary file modified docs/_build/doctrees/IQM_Vis.UI.doctree
Binary file not shown.
Binary file modified docs/_build/doctrees/IQM_Vis.doctree
Binary file not shown.
Binary file modified docs/_build/doctrees/IQM_Vis.examples.doctree
Binary file not shown.
Binary file modified docs/_build/doctrees/environment.pickle
Binary file not shown.
Binary file modified docs/_build/doctrees/getting_started.doctree
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -138,27 +138,7 @@
"metadata": {},
"source": [
"## Putting it all together\n",
"First we need to bundle up the images and metrics in a datastore"
]
},
{
"cell_type": "code",
"execution_count": 6,
"id": "171060e6",
"metadata": {},
"outputs": [],
"source": [
"data = IQM_Vis.dataset_holder(images,\n",
" metrics,\n",
" metric_images)"
]
},
{
"cell_type": "markdown",
"id": "cb8a3088",
"metadata": {},
"source": [
"Now we need to pass everything to the UI maker"
"We need to pass everything to the UI maker"
]
},
{
Expand All @@ -168,8 +148,10 @@
"metadata": {},
"outputs": [],
"source": [
"IQM_Vis.make_UI(data,\n",
" transformations)"
"IQM_Vis.make_UI(transformations=transformations,\n",
" image_list=images,\n",
" metrics=metrics,\n",
" metric_images=metric_images)"
]
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,10 +197,10 @@
"source": [
"images = ['/home/matt/datasets/kodak/kodim01.png', \n",
" '/home/matt/datasets/kodak/kodim02.png']\n",
"data = IQM_Vis.dataset_holder(images,\n",
" metrics)\n",
"IQM_Vis.make_UI(data,\n",
" transformations,\n",
"\n",
"IQM_Vis.make_UI(transformations=transformations,\n",
" image_list=images,\n",
" metrics=metrics,\n",
" metric_params=params)"
]
},
Expand Down
Binary file modified docs/_build/doctrees/notebooks/Tutorial_2-Customisation.doctree
Binary file not shown.
Binary file not shown.
10 changes: 10 additions & 0 deletions docs/_build/html/IQM_Vis.UI.html
Original file line number Diff line number Diff line change
Expand Up @@ -637,6 +637,11 @@ <h2>Submodules<a class="headerlink" href="#submodules" title="Permalink to this
<span class="sig-name descname"><span class="pre">display_slider_num</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">key</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">param_group</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">disp_len</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">5</span></span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/IQM_Vis/UI/widgets.html#widgets.display_slider_num"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#IQM_Vis.UI.widgets.widgets.display_slider_num" title="Permalink to this definition"></a></dt>
<dd></dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="IQM_Vis.UI.widgets.widgets.edit_slider_vals">
<span class="sig-name descname"><span class="pre">edit_slider_vals</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">sliders_dict</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">key</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">info_item</span></span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/IQM_Vis/UI/widgets.html#widgets.edit_slider_vals"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#IQM_Vis.UI.widgets.widgets.edit_slider_vals" title="Permalink to this definition"></a></dt>
<dd></dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="IQM_Vis.UI.widgets.widgets.enable_settings_button">
<span class="sig-name descname"><span class="pre">enable_settings_button</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="_modules/IQM_Vis/UI/widgets.html#widgets.enable_settings_button"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#IQM_Vis.UI.widgets.widgets.enable_settings_button" title="Permalink to this definition"></a></dt>
Expand All @@ -658,6 +663,11 @@ <h2>Submodules<a class="headerlink" href="#submodules" title="Permalink to this
<span class="sig-name descname"><span class="pre">launch_experiment</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="_modules/IQM_Vis/UI/widgets.html#widgets.launch_experiment"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#IQM_Vis.UI.widgets.widgets.launch_experiment" title="Permalink to this definition"></a></dt>
<dd></dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="IQM_Vis.UI.widgets.widgets.make_slider_range">
<span class="sig-name descname"><span class="pre">make_slider_range</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">sliders_dict</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">key</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">_min</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">_max</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">num_steps</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/IQM_Vis/UI/widgets.html#widgets.make_slider_range"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#IQM_Vis.UI.widgets.widgets.make_slider_range" title="Permalink to this definition"></a></dt>
<dd></dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="IQM_Vis.UI.widgets.widgets.reset_slider_group">
<span class="sig-name descname"><span class="pre">reset_slider_group</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">param_group</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">redo_plots</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">False</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">display_images</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">True</span></span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/IQM_Vis/UI/widgets.html#widgets.reset_slider_group"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#IQM_Vis.UI.widgets.widgets.reset_slider_group" title="Permalink to this definition"></a></dt>
Expand Down
9 changes: 9 additions & 0 deletions docs/_build/html/IQM_Vis.examples.html
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,15 @@ <h2>Submodules<a class="headerlink" href="#submodules" title="Permalink to this
<span class="sig-prename descclassname"><span class="pre">IQM_Vis.examples.multiple.</span></span><span class="sig-name descname"><span class="pre">run</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="_modules/IQM_Vis/examples/multiple.html#run"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#IQM_Vis.examples.multiple.run" title="Permalink to this definition"></a></dt>
<dd></dd></dl>

</section>
<section id="module-IQM_Vis.examples.new_api">
<span id="iqm-vis-examples-new-api-module"></span><h2>IQM_Vis.examples.new_api module<a class="headerlink" href="#module-IQM_Vis.examples.new_api" title="Permalink to this headline"></a></h2>
<p>KODAK dataset</p>
<dl class="py function">
<dt class="sig sig-object py" id="IQM_Vis.examples.new_api.run">
<span class="sig-prename descclassname"><span class="pre">IQM_Vis.examples.new_api.</span></span><span class="sig-name descname"><span class="pre">run</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="_modules/IQM_Vis/examples/new_api.html#run"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#IQM_Vis.examples.new_api.run" title="Permalink to this definition"></a></dt>
<dd></dd></dl>

</section>
<section id="module-IQM_Vis.examples.simple">
<span id="iqm-vis-examples-simple-module"></span><h2>IQM_Vis.examples.simple module<a class="headerlink" href="#module-IQM_Vis.examples.simple" title="Permalink to this headline"></a></h2>
Expand Down
Loading

0 comments on commit 6323e3e

Please sign in to comment.