annotate anisotropic_diffusion.py @ 2:b0b92445dd91 draft default tip

planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/anisotropic-diffusion/ commit d93e1dd276027cfc3fb518236110395a23d96f66
author thomaswollmann
date Wed, 16 Jan 2019 15:29:41 -0500
parents 626be11c43fc
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
babb41158e9f planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/anisotropic-diffusion/ commit 3036169a656a17a8c73a93241e375693f281bce8
thomaswollmann
parents:
diff changeset
1 import argparse
babb41158e9f planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/anisotropic-diffusion/ commit 3036169a656a17a8c73a93241e375693f281bce8
thomaswollmann
parents:
diff changeset
2 import sys
babb41158e9f planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/anisotropic-diffusion/ commit 3036169a656a17a8c73a93241e375693f281bce8
thomaswollmann
parents:
diff changeset
3 import warnings
babb41158e9f 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
babb41158e9f planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/anisotropic-diffusion/ commit 3036169a656a17a8c73a93241e375693f281bce8
thomaswollmann
parents:
diff changeset
5 import skimage.io
babb41158e9f planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/anisotropic-diffusion/ commit 3036169a656a17a8c73a93241e375693f281bce8
thomaswollmann
parents:
diff changeset
6 import skimage.util
babb41158e9f 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
babb41158e9f planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/anisotropic-diffusion/ commit 3036169a656a17a8c73a93241e375693f281bce8
thomaswollmann
parents:
diff changeset
8
babb41158e9f planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/anisotropic-diffusion/ commit 3036169a656a17a8c73a93241e375693f281bce8
thomaswollmann
parents:
diff changeset
9 parser = argparse.ArgumentParser()
babb41158e9f 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')
babb41158e9f 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)')
babb41158e9f 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)
babb41158e9f 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)
babb41158e9f 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)
babb41158e9f 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)
babb41158e9f 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()
babb41158e9f planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/anisotropic-diffusion/ commit 3036169a656a17a8c73a93241e375693f281bce8
thomaswollmann
parents:
diff changeset
17
1
626be11c43fc planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/anisotropic-diffusion/ commit 27a6350188f687411bdd6bfe0d569c0803389ca0
thomaswollmann
parents: 0
diff changeset
18 with warnings.catch_warnings():
626be11c43fc planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/anisotropic-diffusion/ commit 27a6350188f687411bdd6bfe0d569c0803389ca0
thomaswollmann
parents: 0
diff changeset
19 warnings.simplefilter("ignore") #to ignore FutureWarning as well
0
babb41158e9f planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/anisotropic-diffusion/ commit 3036169a656a17a8c73a93241e375693f281bce8
thomaswollmann
parents:
diff changeset
20
1
626be11c43fc planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/anisotropic-diffusion/ commit 27a6350188f687411bdd6bfe0d569c0803389ca0
thomaswollmann
parents: 0
diff changeset
21 img_in = skimage.io.imread(args.input_file.name, plugin='tifffile')
626be11c43fc planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/anisotropic-diffusion/ commit 27a6350188f687411bdd6bfe0d569c0803389ca0
thomaswollmann
parents: 0
diff changeset
22 res = anisotropic_diffusion(img_in, niter=args.niter, kappa=args.kappa, gamma=args.gamma, option=args.eqoption)
626be11c43fc planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/anisotropic-diffusion/ commit 27a6350188f687411bdd6bfe0d569c0803389ca0
thomaswollmann
parents: 0
diff changeset
23 res[res<-1]=-1
626be11c43fc planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/anisotropic-diffusion/ commit 27a6350188f687411bdd6bfe0d569c0803389ca0
thomaswollmann
parents: 0
diff changeset
24 res[res>1]=1
626be11c43fc planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/anisotropic-diffusion/ commit 27a6350188f687411bdd6bfe0d569c0803389ca0
thomaswollmann
parents: 0
diff changeset
25
0
babb41158e9f planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/anisotropic-diffusion/ commit 3036169a656a17a8c73a93241e375693f281bce8
thomaswollmann
parents:
diff changeset
26 res = skimage.util.img_as_uint(res) #Attention: precision loss
1
626be11c43fc planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/anisotropic-diffusion/ commit 27a6350188f687411bdd6bfe0d569c0803389ca0
thomaswollmann
parents: 0
diff changeset
27
626be11c43fc planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/anisotropic-diffusion/ commit 27a6350188f687411bdd6bfe0d569c0803389ca0
thomaswollmann
parents: 0
diff changeset
28 skimage.io.imsave(args.out_file.name, res, plugin='tifffile')