annotate filter_image.py @ 1:dba87c4b32d3 draft

planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/2d_simple_filter/ commit 8e0d09b4c4eadfaaf125f4a0ae7dcbd1bee5ee51
author imgteam
date Thu, 18 Jul 2019 08:51:58 -0400
parents f264ae82f735
children f70b215d155c
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
f264ae82f735 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/2d_simple_filter/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff changeset
1 import argparse
f264ae82f735 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/2d_simple_filter/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff changeset
2 import sys
f264ae82f735 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/2d_simple_filter/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff changeset
3 import warnings
f264ae82f735 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/2d_simple_filter/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff changeset
4 import numpy as np
f264ae82f735 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/2d_simple_filter/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff changeset
5 import skimage.io
f264ae82f735 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/2d_simple_filter/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff changeset
6 import skimage.filters
f264ae82f735 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/2d_simple_filter/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff changeset
7 import skimage.util
f264ae82f735 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/2d_simple_filter/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff changeset
8 from skimage.morphology import disk
1
dba87c4b32d3 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/2d_simple_filter/ commit 8e0d09b4c4eadfaaf125f4a0ae7dcbd1bee5ee51
imgteam
parents: 0
diff changeset
9 from skimage import img_as_uint
0
f264ae82f735 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/2d_simple_filter/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff changeset
10
f264ae82f735 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/2d_simple_filter/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff changeset
11 filterOptions = {
f264ae82f735 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/2d_simple_filter/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff changeset
12 'median' : lambda img_raw, radius: skimage.filters.median(img_raw, disk(radius)),
f264ae82f735 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/2d_simple_filter/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff changeset
13 'gaussian' : lambda img_raw, radius: skimage.filters.gaussian(img_raw, sigma=radius),
f264ae82f735 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/2d_simple_filter/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff changeset
14 'prewitt' : lambda img_raw, radius: skimage.filters.prewitt(img_raw),
f264ae82f735 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/2d_simple_filter/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff changeset
15 'sobel' : lambda img_raw, radius: skimage.filters.sobel(img_raw),
f264ae82f735 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/2d_simple_filter/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff changeset
16 'scharr' : lambda img_raw, radius: skimage.filters.scharr(img_raw),
f264ae82f735 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/2d_simple_filter/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff changeset
17 }
f264ae82f735 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/2d_simple_filter/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff changeset
18
f264ae82f735 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/2d_simple_filter/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff changeset
19 if __name__ == "__main__":
f264ae82f735 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/2d_simple_filter/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff changeset
20 parser = argparse.ArgumentParser()
f264ae82f735 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/2d_simple_filter/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff changeset
21 parser.add_argument('input_file', type=argparse.FileType('r'), default=sys.stdin, help='input file')
f264ae82f735 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/2d_simple_filter/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff changeset
22 parser.add_argument('out_file', type=argparse.FileType('w'), default=sys.stdin, help='out file (TIFF)')
f264ae82f735 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/2d_simple_filter/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff changeset
23 parser.add_argument('filter_type', choices=filterOptions.keys(), help='conversion type')
f264ae82f735 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/2d_simple_filter/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff changeset
24 parser.add_argument('radius', default=3.0, type=float, help='Radius/Sigma')
f264ae82f735 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/2d_simple_filter/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff changeset
25 args = parser.parse_args()
f264ae82f735 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/2d_simple_filter/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff changeset
26
f264ae82f735 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/2d_simple_filter/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff changeset
27 img_in = skimage.io.imread(args.input_file.name)
1
dba87c4b32d3 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/2d_simple_filter/ commit 8e0d09b4c4eadfaaf125f4a0ae7dcbd1bee5ee51
imgteam
parents: 0
diff changeset
28 res = img_as_uint(filterOptions[args.filter_type](img_in, args.radius))
dba87c4b32d3 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/2d_simple_filter/ commit 8e0d09b4c4eadfaaf125f4a0ae7dcbd1bee5ee51
imgteam
parents: 0
diff changeset
29 skimage.io.imsave(args.out_file.name, res, plugin='tifffile')