Mercurial > repos > imgteam > 2d_histogram_equalization
annotate histogram_equalization.py @ 1:77f7159d775a draft
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/2d_histogram_equalization/ commit 2286a6c9da88596349ed9d967c51541409c0a7bf
author | imgteam |
---|---|
date | Mon, 13 Nov 2023 22:10:25 +0000 |
parents | 70316d792fc9 |
children | b1c2c210813c |
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 |
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
|
4 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
|
5 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
|
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 = { |
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
|
9 '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
|
10 '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
|
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") |