Skip to content

Commit

Permalink
v0.2.2. Repository rehaul, application now supports build, distributi…
Browse files Browse the repository at this point in the history
…on and install.
  • Loading branch information
jankukacka committed Nov 11, 2021
1 parent d937c4c commit 9bae30f
Show file tree
Hide file tree
Showing 37 changed files with 368 additions and 222 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
*.pyc
__pycache__/
dist/
test_data/
*.egg-info/
7 changes: 7 additions & 0 deletions LICENSE.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Copyright 2021, Jan Kukačka

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
2 changes: 2 additions & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
include src/image_viewer_mk2/resources/*
include README.md
12 changes: 0 additions & 12 deletions ObservableCollections/event.py

This file was deleted.

36 changes: 27 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,23 +1,41 @@
# image_viewer_mk2
Simple image viewer
# Image viewer mk2
Viewer for spectral images, in particular suitable from multispectral optoacoustic tomography.

## Dependencies
![Screenshot of the image viewer.](doc/screenshot.png)

**Non-standard libraries**: happy

**Standard libraries**: PIL, matplotlib, numpy, (optional: PyTorch, pywin32)
## Installation

```
pip install image-viewer-mk2
```

Additional dependencies must be installed separately: `happy` (currently not publicly available), optional: `PyTorch` (for GPU-based rendering), `pywin32` (Windows clipboard functionality)

## Usage

From python script
**From within python scripts and interactive sessions.** Image viewer returns the rendered image back so that it can be further used inside the script.
```
import image_viewer_mk2.app as imv
img = np.zeros((height, width, channels))
imv.main(image=img)
render = imv.start(image=img)
```

**From command line as a standalone application.**
```
> imvmk2 [-i filename] [-c config_filename] [--gpu | --no_gpu] [--debug]
```

From command line
## Credits
This software reuses code and icons produced by: cilame, Benjamin Johnson, Remin Emonet, Icon home, Gregor Cresnar, Freepik, Google, and Pancracysdh

## License

The software is provided under the [MIT open license](LICENSE.txt).

## Citation
If you use this software for your research, please cite it as:
```
> python -m image_viewer_mk2.app [filename]
Kukačka, Jan (2021). Image Viewer MK2 (v0.2.1) [Computer software]. https://github.com/jankukacka/image_viewer_mk2
```
Binary file added doc/screenshot.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 6 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[build-system]
requires = [
"setuptools>=42",
"wheel"
]
build-backend = "setuptools.build_meta"
35 changes: 35 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
[metadata]
name = image-viewer-mk2
author = Jan Kukacka
version = 0.2.2
description = Image viewer for spectral images
long_description = file: README.md
long_description_content_type = text/markdown

url = https://github.com/jankukacka/image_viewer_mk2
license = MIT
classifiers =
Programming Language :: Python :: 3
Programming Language :: Python :: 3.7
License :: OSI Approved :: MIT License
Operating System :: OS Independent

[options]
package_dir =
= src
packages=find:
python_requires = >=3.7

install_requires =
matplotlib
numpy
Pillow

include_package_data = True

[options.packages.find]
where = src

[options.entry_points]
console_scripts =
imvmk2 = image_viewer_mk2.__main__:main
2 changes: 2 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import setuptools
setuptools.setup()
File renamed without changes.
20 changes: 20 additions & 0 deletions src/image_viewer_mk2/ObservableCollections/event.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# ------------------------------------------------------------------------------
# File: event.py
# Author: Remi Emonet
# Date: 8/2019
# Source: https://github.com/twitwi/vuejs-python/tree/master/vuejspython/observablecollections
# License: MIT
# ------------------------------------------------------------------------------

class Event:
def __init__(self, action, source):
self._action = action
self._source = source

@property
def action(self):
return self._action

@property
def source(self):
return self._source
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
# ------------------------------------------------------------------------------
# File: observable.py
# Author: Remi Emonet
# Date: 8/2019
# Source: https://github.com/twitwi/vuejs-python/tree/master/vuejspython/observablecollections
# License: MIT
# ------------------------------------------------------------------------------

import types
from .event import Event

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
# ------------------------------------------------------------------------------
# File: observabledict.py
# Author: Remi Emonet
# Date: 8/2019
# Source: https://github.com/twitwi/vuejs-python/tree/master/vuejspython/observablecollections
# License: MIT
# ------------------------------------------------------------------------------

from .event import Event
from .observable import Observable
from collections import namedtuple
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
# ------------------------------------------------------------------------------
# File: observablelist.py
# Author: Remi Emonet
# Date: 8/2019
# Source: https://github.com/twitwi/vuejs-python/tree/master/vuejspython/observablecollections
# License: MIT
# ------------------------------------------------------------------------------

from .observable import Observable

class ObservableList(list, Observable):
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
# ------------------------------------------------------------------------------
# File: observableset.py
# Author: Remi Emonet
# Date: 8/2019
# Source: https://github.com/twitwi/vuejs-python/tree/master/vuejspython/observablecollections
# License: MIT
# ------------------------------------------------------------------------------

from .observable import Observable

class ObservableSet(Observable, set):
Expand Down
File renamed without changes.
45 changes: 45 additions & 0 deletions src/image_viewer_mk2/__main__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import sys
import argparse

try:
from importlib import metadata
except ImportError: # for Python<3.8
import importlib_metadata as metadata
__version__ = metadata.version('image-viewer-mk2')

# argument parsing
parser = argparse.ArgumentParser(description='Image Viewer MKII: Spectral image viewer')
parser.add_argument('-i', '--input', type=str, help='Filename of the image to open', default=argparse.SUPPRESS)
parser.add_argument('-c', '--config', type=str, help='Filename of the config file to import', default=argparse.SUPPRESS)

parser.add_argument('-d', '--debug', help='Print errors to console.', action='store_true', default=argparse.SUPPRESS)
parser.add_argument('-g', '--gpu', help='Use GPU rendering (default)', action='store_true', default=argparse.SUPPRESS)
parser.add_argument('-ng', '--no_gpu', help='Use CPU rendering', action='store_true', default=argparse.SUPPRESS)


def main(args=None):
from . import app
kwargs = vars(parser.parse_args(sys.argv[1:]))
kwargs2 = {}

if 'no_gpu' in kwargs:
kwargs2['gpu'] = not kwargs['no_gpu']
if 'gpu' in kwargs:
kwargs2['gpu'] = kwargs['gpu']
if 'input' in kwargs:
kwargs2['file'] = kwargs['input']
if 'config' in kwargs:
kwargs2['config_filename'] = kwargs['config']
if 'debug' in kwargs:
kwargs2['debug'] = kwargs['debug']

print(f'Image Viewer MKII (v{__version__}) Jan Kukacka, 2021.')
app.start(**kwargs2)


if __name__ == "__main__":
try:
main()
sys.exit(0)
except Exception:
sys.exit(1)
11 changes: 9 additions & 2 deletions about.py → src/image_viewer_mk2/about.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,13 @@
from PIL import Image, ImageOps, ImageTk
import numpy as np

try:
from importlib import metadata
except ImportError: # for Python<3.8
import importlib_metadata as metadata
__version__ = metadata.version('image-viewer-mk2')


def prepare_icon(filename, skin):
path = Path(os.path.dirname(os.path.abspath(__file__)))
icon = Image.open(str(path/'resources'/filename))
Expand Down Expand Up @@ -51,10 +58,10 @@ def __init__(self, master, skin):
frame = tk.Frame(frame, bg='#ff0000')
frame.pack(side=tk.TOP, expand=True, fill=tk.X, padx=10)
tk.Label(frame, text='Image Viewer MK2', fg=self.skin.fg_color, bg=self.skin.bg_color, font=('Segoe UI', 14, 'bold')).pack(side=tk.TOP, expand=False, fill=tk.X)
tk.Label(frame, text='v0.2.1 (2021-11-11)', fg=self.skin.fg_color, bg=self.skin.bg_color).pack(side=tk.TOP, expand=False, fill=tk.X)
tk.Label(frame, text=f'v{__version__} (2021-11-11)', fg=self.skin.fg_color, bg=self.skin.bg_color).pack(side=tk.TOP, expand=False, fill=tk.X)
tk.Label(frame, text='Author: Jan Kukačka, 2021', fg=self.skin.fg_color, bg=self.skin.bg_color).pack(side=tk.TOP, expand=False, fill=tk.X)
tk.Label(frame, text='Provided under MIT license.', fg=self.skin.fg_color, bg=self.skin.bg_color).pack(side=tk.TOP, expand=False, fill=tk.X)
tk.Label(frame, text='Icon credits: Icon home, Gregor Cresnar,\nFreepik and Pancracysdh.', fg=self.skin.fg_color, bg=self.skin.bg_color).pack(side=tk.TOP, expand=False, fill=tk.X)
tk.Label(frame, text='Icon credits: Icon home, Gregor Cresnar,\nFreepik, Google, and Pancracysdh.', fg=self.skin.fg_color, bg=self.skin.bg_color).pack(side=tk.TOP, expand=False, fill=tk.X)

def on_closing(self):
self.master.window_about = None
Expand Down
33 changes: 1 addition & 32 deletions app.py → src/image_viewer_mk2/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
# ------------------------------------------------------------------------------

import numpy as np
import argparse
try:
from . import view as view_
from . import model as model_
Expand All @@ -19,18 +18,7 @@
import presenter as presenter_


# argument parsing
parser = argparse.ArgumentParser(description='Image Viewer MKII: Spectral image viewer')
parser.add_argument('-i', '--input', type=str, help='Filename of the image to open', default=argparse.SUPPRESS)
parser.add_argument('-c', '--config', type=str, help='Filename of the config file to import', default=argparse.SUPPRESS)

parser.add_argument('-d', '--debug', help='Print errors to console.', action='store_true', default=argparse.SUPPRESS)
parser.add_argument('-g', '--gpu', help='Use GPU rendering (default)', action='store_true', default=argparse.SUPPRESS)
parser.add_argument('-ng', '--no_gpu', help='Use CPU rendering', action='store_true', default=argparse.SUPPRESS)



def main(file=None, image=None, **kwargs):
def start(file=None, image=None, **kwargs):
'''
Starts the app and opens optionally given file or uses given image.
Expand Down Expand Up @@ -90,22 +78,3 @@ def main(file=None, image=None, **kwargs):
return result, config
else:
return result

if __name__ == '__main__':
import sys
kwargs = vars(parser.parse_args(sys.argv[1:]))
kwargs2 = {}

if 'no_gpu' in kwargs:
kwargs2['gpu'] = not kwargs['no_gpu']
if 'gpu' in kwargs:
kwargs2['gpu'] = kwargs['gpu']
if 'input' in kwargs:
kwargs2['file'] = kwargs['input']
if 'config' in kwargs:
kwargs2['config_filename'] = kwargs['config']
if 'debug' in kwargs:
kwargs2['debug'] = kwargs['debug']

print('Image Viewer MKII. Jan Kukacka, 2021')
main(**kwargs2)
Loading

0 comments on commit 9bae30f

Please sign in to comment.