annotate histogram_equalization.py @ 3:b1c2c210813c draft default tip

planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/2d_histogram_equalization/ commit c86a1b93cb7732f7331a981d13465653cc1a2790
author imgteam
date Wed, 24 Apr 2024 08:11:54 +0000
parents 77f7159d775a
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
70316d792fc9 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/2d_histogram_equalization/ commit 767d7fec860d01468701c4e6dc270a7f1c74d53c
imgteam
parents:
diff changeset
1 import argparse
70316d792fc9 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/2d_histogram_equalization/ commit 767d7fec860d01468701c4e6dc270a7f1c74d53c
imgteam
parents:
diff changeset
2 import sys
1
77f7159d775a planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/2d_histogram_equalization/ commit 2286a6c9da88596349ed9d967c51541409c0a7bf
imgteam
parents: 0
diff changeset
3
3
b1c2c210813c planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/2d_histogram_equalization/ commit c86a1b93cb7732f7331a981d13465653cc1a2790
imgteam
parents: 1
diff changeset
4 import giatools.io
1
77f7159d775a planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/2d_histogram_equalization/ commit 2286a6c9da88596349ed9d967c51541409c0a7bf
imgteam
parents: 0
diff changeset
5 import skimage.exposure
0
70316d792fc9 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/2d_histogram_equalization/ commit 767d7fec860d01468701c4e6dc270a7f1c74d53c
imgteam
parents:
diff changeset
6 import skimage.io
70316d792fc9 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/2d_histogram_equalization/ commit 767d7fec860d01468701c4e6dc270a7f1c74d53c
imgteam
parents:
diff changeset
7 import skimage.util
70316d792fc9 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/2d_histogram_equalization/ commit 767d7fec860d01468701c4e6dc270a7f1c74d53c
imgteam
parents:
diff changeset
8
70316d792fc9 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/2d_histogram_equalization/ commit 767d7fec860d01468701c4e6dc270a7f1c74d53c
imgteam
parents:
diff changeset
9 hOptions = {
1
77f7159d775a planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/2d_histogram_equalization/ commit 2286a6c9da88596349ed9d967c51541409c0a7bf
imgteam
parents: 0
diff changeset
10 'default': lambda img_raw: skimage.exposure.equalize_hist(img_raw),
77f7159d775a planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/2d_histogram_equalization/ commit 2286a6c9da88596349ed9d967c51541409c0a7bf
imgteam
parents: 0
diff changeset
11 'clahe': lambda img_raw: skimage.exposure.equalize_adapthist(img_raw)
0
70316d792fc9 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/2d_histogram_equalization/ commit 767d7fec860d01468701c4e6dc270a7f1c74d53c
imgteam
parents:
diff changeset
12 }
70316d792fc9 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/2d_histogram_equalization/ commit 767d7fec860d01468701c4e6dc270a7f1c74d53c
imgteam
parents:
diff changeset
13
70316d792fc9 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/2d_histogram_equalization/ commit 767d7fec860d01468701c4e6dc270a7f1c74d53c
imgteam
parents:
diff changeset
14 if __name__ == "__main__":
70316d792fc9 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/2d_histogram_equalization/ commit 767d7fec860d01468701c4e6dc270a7f1c74d53c
imgteam
parents:
diff changeset
15 parser = argparse.ArgumentParser(description='Histogram equalization')
70316d792fc9 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/2d_histogram_equalization/ commit 767d7fec860d01468701c4e6dc270a7f1c74d53c
imgteam
parents:
diff changeset
16 parser.add_argument('input_file', type=argparse.FileType('r'), default=sys.stdin, help='input file')
70316d792fc9 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/2d_histogram_equalization/ commit 767d7fec860d01468701c4e6dc270a7f1c74d53c
imgteam
parents:
diff changeset
17 parser.add_argument('out_file', type=argparse.FileType('w'), default=sys.stdin, help='out file (TIFF)')
70316d792fc9 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/2d_histogram_equalization/ commit 767d7fec860d01468701c4e6dc270a7f1c74d53c
imgteam
parents:
diff changeset
18 parser.add_argument('h_type', choices=hOptions.keys(), help='histogram equalization method')
70316d792fc9 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/2d_histogram_equalization/ commit 767d7fec860d01468701c4e6dc270a7f1c74d53c
imgteam
parents:
diff changeset
19 args = parser.parse_args()
70316d792fc9 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/2d_histogram_equalization/ commit 767d7fec860d01468701c4e6dc270a7f1c74d53c
imgteam
parents:
diff changeset
20
3
b1c2c210813c planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/2d_histogram_equalization/ commit c86a1b93cb7732f7331a981d13465653cc1a2790
imgteam
parents: 1
diff changeset
21 img_in = giatools.io.imread(args.input_file.name)
0
70316d792fc9 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/2d_histogram_equalization/ commit 767d7fec860d01468701c4e6dc270a7f1c74d53c
imgteam
parents:
diff changeset
22 res = hOptions[args.h_type](img_in)
70316d792fc9 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/2d_histogram_equalization/ commit 767d7fec860d01468701c4e6dc270a7f1c74d53c
imgteam
parents:
diff changeset
23 res = skimage.util.img_as_uint(res)
70316d792fc9 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/2d_histogram_equalization/ commit 767d7fec860d01468701c4e6dc270a7f1c74d53c
imgteam
parents:
diff changeset
24 skimage.io.imsave(args.out_file.name, res, plugin="tifffile")