Mercurial > repos > imgteam > clip_image
view clip_image.py @ 1:53be9a7f94a6 draft default tip
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/clip_image/ commit e9a49428eb8424b1e2b80093e6b3f924f98f2d14
| author | imgteam |
|---|---|
| date | Sun, 04 Jan 2026 22:20:21 +0000 |
| parents | be9e6f9e5d04 |
| children |
line wrap: on
line source
import giatools import numpy as np # Fail early if an optional backend is not available giatools.require_backend('omezarr') if __name__ == "__main__": tool = giatools.ToolBaseplate() tool.add_input_image('input') tool.add_output_image('output') for section in tool.run( 'YX', # do not process all axes jointly so we can safely load a Dask array into a NumPy array (see below) output_dtype_hint='preserve', ): # Perform the clipping clip_args = [ tool.args.params.get('lower_bound', -np.inf), tool.args.params.get('upper_bound', +np.inf), ] if clip_args == list(sorted(clip_args)): print('Applying clipping:', str(clip_args)) section['output'] = np.asarray( # conversion is required until https://github.com/BMCV/giatools/pull/44 is fixed section['input'].data.clip(*clip_args) ) else: exit(f'Lower bound ({clip_args[0]:g}) must be less or equal compared to the upper bound ({clip_args[1]:g}).')
