Mercurial > repos > imgteam > wsi_extract_top_view
annotate wsi_extract_top_view.py @ 1:cfe88c6041e9 draft
"planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/wsi_extract_top_view/ commit 3d389fdec0db29cf6fbd783c0501455bf624fa90"
author | imgteam |
---|---|
date | Wed, 18 Dec 2019 05:03:44 -0500 |
parents | a1d02d2e814a |
children | 3bd767eee603 |
rev | line source |
---|---|
0
a1d02d2e814a
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/wsi_extract_top_view/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff
changeset
|
1 import argparse |
a1d02d2e814a
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/wsi_extract_top_view/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff
changeset
|
2 import openslide |
a1d02d2e814a
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/wsi_extract_top_view/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff
changeset
|
3 import os |
a1d02d2e814a
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/wsi_extract_top_view/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff
changeset
|
4 import fnmatch |
a1d02d2e814a
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/wsi_extract_top_view/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff
changeset
|
5 import skimage.io |
a1d02d2e814a
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/wsi_extract_top_view/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff
changeset
|
6 import numpy as np |
1
cfe88c6041e9
"planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/wsi_extract_top_view/ commit 3d389fdec0db29cf6fbd783c0501455bf624fa90"
imgteam
parents:
0
diff
changeset
|
7 |
0
a1d02d2e814a
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/wsi_extract_top_view/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff
changeset
|
8 def wsi_extract_top_view(input_path, out_path): |
a1d02d2e814a
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/wsi_extract_top_view/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff
changeset
|
9 img_raw = openslide.OpenSlide(input_path) |
a1d02d2e814a
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/wsi_extract_top_view/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff
changeset
|
10 top_size = img_raw.level_dimensions[len(img_raw.level_dimensions)-1] |
a1d02d2e814a
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/wsi_extract_top_view/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff
changeset
|
11 img_area = img_raw.read_region((0,0), len(img_raw.level_dimensions)-1, top_size) |
a1d02d2e814a
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/wsi_extract_top_view/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff
changeset
|
12 img_area = np.asarray(img_area, dtype=np.uint8) |
a1d02d2e814a
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/wsi_extract_top_view/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff
changeset
|
13 skimage.io.imsave(out_path, img_area, plugin="tifffile") |
a1d02d2e814a
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/wsi_extract_top_view/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff
changeset
|
14 |
a1d02d2e814a
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/wsi_extract_top_view/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff
changeset
|
15 |
a1d02d2e814a
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/wsi_extract_top_view/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff
changeset
|
16 if __name__ == "__main__": |
a1d02d2e814a
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/wsi_extract_top_view/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff
changeset
|
17 parser = argparse.ArgumentParser() |
a1d02d2e814a
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/wsi_extract_top_view/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff
changeset
|
18 parser.add_argument('input_file', type=argparse.FileType('r'), help='input file') |
a1d02d2e814a
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/wsi_extract_top_view/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff
changeset
|
19 parser.add_argument('out_file', help='out file') |
a1d02d2e814a
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/wsi_extract_top_view/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff
changeset
|
20 args = parser.parse_args() |
1
cfe88c6041e9
"planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/wsi_extract_top_view/ commit 3d389fdec0db29cf6fbd783c0501455bf624fa90"
imgteam
parents:
0
diff
changeset
|
21 |
0
a1d02d2e814a
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/wsi_extract_top_view/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff
changeset
|
22 wsi_extract_top_view(args.input_file.name, args.out_file) |