Mercurial > repos > imgteam > 2d_histogram_equalization
annotate 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 |
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 os |
70316d792fc9
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/2d_histogram_equalization/ commit 767d7fec860d01468701c4e6dc270a7f1c74d53c
imgteam
parents:
diff
changeset
|
3 import sys |
70316d792fc9
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/2d_histogram_equalization/ commit 767d7fec860d01468701c4e6dc270a7f1c74d53c
imgteam
parents:
diff
changeset
|
4 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
|
5 import skimage.exposure |
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.util |
70316d792fc9
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/2d_histogram_equalization/ commit 767d7fec860d01468701c4e6dc270a7f1c74d53c
imgteam
parents:
diff
changeset
|
7 |
70316d792fc9
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/2d_histogram_equalization/ commit 767d7fec860d01468701c4e6dc270a7f1c74d53c
imgteam
parents:
diff
changeset
|
8 hOptions = { |
70316d792fc9
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/2d_histogram_equalization/ commit 767d7fec860d01468701c4e6dc270a7f1c74d53c
imgteam
parents:
diff
changeset
|
9 'default' : lambda img_raw: skimage.exposure.equalize_hist(img_raw), |
70316d792fc9
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/2d_histogram_equalization/ commit 767d7fec860d01468701c4e6dc270a7f1c74d53c
imgteam
parents:
diff
changeset
|
10 'clahe' : lambda img_raw: skimage.exposure.equalize_adapthist(img_raw) |
70316d792fc9
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/2d_histogram_equalization/ commit 767d7fec860d01468701c4e6dc270a7f1c74d53c
imgteam
parents:
diff
changeset
|
11 } |
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 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
|
14 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
|
15 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
|
16 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
|
17 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
|
18 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
|
19 |
70316d792fc9
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/2d_histogram_equalization/ commit 767d7fec860d01468701c4e6dc270a7f1c74d53c
imgteam
parents:
diff
changeset
|
20 img_in = skimage.io.imread(args.input_file.name) |
70316d792fc9
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/2d_histogram_equalization/ commit 767d7fec860d01468701c4e6dc270a7f1c74d53c
imgteam
parents:
diff
changeset
|
21 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
|
22 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
|
23 skimage.io.imsave(args.out_file.name, res, plugin="tifffile") |