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