Next changeset 1:dba87c4b32d3 (2019-07-18) |
Commit message:
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/2d_simple_filter/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581 |
added:
filter.xml filter_image.py test-data/res.tif test-data/sample.tif |
b |
diff -r 000000000000 -r f264ae82f735 filter.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/filter.xml Sat Feb 09 14:29:13 2019 -0500 |
[ |
@@ -0,0 +1,44 @@ +<tool id="ip_filter_standard" name="Filter Image" version="0.0.2"> + <description>applies a standard filter to an image</description> + <requirements> + <requirement type="package" version="0.14.2">scikit-image</requirement> + <requirement type="package" version="1.15.4">numpy</requirement> + <requirement type="package" version="5.3.0">pillow</requirement> + <requirement type="package" version="0.15.1">tifffile</requirement> + </requirements> + <command detect_errors="aggressive"> + <![CDATA[ + python '$__tool_directory__/filter_image.py' '$input' '$output' $filter_type $radius + ]]> + </command> + <inputs> + <param name="filter_type" type="select" label="Image type"> + <option value="median" selected="True">Median</option> + <option value="gaussian">Gaussian Blur</option> + <option value="prewitt">Prewitt</option> + <option value="sobel">Sobel</option> + <option value="scharr">Scharr</option> + </param> + <param name="radius" type="integer" value="3" label="Radius/Sigma" /> + <param name="input" type="data" format="tiff" label="Source file" /> + </inputs> + <outputs> + <data format="tiff" name="output" /> + </outputs> + <tests> + <test> + <param name="input" value="sample.tif" /> + <output name="output" value="res.tif" ftype="tiff" compare="sim_size"/> + <param name="filter_type" value="prewitt" /> + <param name="radius" value="4" /> + </test> + </tests> + <help> + **What it does** + + Applies a standard filter to an image. + </help> + <citations> + <citation type="doi">10.1016/j.jbiotec.2017.07.019</citation> + </citations> +</tool> |
b |
diff -r 000000000000 -r f264ae82f735 filter_image.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/filter_image.py Sat Feb 09 14:29:13 2019 -0500 |
[ |
@@ -0,0 +1,34 @@ +import argparse +import sys +import warnings +import numpy as np +import skimage.io +import skimage.filters +import skimage.util +from skimage.morphology import disk + +filterOptions = { + 'median' : lambda img_raw, radius: skimage.filters.median(img_raw, disk(radius)), + 'gaussian' : lambda img_raw, radius: skimage.filters.gaussian(img_raw, sigma=radius), + 'prewitt' : lambda img_raw, radius: skimage.filters.prewitt(img_raw), + 'sobel' : lambda img_raw, radius: skimage.filters.sobel(img_raw), + 'scharr' : lambda img_raw, radius: skimage.filters.scharr(img_raw), +} + +if __name__ == "__main__": + parser = argparse.ArgumentParser() + parser.add_argument('input_file', type=argparse.FileType('r'), default=sys.stdin, help='input file') + parser.add_argument('out_file', type=argparse.FileType('w'), default=sys.stdin, help='out file (TIFF)') + parser.add_argument('filter_type', choices=filterOptions.keys(), help='conversion type') + parser.add_argument('radius', default=3.0, type=float, help='Radius/Sigma') + args = parser.parse_args() + + img_in = skimage.io.imread(args.input_file.name) + res = filterOptions[args.filter_type](img_in, args.radius) + res[res<-1]=-1 + res[res>1]=1 + + with warnings.catch_warnings(): + warnings.simplefilter("ignore") + res = skimage.util.img_as_uint(res) #Attention: precision loss + skimage.io.imsave(args.out_file.name, res, plugin='tifffile') |
b |
diff -r 000000000000 -r f264ae82f735 test-data/res.tif |
b |
Binary file test-data/res.tif has changed |
b |
diff -r 000000000000 -r f264ae82f735 test-data/sample.tif |
b |
Binary file test-data/sample.tif has changed |