comparison anisotropic_diffusion.py @ 2:e6987afa0484 draft

planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/anisotropic-diffusion/ commit 2286a6c9da88596349ed9d967c51541409c0a7bf
author imgteam
date Mon, 13 Nov 2023 22:10:29 +0000
parents 17d3cfba9b5a
children 6ad5de2c5b7c
comparison
equal deleted inserted replaced
1:17d3cfba9b5a 2:e6987afa0484
1 import argparse 1 import argparse
2 import sys 2 import sys
3 import warnings 3 import warnings
4 import numpy as np 4
5 import skimage.io 5 import skimage.io
6 import skimage.util 6 import skimage.util
7 from medpy.filter.smoothing import anisotropic_diffusion 7 from medpy.filter.smoothing import anisotropic_diffusion
8 8
9 parser = argparse.ArgumentParser() 9 parser = argparse.ArgumentParser()
10 parser.add_argument('input_file', type=argparse.FileType('r'), default=sys.stdin, help='input file') 10 parser.add_argument('input_file', type=argparse.FileType('r'), default=sys.stdin, help='input file')
11 parser.add_argument('out_file', type=argparse.FileType('w'), default=sys.stdin, help='out file (TIFF)') 11 parser.add_argument('out_file', type=argparse.FileType('w'), default=sys.stdin, help='out file (TIFF)')
12 parser.add_argument('niter', type=int, help='Number of iterations', default=1) 12 parser.add_argument('niter', type=int, help='Number of iterations', default=1)
13 parser.add_argument('kappa', type=int, help='Conduction coefficient', default=50) 13 parser.add_argument('kappa', type=int, help='Conduction coefficient', default=50)
14 parser.add_argument('gamma', type=float, help='Speed of diffusion', default=0.1) 14 parser.add_argument('gamma', type=float, help='Speed of diffusion', default=0.1)
15 parser.add_argument('eqoption', type=int, choices=[1,2], help='Perona Malik diffusion equation', default=1) 15 parser.add_argument('eqoption', type=int, choices=[1, 2], help='Perona Malik diffusion equation', default=1)
16 args = parser.parse_args() 16 args = parser.parse_args()
17 17
18 with warnings.catch_warnings(): 18 with warnings.catch_warnings():
19 warnings.simplefilter("ignore") #to ignore FutureWarning as well 19 warnings.simplefilter("ignore") # to ignore FutureWarning as well
20 20
21 img_in = skimage.io.imread(args.input_file.name, plugin='tifffile') 21 img_in = skimage.io.imread(args.input_file.name, plugin='tifffile')
22 res = anisotropic_diffusion(img_in, niter=args.niter, kappa=args.kappa, gamma=args.gamma, option=args.eqoption) 22 res = anisotropic_diffusion(img_in, niter=args.niter, kappa=args.kappa, gamma=args.gamma, option=args.eqoption)
23 res[res<-1]=-1 23 res[res < -1] = -1
24 res[res>1]=1 24 res[res > +1] = +1
25 25
26 res = skimage.util.img_as_uint(res) #Attention: precision loss 26 res = skimage.util.img_as_uint(res) # Attention: precision loss
27 27
28 skimage.io.imsave(args.out_file.name, res, plugin='tifffile') 28 skimage.io.imsave(args.out_file.name, res, plugin='tifffile')