annotate filter.py @ 2:b2d9c92bc431 draft

planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/2d_simple_filter/ commit a6fd77be465068f709a71d377900da99becf94d8
author imgteam
date Fri, 12 Dec 2025 21:18:04 +0000
parents
children 5ab62693dca5
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2
b2d9c92bc431 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/2d_simple_filter/ commit a6fd77be465068f709a71d377900da99becf94d8
imgteam
parents:
diff changeset
1 import argparse
b2d9c92bc431 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/2d_simple_filter/ commit a6fd77be465068f709a71d377900da99becf94d8
imgteam
parents:
diff changeset
2 import json
b2d9c92bc431 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/2d_simple_filter/ commit a6fd77be465068f709a71d377900da99becf94d8
imgteam
parents:
diff changeset
3 from typing import (
b2d9c92bc431 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/2d_simple_filter/ commit a6fd77be465068f709a71d377900da99becf94d8
imgteam
parents:
diff changeset
4 Any,
b2d9c92bc431 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/2d_simple_filter/ commit a6fd77be465068f709a71d377900da99becf94d8
imgteam
parents:
diff changeset
5 Callable,
b2d9c92bc431 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/2d_simple_filter/ commit a6fd77be465068f709a71d377900da99becf94d8
imgteam
parents:
diff changeset
6 )
b2d9c92bc431 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/2d_simple_filter/ commit a6fd77be465068f709a71d377900da99becf94d8
imgteam
parents:
diff changeset
7
b2d9c92bc431 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/2d_simple_filter/ commit a6fd77be465068f709a71d377900da99becf94d8
imgteam
parents:
diff changeset
8 import giatools
b2d9c92bc431 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/2d_simple_filter/ commit a6fd77be465068f709a71d377900da99becf94d8
imgteam
parents:
diff changeset
9 import numpy as np
b2d9c92bc431 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/2d_simple_filter/ commit a6fd77be465068f709a71d377900da99becf94d8
imgteam
parents:
diff changeset
10 import scipy.ndimage as ndi
b2d9c92bc431 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/2d_simple_filter/ commit a6fd77be465068f709a71d377900da99becf94d8
imgteam
parents:
diff changeset
11 from skimage.morphology import disk
b2d9c92bc431 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/2d_simple_filter/ commit a6fd77be465068f709a71d377900da99becf94d8
imgteam
parents:
diff changeset
12
b2d9c92bc431 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/2d_simple_filter/ commit a6fd77be465068f709a71d377900da99becf94d8
imgteam
parents:
diff changeset
13
b2d9c92bc431 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/2d_simple_filter/ commit a6fd77be465068f709a71d377900da99becf94d8
imgteam
parents:
diff changeset
14 def image_astype(img: giatools.Image, dtype: np.dtype) -> giatools.Image:
b2d9c92bc431 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/2d_simple_filter/ commit a6fd77be465068f709a71d377900da99becf94d8
imgteam
parents:
diff changeset
15 return giatools.Image(
b2d9c92bc431 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/2d_simple_filter/ commit a6fd77be465068f709a71d377900da99becf94d8
imgteam
parents:
diff changeset
16 data=img.data.astype(dtype),
b2d9c92bc431 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/2d_simple_filter/ commit a6fd77be465068f709a71d377900da99becf94d8
imgteam
parents:
diff changeset
17 axes=img.axes,
b2d9c92bc431 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/2d_simple_filter/ commit a6fd77be465068f709a71d377900da99becf94d8
imgteam
parents:
diff changeset
18 original_axes=img.original_axes,
b2d9c92bc431 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/2d_simple_filter/ commit a6fd77be465068f709a71d377900da99becf94d8
imgteam
parents:
diff changeset
19 metadata=img.metadata,
b2d9c92bc431 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/2d_simple_filter/ commit a6fd77be465068f709a71d377900da99becf94d8
imgteam
parents:
diff changeset
20 )
b2d9c92bc431 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/2d_simple_filter/ commit a6fd77be465068f709a71d377900da99becf94d8
imgteam
parents:
diff changeset
21
b2d9c92bc431 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/2d_simple_filter/ commit a6fd77be465068f709a71d377900da99becf94d8
imgteam
parents:
diff changeset
22
b2d9c92bc431 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/2d_simple_filter/ commit a6fd77be465068f709a71d377900da99becf94d8
imgteam
parents:
diff changeset
23 filters = {
b2d9c92bc431 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/2d_simple_filter/ commit a6fd77be465068f709a71d377900da99becf94d8
imgteam
parents:
diff changeset
24 'gaussian': lambda img, sigma, order=0, axis=None: (
b2d9c92bc431 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/2d_simple_filter/ commit a6fd77be465068f709a71d377900da99becf94d8
imgteam
parents:
diff changeset
25 apply_2d_filter(
b2d9c92bc431 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/2d_simple_filter/ commit a6fd77be465068f709a71d377900da99becf94d8
imgteam
parents:
diff changeset
26 ndi.gaussian_filter,
b2d9c92bc431 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/2d_simple_filter/ commit a6fd77be465068f709a71d377900da99becf94d8
imgteam
parents:
diff changeset
27 img if order == 0 else image_astype(img, float),
b2d9c92bc431 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/2d_simple_filter/ commit a6fd77be465068f709a71d377900da99becf94d8
imgteam
parents:
diff changeset
28 sigma=sigma,
b2d9c92bc431 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/2d_simple_filter/ commit a6fd77be465068f709a71d377900da99becf94d8
imgteam
parents:
diff changeset
29 order=order,
b2d9c92bc431 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/2d_simple_filter/ commit a6fd77be465068f709a71d377900da99becf94d8
imgteam
parents:
diff changeset
30 axes=axis,
b2d9c92bc431 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/2d_simple_filter/ commit a6fd77be465068f709a71d377900da99becf94d8
imgteam
parents:
diff changeset
31 )
b2d9c92bc431 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/2d_simple_filter/ commit a6fd77be465068f709a71d377900da99becf94d8
imgteam
parents:
diff changeset
32 ),
b2d9c92bc431 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/2d_simple_filter/ commit a6fd77be465068f709a71d377900da99becf94d8
imgteam
parents:
diff changeset
33 'uniform': lambda img, size: (
b2d9c92bc431 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/2d_simple_filter/ commit a6fd77be465068f709a71d377900da99becf94d8
imgteam
parents:
diff changeset
34 apply_2d_filter(ndi.uniform_filter, img, size=size)
b2d9c92bc431 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/2d_simple_filter/ commit a6fd77be465068f709a71d377900da99becf94d8
imgteam
parents:
diff changeset
35 ),
b2d9c92bc431 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/2d_simple_filter/ commit a6fd77be465068f709a71d377900da99becf94d8
imgteam
parents:
diff changeset
36 'median': lambda img, radius: (
b2d9c92bc431 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/2d_simple_filter/ commit a6fd77be465068f709a71d377900da99becf94d8
imgteam
parents:
diff changeset
37 apply_2d_filter(ndi.median_filter, img, footprint=disk(radius))
b2d9c92bc431 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/2d_simple_filter/ commit a6fd77be465068f709a71d377900da99becf94d8
imgteam
parents:
diff changeset
38 ),
b2d9c92bc431 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/2d_simple_filter/ commit a6fd77be465068f709a71d377900da99becf94d8
imgteam
parents:
diff changeset
39 'prewitt': lambda img, axis: (
b2d9c92bc431 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/2d_simple_filter/ commit a6fd77be465068f709a71d377900da99becf94d8
imgteam
parents:
diff changeset
40 apply_2d_filter(ndi.prewitt, img, axis=axis)
b2d9c92bc431 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/2d_simple_filter/ commit a6fd77be465068f709a71d377900da99becf94d8
imgteam
parents:
diff changeset
41 ),
b2d9c92bc431 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/2d_simple_filter/ commit a6fd77be465068f709a71d377900da99becf94d8
imgteam
parents:
diff changeset
42 'sobel': lambda img, axis: (
b2d9c92bc431 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/2d_simple_filter/ commit a6fd77be465068f709a71d377900da99becf94d8
imgteam
parents:
diff changeset
43 apply_2d_filter(ndi.sobel, img, axis=axis)
b2d9c92bc431 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/2d_simple_filter/ commit a6fd77be465068f709a71d377900da99becf94d8
imgteam
parents:
diff changeset
44 ),
b2d9c92bc431 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/2d_simple_filter/ commit a6fd77be465068f709a71d377900da99becf94d8
imgteam
parents:
diff changeset
45 }
b2d9c92bc431 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/2d_simple_filter/ commit a6fd77be465068f709a71d377900da99becf94d8
imgteam
parents:
diff changeset
46
b2d9c92bc431 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/2d_simple_filter/ commit a6fd77be465068f709a71d377900da99becf94d8
imgteam
parents:
diff changeset
47
b2d9c92bc431 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/2d_simple_filter/ commit a6fd77be465068f709a71d377900da99becf94d8
imgteam
parents:
diff changeset
48 def apply_2d_filter(
b2d9c92bc431 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/2d_simple_filter/ commit a6fd77be465068f709a71d377900da99becf94d8
imgteam
parents:
diff changeset
49 filter_impl: Callable[[np.ndarray, Any, ...], np.ndarray],
b2d9c92bc431 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/2d_simple_filter/ commit a6fd77be465068f709a71d377900da99becf94d8
imgteam
parents:
diff changeset
50 img: giatools.Image,
b2d9c92bc431 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/2d_simple_filter/ commit a6fd77be465068f709a71d377900da99becf94d8
imgteam
parents:
diff changeset
51 **kwargs: Any,
b2d9c92bc431 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/2d_simple_filter/ commit a6fd77be465068f709a71d377900da99becf94d8
imgteam
parents:
diff changeset
52 ) -> giatools.Image:
b2d9c92bc431 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/2d_simple_filter/ commit a6fd77be465068f709a71d377900da99becf94d8
imgteam
parents:
diff changeset
53 """
b2d9c92bc431 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/2d_simple_filter/ commit a6fd77be465068f709a71d377900da99becf94d8
imgteam
parents:
diff changeset
54 Apply the 2-D filter to the 2-D/3-D, potentially multi-frame and multi-channel image.
b2d9c92bc431 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/2d_simple_filter/ commit a6fd77be465068f709a71d377900da99becf94d8
imgteam
parents:
diff changeset
55 """
b2d9c92bc431 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/2d_simple_filter/ commit a6fd77be465068f709a71d377900da99becf94d8
imgteam
parents:
diff changeset
56 result_data = None
b2d9c92bc431 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/2d_simple_filter/ commit a6fd77be465068f709a71d377900da99becf94d8
imgteam
parents:
diff changeset
57 for qtzc in np.ndindex(
b2d9c92bc431 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/2d_simple_filter/ commit a6fd77be465068f709a71d377900da99becf94d8
imgteam
parents:
diff changeset
58 img.data.shape[ 0], # Q axis
b2d9c92bc431 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/2d_simple_filter/ commit a6fd77be465068f709a71d377900da99becf94d8
imgteam
parents:
diff changeset
59 img.data.shape[ 1], # T axis
b2d9c92bc431 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/2d_simple_filter/ commit a6fd77be465068f709a71d377900da99becf94d8
imgteam
parents:
diff changeset
60 img.data.shape[ 2], # Z axis
b2d9c92bc431 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/2d_simple_filter/ commit a6fd77be465068f709a71d377900da99becf94d8
imgteam
parents:
diff changeset
61 img.data.shape[-1], # C axis
b2d9c92bc431 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/2d_simple_filter/ commit a6fd77be465068f709a71d377900da99becf94d8
imgteam
parents:
diff changeset
62 ):
b2d9c92bc431 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/2d_simple_filter/ commit a6fd77be465068f709a71d377900da99becf94d8
imgteam
parents:
diff changeset
63 sl = np.s_[*qtzc[:3], ..., qtzc[3]] # noqa: E999
b2d9c92bc431 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/2d_simple_filter/ commit a6fd77be465068f709a71d377900da99becf94d8
imgteam
parents:
diff changeset
64 arr = img.data[sl]
b2d9c92bc431 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/2d_simple_filter/ commit a6fd77be465068f709a71d377900da99becf94d8
imgteam
parents:
diff changeset
65 assert arr.ndim == 2 # sanity check, should always be True
b2d9c92bc431 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/2d_simple_filter/ commit a6fd77be465068f709a71d377900da99becf94d8
imgteam
parents:
diff changeset
66
b2d9c92bc431 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/2d_simple_filter/ commit a6fd77be465068f709a71d377900da99becf94d8
imgteam
parents:
diff changeset
67 # Perform 2-D filtering
b2d9c92bc431 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/2d_simple_filter/ commit a6fd77be465068f709a71d377900da99becf94d8
imgteam
parents:
diff changeset
68 res = filter_impl(arr, **kwargs)
b2d9c92bc431 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/2d_simple_filter/ commit a6fd77be465068f709a71d377900da99becf94d8
imgteam
parents:
diff changeset
69 if result_data is None:
b2d9c92bc431 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/2d_simple_filter/ commit a6fd77be465068f709a71d377900da99becf94d8
imgteam
parents:
diff changeset
70 result_data = np.empty(img.data.shape, res.dtype)
b2d9c92bc431 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/2d_simple_filter/ commit a6fd77be465068f709a71d377900da99becf94d8
imgteam
parents:
diff changeset
71 result_data[sl] = res
b2d9c92bc431 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/2d_simple_filter/ commit a6fd77be465068f709a71d377900da99becf94d8
imgteam
parents:
diff changeset
72
b2d9c92bc431 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/2d_simple_filter/ commit a6fd77be465068f709a71d377900da99becf94d8
imgteam
parents:
diff changeset
73 # Return results
b2d9c92bc431 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/2d_simple_filter/ commit a6fd77be465068f709a71d377900da99becf94d8
imgteam
parents:
diff changeset
74 return giatools.Image(result_data, img.axes)
b2d9c92bc431 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/2d_simple_filter/ commit a6fd77be465068f709a71d377900da99becf94d8
imgteam
parents:
diff changeset
75
b2d9c92bc431 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/2d_simple_filter/ commit a6fd77be465068f709a71d377900da99becf94d8
imgteam
parents:
diff changeset
76
b2d9c92bc431 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/2d_simple_filter/ commit a6fd77be465068f709a71d377900da99becf94d8
imgteam
parents:
diff changeset
77 def apply_filter(
b2d9c92bc431 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/2d_simple_filter/ commit a6fd77be465068f709a71d377900da99becf94d8
imgteam
parents:
diff changeset
78 input_filepath: str,
b2d9c92bc431 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/2d_simple_filter/ commit a6fd77be465068f709a71d377900da99becf94d8
imgteam
parents:
diff changeset
79 output_filepath: str,
b2d9c92bc431 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/2d_simple_filter/ commit a6fd77be465068f709a71d377900da99becf94d8
imgteam
parents:
diff changeset
80 filter_type: str,
b2d9c92bc431 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/2d_simple_filter/ commit a6fd77be465068f709a71d377900da99becf94d8
imgteam
parents:
diff changeset
81 **kwargs: Any,
b2d9c92bc431 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/2d_simple_filter/ commit a6fd77be465068f709a71d377900da99becf94d8
imgteam
parents:
diff changeset
82 ):
b2d9c92bc431 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/2d_simple_filter/ commit a6fd77be465068f709a71d377900da99becf94d8
imgteam
parents:
diff changeset
83 # Read the input image
b2d9c92bc431 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/2d_simple_filter/ commit a6fd77be465068f709a71d377900da99becf94d8
imgteam
parents:
diff changeset
84 img = giatools.Image.read(input_filepath)
b2d9c92bc431 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/2d_simple_filter/ commit a6fd77be465068f709a71d377900da99becf94d8
imgteam
parents:
diff changeset
85
b2d9c92bc431 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/2d_simple_filter/ commit a6fd77be465068f709a71d377900da99becf94d8
imgteam
parents:
diff changeset
86 # Perform filtering
b2d9c92bc431 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/2d_simple_filter/ commit a6fd77be465068f709a71d377900da99becf94d8
imgteam
parents:
diff changeset
87 filter_impl = filters[filter_type]
b2d9c92bc431 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/2d_simple_filter/ commit a6fd77be465068f709a71d377900da99becf94d8
imgteam
parents:
diff changeset
88 res = filter_impl(img, **kwargs).normalize_axes_like(img.original_axes)
b2d9c92bc431 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/2d_simple_filter/ commit a6fd77be465068f709a71d377900da99becf94d8
imgteam
parents:
diff changeset
89
b2d9c92bc431 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/2d_simple_filter/ commit a6fd77be465068f709a71d377900da99becf94d8
imgteam
parents:
diff changeset
90 # Adopt metadata and write the result
b2d9c92bc431 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/2d_simple_filter/ commit a6fd77be465068f709a71d377900da99becf94d8
imgteam
parents:
diff changeset
91 res.metadata = img.metadata
b2d9c92bc431 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/2d_simple_filter/ commit a6fd77be465068f709a71d377900da99becf94d8
imgteam
parents:
diff changeset
92 res.write(output_filepath, backend='tifffile')
b2d9c92bc431 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/2d_simple_filter/ commit a6fd77be465068f709a71d377900da99becf94d8
imgteam
parents:
diff changeset
93
b2d9c92bc431 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/2d_simple_filter/ commit a6fd77be465068f709a71d377900da99becf94d8
imgteam
parents:
diff changeset
94
b2d9c92bc431 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/2d_simple_filter/ commit a6fd77be465068f709a71d377900da99becf94d8
imgteam
parents:
diff changeset
95 if __name__ == "__main__":
b2d9c92bc431 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/2d_simple_filter/ commit a6fd77be465068f709a71d377900da99becf94d8
imgteam
parents:
diff changeset
96 parser = argparse.ArgumentParser()
b2d9c92bc431 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/2d_simple_filter/ commit a6fd77be465068f709a71d377900da99becf94d8
imgteam
parents:
diff changeset
97 parser.add_argument('input', type=str, help='Input image filepath')
b2d9c92bc431 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/2d_simple_filter/ commit a6fd77be465068f709a71d377900da99becf94d8
imgteam
parents:
diff changeset
98 parser.add_argument('output', type=str, help='Output image filepath (TIFF)')
b2d9c92bc431 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/2d_simple_filter/ commit a6fd77be465068f709a71d377900da99becf94d8
imgteam
parents:
diff changeset
99 parser.add_argument('params', type=str)
b2d9c92bc431 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/2d_simple_filter/ commit a6fd77be465068f709a71d377900da99becf94d8
imgteam
parents:
diff changeset
100 args = parser.parse_args()
b2d9c92bc431 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/2d_simple_filter/ commit a6fd77be465068f709a71d377900da99becf94d8
imgteam
parents:
diff changeset
101
b2d9c92bc431 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/2d_simple_filter/ commit a6fd77be465068f709a71d377900da99becf94d8
imgteam
parents:
diff changeset
102 # Read the config file
b2d9c92bc431 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/2d_simple_filter/ commit a6fd77be465068f709a71d377900da99becf94d8
imgteam
parents:
diff changeset
103 with open(args.params) as cfgf:
b2d9c92bc431 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/2d_simple_filter/ commit a6fd77be465068f709a71d377900da99becf94d8
imgteam
parents:
diff changeset
104 cfg = json.load(cfgf)
b2d9c92bc431 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/2d_simple_filter/ commit a6fd77be465068f709a71d377900da99becf94d8
imgteam
parents:
diff changeset
105
b2d9c92bc431 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/2d_simple_filter/ commit a6fd77be465068f709a71d377900da99becf94d8
imgteam
parents:
diff changeset
106 apply_filter(
b2d9c92bc431 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/2d_simple_filter/ commit a6fd77be465068f709a71d377900da99becf94d8
imgteam
parents:
diff changeset
107 args.input,
b2d9c92bc431 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/2d_simple_filter/ commit a6fd77be465068f709a71d377900da99becf94d8
imgteam
parents:
diff changeset
108 args.output,
b2d9c92bc431 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/2d_simple_filter/ commit a6fd77be465068f709a71d377900da99becf94d8
imgteam
parents:
diff changeset
109 **cfg,
b2d9c92bc431 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/2d_simple_filter/ commit a6fd77be465068f709a71d377900da99becf94d8
imgteam
parents:
diff changeset
110 )