Skip to content

Commit

Permalink
Merge pull request #1 from jankukacka/dev
Browse files Browse the repository at this point in the history
v0.2.3
  • Loading branch information
jankukacka committed Nov 26, 2021
2 parents 9bae30f + 2300400 commit bd7fc72
Show file tree
Hide file tree
Showing 5 changed files with 381 additions and 317 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ render = imv.start(image=img)

**From command line as a standalone application.**
```
> imvmk2 [-i filename] [-c config_filename] [--gpu | --no_gpu] [--debug]
> imvmk2 [-i filename] [-c config_filename] [-g (GPU) | -ng (No GPU)] [-d (debug)]
```

## Credits
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[metadata]
name = image-viewer-mk2
author = Jan Kukacka
version = 0.2.2
version = 0.2.3
description = Image viewer for spectral images
long_description = file: README.md
long_description_content_type = text/markdown
Expand Down
30 changes: 18 additions & 12 deletions src/image_viewer_mk2/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
# Author: Jan Kukacka
# Date: 3/2021
# ------------------------------------------------------------------------------
# A simple tool for displaying of images
# run from parent directory as: python -m image_viewer_mk2.app
# App interface - processes inputs, starts GUI, returns output
# ------------------------------------------------------------------------------

import numpy as np
import happy as hp
try:
from . import view as view_
from . import model as model_
Expand All @@ -28,8 +28,8 @@ def start(file=None, image=None, **kwargs):
of shape (height, width, n_channels)
# Additional optional kwargs:
- gpu: bool. If True (default), PyTorch+GPU based rendering will be used (if
installed). If False, defaults to NumPy+CPU rendering
- gpu: bool. If True, PyTorch+GPU based rendering will be used (if
installed). If False (default), defaults to NumPy+CPU rendering
- config_filename: Filename of the config to apply.
- config: Dictionary with config to apply.
- return_config: bool. If True, returns also the config dict. False by default.
Expand All @@ -39,9 +39,9 @@ def start(file=None, image=None, **kwargs):
- (config dictionary. Only if return_config was set to True.)
'''

gpu = True
model_kwargs = {'use_gpu': False}
if 'gpu' in kwargs:
gpu = kwargs['gpu']
model_kwargs['use_gpu'] = kwargs['gpu']

config = None
if 'config_filename' in kwargs:
Expand All @@ -52,23 +52,29 @@ def start(file=None, image=None, **kwargs):
view_kwargs = {}
if 'debug' in kwargs:
view_kwargs['debug'] = kwargs['debug']
model_kwargs['debug'] = kwargs['debug']

return_config = False
if 'return_config' in kwargs:
return_config = kwargs['return_config']

view = view_.View(**view_kwargs)
with model_.Model(use_gpu=gpu) as model:
with model_.Model(**model_kwargs) as model:
presenter = presenter_.Presenter(view, model)

if file is not None:
model.filename = file

if image is not None:
model.update_image(image)

if config is not None:
model.load(config)
if file is not None:
model.filename = file

## Model loading has to wait for image loading io to finish
def img_onload(event):
if event.action == 'propertyChanged' and event.propertyName == 'render':
if config is not None:
model.load(config)
view.after(1, lambda: model.detach(img_onload))
model.attach(img_onload)

presenter.mainloop()
result = np.array(model.render)
Expand Down
Loading

0 comments on commit bd7fc72

Please sign in to comment.