def pipeline(image, actions):
"""Allow chaining a series of actions to be applied to IMAGE.
Output will depend on the last action applied.
\b
- ACTIONS is a JSON list of dictionaries containing each an 'action' key
specifying the action to apply, a 'arguments' key which is a
list of arguments, and a 'options' key with a dictionary to set the
options for the corresponding action.
Example::
histonets pipeline '[{"action": "contrast", "options": {"value": 50}}]'
"""
output = image.image
for action in actions:
ctx = click.get_current_context()
arguments = [output] + action.get('arguments', [])
command = main.get_command(ctx, action['action'])
if command is None:
raise click.BadParameter(
"Action '{}' not found".format(action['action']))
action_options = action.get('options', {})
options = {param.name: action_options.get(param.name, param.default)
for param in command.params[:-2]}
options['output'] = RAW
try:
output = command.callback(*arguments, **options)
except TypeError as e:
raise click.BadParameter(e)
return output
评论列表
文章目录