annotate anisotropic_diffusion.py @ 0:9a30c8f0f651 draft

planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/anisotropic-diffusion/ commit 3036169a656a17a8c73a93241e375693f281bce8
author thomaswollmann
date Tue, 21 Feb 2017 09:11:07 -0500
parents
children 6be26440a8ec
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
9a30c8f0f651 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/anisotropic-diffusion/ commit 3036169a656a17a8c73a93241e375693f281bce8
thomaswollmann
parents:
diff changeset
1 import argparse
9a30c8f0f651 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/anisotropic-diffusion/ commit 3036169a656a17a8c73a93241e375693f281bce8
thomaswollmann
parents:
diff changeset
2 import sys
9a30c8f0f651 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/anisotropic-diffusion/ commit 3036169a656a17a8c73a93241e375693f281bce8
thomaswollmann
parents:
diff changeset
3 import warnings
9a30c8f0f651 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/anisotropic-diffusion/ commit 3036169a656a17a8c73a93241e375693f281bce8
thomaswollmann
parents:
diff changeset
4 import numpy as np
9a30c8f0f651 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/anisotropic-diffusion/ commit 3036169a656a17a8c73a93241e375693f281bce8
thomaswollmann
parents:
diff changeset
5 import skimage.io
9a30c8f0f651 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/anisotropic-diffusion/ commit 3036169a656a17a8c73a93241e375693f281bce8
thomaswollmann
parents:
diff changeset
6 import skimage.util
9a30c8f0f651 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/anisotropic-diffusion/ commit 3036169a656a17a8c73a93241e375693f281bce8
thomaswollmann
parents:
diff changeset
7 from medpy.filter.smoothing import anisotropic_diffusion
9a30c8f0f651 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/anisotropic-diffusion/ commit 3036169a656a17a8c73a93241e375693f281bce8
thomaswollmann
parents:
diff changeset
8
9a30c8f0f651 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/anisotropic-diffusion/ commit 3036169a656a17a8c73a93241e375693f281bce8
thomaswollmann
parents:
diff changeset
9 parser = argparse.ArgumentParser()
9a30c8f0f651 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/anisotropic-diffusion/ commit 3036169a656a17a8c73a93241e375693f281bce8
thomaswollmann
parents:
diff changeset
10 parser.add_argument('input_file', type=argparse.FileType('r'), default=sys.stdin, help='input file')
9a30c8f0f651 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/anisotropic-diffusion/ commit 3036169a656a17a8c73a93241e375693f281bce8
thomaswollmann
parents:
diff changeset
11 parser.add_argument('out_file', type=argparse.FileType('w'), default=sys.stdin, help='out file (TIFF)')
9a30c8f0f651 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/anisotropic-diffusion/ commit 3036169a656a17a8c73a93241e375693f281bce8
thomaswollmann
parents:
diff changeset
12 parser.add_argument('niter', type=int, help='Number of iterations', default=1)
9a30c8f0f651 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/anisotropic-diffusion/ commit 3036169a656a17a8c73a93241e375693f281bce8
thomaswollmann
parents:
diff changeset
13 parser.add_argument('kappa', type=int, help='Conduction coefficient', default=50)
9a30c8f0f651 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/anisotropic-diffusion/ commit 3036169a656a17a8c73a93241e375693f281bce8
thomaswollmann
parents:
diff changeset
14 parser.add_argument('gamma', type=float, help='Speed of diffusion', default=0.1)
9a30c8f0f651 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/anisotropic-diffusion/ commit 3036169a656a17a8c73a93241e375693f281bce8
thomaswollmann
parents:
diff changeset
15 parser.add_argument('eqoption', type=int, choices=[1,2], help='Perona Malik diffusion equation', default=1)
9a30c8f0f651 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/anisotropic-diffusion/ commit 3036169a656a17a8c73a93241e375693f281bce8
thomaswollmann
parents:
diff changeset
16 args = parser.parse_args()
9a30c8f0f651 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/anisotropic-diffusion/ commit 3036169a656a17a8c73a93241e375693f281bce8
thomaswollmann
parents:
diff changeset
17
9a30c8f0f651 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/anisotropic-diffusion/ commit 3036169a656a17a8c73a93241e375693f281bce8
thomaswollmann
parents:
diff changeset
18 img_in = skimage.io.imread(args.input_file.name)
9a30c8f0f651 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/anisotropic-diffusion/ commit 3036169a656a17a8c73a93241e375693f281bce8
thomaswollmann
parents:
diff changeset
19 res = anisotropic_diffusion(img_raw, niter=args.niter, kappa=args.kappa, gamma=args.gamma, option=args.eqoption)
9a30c8f0f651 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/anisotropic-diffusion/ commit 3036169a656a17a8c73a93241e375693f281bce8
thomaswollmann
parents:
diff changeset
20 res[res<-1]=-1
9a30c8f0f651 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/anisotropic-diffusion/ commit 3036169a656a17a8c73a93241e375693f281bce8
thomaswollmann
parents:
diff changeset
21 res[res>1]=1
9a30c8f0f651 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/anisotropic-diffusion/ commit 3036169a656a17a8c73a93241e375693f281bce8
thomaswollmann
parents:
diff changeset
22
9a30c8f0f651 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/anisotropic-diffusion/ commit 3036169a656a17a8c73a93241e375693f281bce8
thomaswollmann
parents:
diff changeset
23 with warnings.catch_warnings():
9a30c8f0f651 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/anisotropic-diffusion/ commit 3036169a656a17a8c73a93241e375693f281bce8
thomaswollmann
parents:
diff changeset
24 warnings.simplefilter("ignore")
9a30c8f0f651 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/anisotropic-diffusion/ commit 3036169a656a17a8c73a93241e375693f281bce8
thomaswollmann
parents:
diff changeset
25 res = skimage.util.img_as_uint(res) #Attention: precision loss
9a30c8f0f651 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/anisotropic-diffusion/ commit 3036169a656a17a8c73a93241e375693f281bce8
thomaswollmann
parents:
diff changeset
26 skimage.io.imsave(args.out_file.name, res, plugin='tifffile')