Mercurial > repos > imgteam > ridge_filter
annotate filter_skimage.py @ 1:b8867c9e0526 draft default tip
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/ridge_filter/ commit ee4527761a958353ab636eb9e7ad7502a2f6cece
| author | imgteam |
|---|---|
| date | Mon, 15 Dec 2025 22:25:39 +0000 |
| parents | 0cb07fefbe70 |
| children |
| rev | line source |
|---|---|
|
0
0cb07fefbe70
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/ridge_filter/ commit 85b0f6afacb8933db19e03682559cc4d71031cf1
imgteam
parents:
diff
changeset
|
1 import argparse |
|
0cb07fefbe70
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/ridge_filter/ commit 85b0f6afacb8933db19e03682559cc4d71031cf1
imgteam
parents:
diff
changeset
|
2 import json |
|
0cb07fefbe70
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/ridge_filter/ commit 85b0f6afacb8933db19e03682559cc4d71031cf1
imgteam
parents:
diff
changeset
|
3 from typing import ( |
|
0cb07fefbe70
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/ridge_filter/ commit 85b0f6afacb8933db19e03682559cc4d71031cf1
imgteam
parents:
diff
changeset
|
4 Any, |
|
0cb07fefbe70
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/ridge_filter/ commit 85b0f6afacb8933db19e03682559cc4d71031cf1
imgteam
parents:
diff
changeset
|
5 Callable, |
|
0cb07fefbe70
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/ridge_filter/ commit 85b0f6afacb8933db19e03682559cc4d71031cf1
imgteam
parents:
diff
changeset
|
6 ) |
|
0cb07fefbe70
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/ridge_filter/ commit 85b0f6afacb8933db19e03682559cc4d71031cf1
imgteam
parents:
diff
changeset
|
7 |
|
0cb07fefbe70
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/ridge_filter/ commit 85b0f6afacb8933db19e03682559cc4d71031cf1
imgteam
parents:
diff
changeset
|
8 import giatools |
|
0cb07fefbe70
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/ridge_filter/ commit 85b0f6afacb8933db19e03682559cc4d71031cf1
imgteam
parents:
diff
changeset
|
9 import numpy as np |
|
0cb07fefbe70
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/ridge_filter/ commit 85b0f6afacb8933db19e03682559cc4d71031cf1
imgteam
parents:
diff
changeset
|
10 import skimage.filters |
|
0cb07fefbe70
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/ridge_filter/ commit 85b0f6afacb8933db19e03682559cc4d71031cf1
imgteam
parents:
diff
changeset
|
11 |
|
0cb07fefbe70
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/ridge_filter/ commit 85b0f6afacb8933db19e03682559cc4d71031cf1
imgteam
parents:
diff
changeset
|
12 |
|
0cb07fefbe70
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/ridge_filter/ commit 85b0f6afacb8933db19e03682559cc4d71031cf1
imgteam
parents:
diff
changeset
|
13 filters = { |
|
0cb07fefbe70
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/ridge_filter/ commit 85b0f6afacb8933db19e03682559cc4d71031cf1
imgteam
parents:
diff
changeset
|
14 'frangi': lambda img, **kwargs: ( |
|
0cb07fefbe70
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/ridge_filter/ commit 85b0f6afacb8933db19e03682559cc4d71031cf1
imgteam
parents:
diff
changeset
|
15 apply_nd_filter(skimage.filters.frangi, img, **kwargs) |
|
0cb07fefbe70
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/ridge_filter/ commit 85b0f6afacb8933db19e03682559cc4d71031cf1
imgteam
parents:
diff
changeset
|
16 ), |
|
0cb07fefbe70
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/ridge_filter/ commit 85b0f6afacb8933db19e03682559cc4d71031cf1
imgteam
parents:
diff
changeset
|
17 'hessian': lambda img, **kwargs: ( |
|
0cb07fefbe70
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/ridge_filter/ commit 85b0f6afacb8933db19e03682559cc4d71031cf1
imgteam
parents:
diff
changeset
|
18 apply_nd_filter(skimage.filters.hessian, img, **kwargs) |
|
0cb07fefbe70
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/ridge_filter/ commit 85b0f6afacb8933db19e03682559cc4d71031cf1
imgteam
parents:
diff
changeset
|
19 ), |
|
0cb07fefbe70
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/ridge_filter/ commit 85b0f6afacb8933db19e03682559cc4d71031cf1
imgteam
parents:
diff
changeset
|
20 'laplace': lambda img, **kwargs: ( |
|
0cb07fefbe70
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/ridge_filter/ commit 85b0f6afacb8933db19e03682559cc4d71031cf1
imgteam
parents:
diff
changeset
|
21 apply_nd_filter(skimage.filters.laplace, img, **kwargs) |
|
0cb07fefbe70
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/ridge_filter/ commit 85b0f6afacb8933db19e03682559cc4d71031cf1
imgteam
parents:
diff
changeset
|
22 ), |
|
0cb07fefbe70
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/ridge_filter/ commit 85b0f6afacb8933db19e03682559cc4d71031cf1
imgteam
parents:
diff
changeset
|
23 'meijering': lambda img, **kwargs: ( |
|
0cb07fefbe70
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/ridge_filter/ commit 85b0f6afacb8933db19e03682559cc4d71031cf1
imgteam
parents:
diff
changeset
|
24 apply_nd_filter(skimage.filters.meijering, img, **kwargs) |
|
0cb07fefbe70
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/ridge_filter/ commit 85b0f6afacb8933db19e03682559cc4d71031cf1
imgteam
parents:
diff
changeset
|
25 ), |
|
0cb07fefbe70
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/ridge_filter/ commit 85b0f6afacb8933db19e03682559cc4d71031cf1
imgteam
parents:
diff
changeset
|
26 'sato': lambda img, **kwargs: ( |
|
0cb07fefbe70
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/ridge_filter/ commit 85b0f6afacb8933db19e03682559cc4d71031cf1
imgteam
parents:
diff
changeset
|
27 apply_nd_filter(skimage.filters.sato, img, **kwargs) |
|
0cb07fefbe70
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/ridge_filter/ commit 85b0f6afacb8933db19e03682559cc4d71031cf1
imgteam
parents:
diff
changeset
|
28 ), |
|
0cb07fefbe70
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/ridge_filter/ commit 85b0f6afacb8933db19e03682559cc4d71031cf1
imgteam
parents:
diff
changeset
|
29 } |
|
0cb07fefbe70
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/ridge_filter/ commit 85b0f6afacb8933db19e03682559cc4d71031cf1
imgteam
parents:
diff
changeset
|
30 |
|
0cb07fefbe70
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/ridge_filter/ commit 85b0f6afacb8933db19e03682559cc4d71031cf1
imgteam
parents:
diff
changeset
|
31 |
|
0cb07fefbe70
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/ridge_filter/ commit 85b0f6afacb8933db19e03682559cc4d71031cf1
imgteam
parents:
diff
changeset
|
32 def apply_nd_filter( |
|
0cb07fefbe70
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/ridge_filter/ commit 85b0f6afacb8933db19e03682559cc4d71031cf1
imgteam
parents:
diff
changeset
|
33 filter_impl: Callable[[np.ndarray, Any, ...], np.ndarray], |
|
0cb07fefbe70
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/ridge_filter/ commit 85b0f6afacb8933db19e03682559cc4d71031cf1
imgteam
parents:
diff
changeset
|
34 img: giatools.Image, |
|
0cb07fefbe70
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/ridge_filter/ commit 85b0f6afacb8933db19e03682559cc4d71031cf1
imgteam
parents:
diff
changeset
|
35 dtype: str, |
|
0cb07fefbe70
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/ridge_filter/ commit 85b0f6afacb8933db19e03682559cc4d71031cf1
imgteam
parents:
diff
changeset
|
36 **kwargs: Any, |
|
0cb07fefbe70
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/ridge_filter/ commit 85b0f6afacb8933db19e03682559cc4d71031cf1
imgteam
parents:
diff
changeset
|
37 ) -> giatools.Image: |
|
0cb07fefbe70
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/ridge_filter/ commit 85b0f6afacb8933db19e03682559cc4d71031cf1
imgteam
parents:
diff
changeset
|
38 """ |
|
0cb07fefbe70
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/ridge_filter/ commit 85b0f6afacb8933db19e03682559cc4d71031cf1
imgteam
parents:
diff
changeset
|
39 Apply the filter to the 2-D/3-D, potentially multi-frame and multi-channel image. |
|
0cb07fefbe70
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/ridge_filter/ commit 85b0f6afacb8933db19e03682559cc4d71031cf1
imgteam
parents:
diff
changeset
|
40 """ |
|
0cb07fefbe70
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/ridge_filter/ commit 85b0f6afacb8933db19e03682559cc4d71031cf1
imgteam
parents:
diff
changeset
|
41 result_data = np.empty(img.data.shape, dtype=dtype) |
|
0cb07fefbe70
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/ridge_filter/ commit 85b0f6afacb8933db19e03682559cc4d71031cf1
imgteam
parents:
diff
changeset
|
42 for qtc in np.ndindex( |
|
0cb07fefbe70
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/ridge_filter/ commit 85b0f6afacb8933db19e03682559cc4d71031cf1
imgteam
parents:
diff
changeset
|
43 img.data.shape[ 0], # Q axis |
|
0cb07fefbe70
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/ridge_filter/ commit 85b0f6afacb8933db19e03682559cc4d71031cf1
imgteam
parents:
diff
changeset
|
44 img.data.shape[ 1], # T axis |
|
0cb07fefbe70
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/ridge_filter/ commit 85b0f6afacb8933db19e03682559cc4d71031cf1
imgteam
parents:
diff
changeset
|
45 img.data.shape[-1], # C axis |
|
0cb07fefbe70
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/ridge_filter/ commit 85b0f6afacb8933db19e03682559cc4d71031cf1
imgteam
parents:
diff
changeset
|
46 ): |
|
0cb07fefbe70
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/ridge_filter/ commit 85b0f6afacb8933db19e03682559cc4d71031cf1
imgteam
parents:
diff
changeset
|
47 sl = np.s_[*qtc[:2], ..., qtc[2]] # noqa: E999 |
|
0cb07fefbe70
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/ridge_filter/ commit 85b0f6afacb8933db19e03682559cc4d71031cf1
imgteam
parents:
diff
changeset
|
48 arr = img.data[sl] |
|
0cb07fefbe70
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/ridge_filter/ commit 85b0f6afacb8933db19e03682559cc4d71031cf1
imgteam
parents:
diff
changeset
|
49 assert arr.ndim == 3 # sanity check, should always be True |
|
0cb07fefbe70
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/ridge_filter/ commit 85b0f6afacb8933db19e03682559cc4d71031cf1
imgteam
parents:
diff
changeset
|
50 |
|
0cb07fefbe70
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/ridge_filter/ commit 85b0f6afacb8933db19e03682559cc4d71031cf1
imgteam
parents:
diff
changeset
|
51 # Perform 2-D or 3-D filtering |
|
0cb07fefbe70
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/ridge_filter/ commit 85b0f6afacb8933db19e03682559cc4d71031cf1
imgteam
parents:
diff
changeset
|
52 if arr.shape[0] == 1: |
|
0cb07fefbe70
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/ridge_filter/ commit 85b0f6afacb8933db19e03682559cc4d71031cf1
imgteam
parents:
diff
changeset
|
53 info = 'Performing 2-D filtering' |
|
0cb07fefbe70
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/ridge_filter/ commit 85b0f6afacb8933db19e03682559cc4d71031cf1
imgteam
parents:
diff
changeset
|
54 result_data[sl][0] = filter_impl(arr[0], **kwargs).astype(dtype) |
|
0cb07fefbe70
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/ridge_filter/ commit 85b0f6afacb8933db19e03682559cc4d71031cf1
imgteam
parents:
diff
changeset
|
55 else: |
|
0cb07fefbe70
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/ridge_filter/ commit 85b0f6afacb8933db19e03682559cc4d71031cf1
imgteam
parents:
diff
changeset
|
56 info = 'Performing 3-D filtering' |
|
0cb07fefbe70
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/ridge_filter/ commit 85b0f6afacb8933db19e03682559cc4d71031cf1
imgteam
parents:
diff
changeset
|
57 result_data[sl] = filter_impl(arr, **kwargs).astype(dtype) |
|
0cb07fefbe70
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/ridge_filter/ commit 85b0f6afacb8933db19e03682559cc4d71031cf1
imgteam
parents:
diff
changeset
|
58 |
|
0cb07fefbe70
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/ridge_filter/ commit 85b0f6afacb8933db19e03682559cc4d71031cf1
imgteam
parents:
diff
changeset
|
59 # Print status info |
|
0cb07fefbe70
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/ridge_filter/ commit 85b0f6afacb8933db19e03682559cc4d71031cf1
imgteam
parents:
diff
changeset
|
60 print(info) |
|
0cb07fefbe70
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/ridge_filter/ commit 85b0f6afacb8933db19e03682559cc4d71031cf1
imgteam
parents:
diff
changeset
|
61 |
|
0cb07fefbe70
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/ridge_filter/ commit 85b0f6afacb8933db19e03682559cc4d71031cf1
imgteam
parents:
diff
changeset
|
62 # Return results as 16bit, 32bit, or 64bit floating point |
|
0cb07fefbe70
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/ridge_filter/ commit 85b0f6afacb8933db19e03682559cc4d71031cf1
imgteam
parents:
diff
changeset
|
63 return giatools.Image(result_data.astype(dtype), img.axes) |
|
0cb07fefbe70
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/ridge_filter/ commit 85b0f6afacb8933db19e03682559cc4d71031cf1
imgteam
parents:
diff
changeset
|
64 |
|
0cb07fefbe70
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/ridge_filter/ commit 85b0f6afacb8933db19e03682559cc4d71031cf1
imgteam
parents:
diff
changeset
|
65 |
|
0cb07fefbe70
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/ridge_filter/ commit 85b0f6afacb8933db19e03682559cc4d71031cf1
imgteam
parents:
diff
changeset
|
66 def apply_filter( |
|
0cb07fefbe70
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/ridge_filter/ commit 85b0f6afacb8933db19e03682559cc4d71031cf1
imgteam
parents:
diff
changeset
|
67 input_filepath: str, |
|
0cb07fefbe70
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/ridge_filter/ commit 85b0f6afacb8933db19e03682559cc4d71031cf1
imgteam
parents:
diff
changeset
|
68 output_filepath: str, |
|
0cb07fefbe70
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/ridge_filter/ commit 85b0f6afacb8933db19e03682559cc4d71031cf1
imgteam
parents:
diff
changeset
|
69 filter_type: str, |
|
0cb07fefbe70
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/ridge_filter/ commit 85b0f6afacb8933db19e03682559cc4d71031cf1
imgteam
parents:
diff
changeset
|
70 **kwargs: Any, |
|
0cb07fefbe70
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/ridge_filter/ commit 85b0f6afacb8933db19e03682559cc4d71031cf1
imgteam
parents:
diff
changeset
|
71 ): |
|
0cb07fefbe70
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/ridge_filter/ commit 85b0f6afacb8933db19e03682559cc4d71031cf1
imgteam
parents:
diff
changeset
|
72 # Validate and transform input parameters |
|
0cb07fefbe70
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/ridge_filter/ commit 85b0f6afacb8933db19e03682559cc4d71031cf1
imgteam
parents:
diff
changeset
|
73 params = dict(kwargs) |
|
0cb07fefbe70
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/ridge_filter/ commit 85b0f6afacb8933db19e03682559cc4d71031cf1
imgteam
parents:
diff
changeset
|
74 if (sigma_min := params.pop('sigma_min', None)) is not None and (sigma_max := params.pop('sigma_max', None)) is not None: |
|
0cb07fefbe70
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/ridge_filter/ commit 85b0f6afacb8933db19e03682559cc4d71031cf1
imgteam
parents:
diff
changeset
|
75 num_sigma = params.pop('num_sigma') |
|
0cb07fefbe70
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/ridge_filter/ commit 85b0f6afacb8933db19e03682559cc4d71031cf1
imgteam
parents:
diff
changeset
|
76 if sigma_min < sigma_max: |
|
0cb07fefbe70
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/ridge_filter/ commit 85b0f6afacb8933db19e03682559cc4d71031cf1
imgteam
parents:
diff
changeset
|
77 params['sigmas'] = np.linspace(sigma_min, sigma_max, num_sigma) |
|
0cb07fefbe70
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/ridge_filter/ commit 85b0f6afacb8933db19e03682559cc4d71031cf1
imgteam
parents:
diff
changeset
|
78 elif sigma_min == sigma_max: |
|
0cb07fefbe70
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/ridge_filter/ commit 85b0f6afacb8933db19e03682559cc4d71031cf1
imgteam
parents:
diff
changeset
|
79 params['sigmas'] = [sigma_min] |
|
0cb07fefbe70
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/ridge_filter/ commit 85b0f6afacb8933db19e03682559cc4d71031cf1
imgteam
parents:
diff
changeset
|
80 else: |
|
0cb07fefbe70
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/ridge_filter/ commit 85b0f6afacb8933db19e03682559cc4d71031cf1
imgteam
parents:
diff
changeset
|
81 raise ValueError(f'Minimum sigma ({sigma_min:g}) must not be greater than Maximum sigma ({sigma_max:g})') |
|
0cb07fefbe70
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/ridge_filter/ commit 85b0f6afacb8933db19e03682559cc4d71031cf1
imgteam
parents:
diff
changeset
|
82 |
|
0cb07fefbe70
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/ridge_filter/ commit 85b0f6afacb8933db19e03682559cc4d71031cf1
imgteam
parents:
diff
changeset
|
83 # Read the input image |
|
0cb07fefbe70
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/ridge_filter/ commit 85b0f6afacb8933db19e03682559cc4d71031cf1
imgteam
parents:
diff
changeset
|
84 img = giatools.Image.read(input_filepath) |
|
0cb07fefbe70
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/ridge_filter/ commit 85b0f6afacb8933db19e03682559cc4d71031cf1
imgteam
parents:
diff
changeset
|
85 |
|
0cb07fefbe70
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/ridge_filter/ commit 85b0f6afacb8933db19e03682559cc4d71031cf1
imgteam
parents:
diff
changeset
|
86 # Perform filtering |
|
0cb07fefbe70
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/ridge_filter/ commit 85b0f6afacb8933db19e03682559cc4d71031cf1
imgteam
parents:
diff
changeset
|
87 print(f'Applying filter: "{filter_type}"') |
|
0cb07fefbe70
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/ridge_filter/ commit 85b0f6afacb8933db19e03682559cc4d71031cf1
imgteam
parents:
diff
changeset
|
88 filter_impl = filters[filter_type] |
|
0cb07fefbe70
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/ridge_filter/ commit 85b0f6afacb8933db19e03682559cc4d71031cf1
imgteam
parents:
diff
changeset
|
89 res = filter_impl(img, **params).normalize_axes_like(img.original_axes) |
|
0cb07fefbe70
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/ridge_filter/ commit 85b0f6afacb8933db19e03682559cc4d71031cf1
imgteam
parents:
diff
changeset
|
90 |
|
0cb07fefbe70
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/ridge_filter/ commit 85b0f6afacb8933db19e03682559cc4d71031cf1
imgteam
parents:
diff
changeset
|
91 # Adopt metadata and write the result |
|
0cb07fefbe70
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/ridge_filter/ commit 85b0f6afacb8933db19e03682559cc4d71031cf1
imgteam
parents:
diff
changeset
|
92 res.metadata = img.metadata |
|
0cb07fefbe70
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/ridge_filter/ commit 85b0f6afacb8933db19e03682559cc4d71031cf1
imgteam
parents:
diff
changeset
|
93 res.write(output_filepath, backend='tifffile') |
|
0cb07fefbe70
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/ridge_filter/ commit 85b0f6afacb8933db19e03682559cc4d71031cf1
imgteam
parents:
diff
changeset
|
94 |
|
0cb07fefbe70
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/ridge_filter/ commit 85b0f6afacb8933db19e03682559cc4d71031cf1
imgteam
parents:
diff
changeset
|
95 |
|
0cb07fefbe70
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/ridge_filter/ commit 85b0f6afacb8933db19e03682559cc4d71031cf1
imgteam
parents:
diff
changeset
|
96 if __name__ == "__main__": |
|
0cb07fefbe70
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/ridge_filter/ commit 85b0f6afacb8933db19e03682559cc4d71031cf1
imgteam
parents:
diff
changeset
|
97 parser = argparse.ArgumentParser() |
|
0cb07fefbe70
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/ridge_filter/ commit 85b0f6afacb8933db19e03682559cc4d71031cf1
imgteam
parents:
diff
changeset
|
98 parser.add_argument('input', type=str) |
|
0cb07fefbe70
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/ridge_filter/ commit 85b0f6afacb8933db19e03682559cc4d71031cf1
imgteam
parents:
diff
changeset
|
99 parser.add_argument('output', type=str) |
|
0cb07fefbe70
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/ridge_filter/ commit 85b0f6afacb8933db19e03682559cc4d71031cf1
imgteam
parents:
diff
changeset
|
100 parser.add_argument('params', type=str) |
|
0cb07fefbe70
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/ridge_filter/ commit 85b0f6afacb8933db19e03682559cc4d71031cf1
imgteam
parents:
diff
changeset
|
101 args = parser.parse_args() |
|
0cb07fefbe70
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/ridge_filter/ commit 85b0f6afacb8933db19e03682559cc4d71031cf1
imgteam
parents:
diff
changeset
|
102 |
|
0cb07fefbe70
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/ridge_filter/ commit 85b0f6afacb8933db19e03682559cc4d71031cf1
imgteam
parents:
diff
changeset
|
103 # Read the config file |
|
0cb07fefbe70
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/ridge_filter/ commit 85b0f6afacb8933db19e03682559cc4d71031cf1
imgteam
parents:
diff
changeset
|
104 with open(args.params) as cfgf: |
|
0cb07fefbe70
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/ridge_filter/ commit 85b0f6afacb8933db19e03682559cc4d71031cf1
imgteam
parents:
diff
changeset
|
105 cfg = json.load(cfgf) |
|
0cb07fefbe70
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/ridge_filter/ commit 85b0f6afacb8933db19e03682559cc4d71031cf1
imgteam
parents:
diff
changeset
|
106 |
|
0cb07fefbe70
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/ridge_filter/ commit 85b0f6afacb8933db19e03682559cc4d71031cf1
imgteam
parents:
diff
changeset
|
107 apply_filter( |
|
0cb07fefbe70
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/ridge_filter/ commit 85b0f6afacb8933db19e03682559cc4d71031cf1
imgteam
parents:
diff
changeset
|
108 args.input, |
|
0cb07fefbe70
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/ridge_filter/ commit 85b0f6afacb8933db19e03682559cc4d71031cf1
imgteam
parents:
diff
changeset
|
109 args.output, |
|
0cb07fefbe70
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/ridge_filter/ commit 85b0f6afacb8933db19e03682559cc4d71031cf1
imgteam
parents:
diff
changeset
|
110 **cfg, |
|
0cb07fefbe70
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/ridge_filter/ commit 85b0f6afacb8933db19e03682559cc4d71031cf1
imgteam
parents:
diff
changeset
|
111 ) |
