comparison histogram_equalization.py @ 0:70316d792fc9 draft

planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/2d_histogram_equalization/ commit 767d7fec860d01468701c4e6dc270a7f1c74d53c
author imgteam
date Tue, 23 Jul 2019 14:07:07 -0400
parents
children 77f7159d775a
comparison
equal deleted inserted replaced
-1:000000000000 0:70316d792fc9
1 import argparse
2 import os
3 import sys
4 import skimage.io
5 import skimage.exposure
6 import skimage.util
7
8 hOptions = {
9 'default' : lambda img_raw: skimage.exposure.equalize_hist(img_raw),
10 'clahe' : lambda img_raw: skimage.exposure.equalize_adapthist(img_raw)
11 }
12
13 if __name__ == "__main__":
14 parser = argparse.ArgumentParser(description='Histogram equalization')
15 parser.add_argument('input_file', type=argparse.FileType('r'), default=sys.stdin, help='input file')
16 parser.add_argument('out_file', type=argparse.FileType('w'), default=sys.stdin, help='out file (TIFF)')
17 parser.add_argument('h_type', choices=hOptions.keys(), help='histogram equalization method')
18 args = parser.parse_args()
19
20 img_in = skimage.io.imread(args.input_file.name)
21 res = hOptions[args.h_type](img_in)
22 res = skimage.util.img_as_uint(res)
23 skimage.io.imsave(args.out_file.name, res, plugin="tifffile")