This repository has been archived by the owner on May 23, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
/
main.py
79 lines (63 loc) · 2.88 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
"""This module creates a command line interface and is an entry point"""
from functools import wraps
from typing import Any, Callable
import click
from core import (FDM, GRAY, HM, HSV, IMAGE_CHANNELS, LAB, MATCH_FULL,
MATCH_ZERO, RGB, Params)
from utils import application
def command_wrapper(func: Callable[..., Any]) -> Callable[..., Any]:
"""
Command wrapper, parameters that are common for all commands are set here
:param func: command function to be wrapped
:return: command function wrapped / decorated with the common parameters
"""
@wraps(func)
@click.option('--color-space', '-s', 'color_space', default=RGB,
type=click.Choice([GRAY, HSV, LAB, RGB],
case_sensitive=False),
help='color space')
@click.option('--channels', '-c', 'channels', default=IMAGE_CHANNELS,
type=click.Choice(
['0', '1', '2', '0,1', '0,2', '1,2', '0,1,2']),
help='comma-separated list of channels to matching '
f'(supported channels are {IMAGE_CHANNELS})')
@click.option('--plot', '-p', 'plot', is_flag=True, default=False,
help='creates the visualization for an applied operation')
@click.option('--verify-input', '-v', 'verify_input', default=False,
type=bool, help='input data verification')
@click.argument('source_path', type=click.Path(exists=True))
@click.argument('reference_path', type=click.Path(exists=True))
@click.argument('result_path', type=click.Path(exists=False))
def wrapper(ctx: click.core.Context, **kwargs: Any) -> Any:
for name, value in kwargs.items():
ctx.obj[name] = value
run(ctx)
return func()
return wrapper
# pylint: disable=no-value-for-parameter (E1120)
@click.group()
@click.pass_context
def main(ctx: click.core.Context) -> None:
""" Defines a group of commands """
ctx.ensure_object(dict)
@main.command(name=FDM, help='Feature Distribution Matching')
@click.pass_context
@command_wrapper
def command_fdm() -> None:
""" Feature Distribution Matching command function """
@main.command(name=HM, help='Histogram Matching')
@click.option('--match-proportion', '-m', 'match_proportion',
default=MATCH_FULL,
type=click.FloatRange(MATCH_ZERO, MATCH_FULL),
help=f'interpolation strength between source and reference '
f'histograms, {MATCH_FULL} (default) is full matching, '
f'{MATCH_ZERO} is no matching')
@click.pass_context
@command_wrapper
def command_hm() -> None:
""" Histogram Matching command function """
def run(ctx: click.core.Context) -> None:
""" Calls the main program with the parameters available in the context """
application.run(ctx.command.name, Params(ctx.obj))
if __name__ == '__main__':
main()