annotate wsi_extract_top_view.py @ 1:257397c40c25 draft default tip

planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/wsi_extract_top_view/ commit d93e1dd276027cfc3fb518236110395a23d96f66
author thomaswollmann
date Wed, 16 Jan 2019 15:36:04 -0500
parents 9f01fd145af4
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
9f01fd145af4 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/wsi_extract_top_view/ commit 42d972afdd700fccae1017c06efbfd06b9c96791
thomaswollmann
parents:
diff changeset
1 import argparse
9f01fd145af4 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/wsi_extract_top_view/ commit 42d972afdd700fccae1017c06efbfd06b9c96791
thomaswollmann
parents:
diff changeset
2 import openslide
9f01fd145af4 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/wsi_extract_top_view/ commit 42d972afdd700fccae1017c06efbfd06b9c96791
thomaswollmann
parents:
diff changeset
3 import os
9f01fd145af4 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/wsi_extract_top_view/ commit 42d972afdd700fccae1017c06efbfd06b9c96791
thomaswollmann
parents:
diff changeset
4 import fnmatch
9f01fd145af4 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/wsi_extract_top_view/ commit 42d972afdd700fccae1017c06efbfd06b9c96791
thomaswollmann
parents:
diff changeset
5 import skimage.io
9f01fd145af4 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/wsi_extract_top_view/ commit 42d972afdd700fccae1017c06efbfd06b9c96791
thomaswollmann
parents:
diff changeset
6 import numpy as np
9f01fd145af4 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/wsi_extract_top_view/ commit 42d972afdd700fccae1017c06efbfd06b9c96791
thomaswollmann
parents:
diff changeset
7
9f01fd145af4 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/wsi_extract_top_view/ commit 42d972afdd700fccae1017c06efbfd06b9c96791
thomaswollmann
parents:
diff changeset
8 def wsi_extract_top_view(input_path, out_path):
9f01fd145af4 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/wsi_extract_top_view/ commit 42d972afdd700fccae1017c06efbfd06b9c96791
thomaswollmann
parents:
diff changeset
9 img_raw = openslide.OpenSlide(input_path)
9f01fd145af4 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/wsi_extract_top_view/ commit 42d972afdd700fccae1017c06efbfd06b9c96791
thomaswollmann
parents:
diff changeset
10 top_size = img_raw.level_dimensions[len(img_raw.level_dimensions)-1]
9f01fd145af4 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/wsi_extract_top_view/ commit 42d972afdd700fccae1017c06efbfd06b9c96791
thomaswollmann
parents:
diff changeset
11 img_area = img_raw.read_region((0,0), len(img_raw.level_dimensions)-1, top_size)
9f01fd145af4 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/wsi_extract_top_view/ commit 42d972afdd700fccae1017c06efbfd06b9c96791
thomaswollmann
parents:
diff changeset
12 img_area = np.asarray(img_area, dtype=np.uint8)
9f01fd145af4 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/wsi_extract_top_view/ commit 42d972afdd700fccae1017c06efbfd06b9c96791
thomaswollmann
parents:
diff changeset
13 skimage.io.imsave(out_path, img_area, plugin="tifffile")
9f01fd145af4 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/wsi_extract_top_view/ commit 42d972afdd700fccae1017c06efbfd06b9c96791
thomaswollmann
parents:
diff changeset
14
9f01fd145af4 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/wsi_extract_top_view/ commit 42d972afdd700fccae1017c06efbfd06b9c96791
thomaswollmann
parents:
diff changeset
15
9f01fd145af4 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/wsi_extract_top_view/ commit 42d972afdd700fccae1017c06efbfd06b9c96791
thomaswollmann
parents:
diff changeset
16 if __name__ == "__main__":
9f01fd145af4 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/wsi_extract_top_view/ commit 42d972afdd700fccae1017c06efbfd06b9c96791
thomaswollmann
parents:
diff changeset
17 parser = argparse.ArgumentParser()
9f01fd145af4 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/wsi_extract_top_view/ commit 42d972afdd700fccae1017c06efbfd06b9c96791
thomaswollmann
parents:
diff changeset
18 parser.add_argument('input_file', type=argparse.FileType('r'), help='input file')
9f01fd145af4 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/wsi_extract_top_view/ commit 42d972afdd700fccae1017c06efbfd06b9c96791
thomaswollmann
parents:
diff changeset
19 parser.add_argument('out_file', help='out file')
9f01fd145af4 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/wsi_extract_top_view/ commit 42d972afdd700fccae1017c06efbfd06b9c96791
thomaswollmann
parents:
diff changeset
20 args = parser.parse_args()
9f01fd145af4 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/wsi_extract_top_view/ commit 42d972afdd700fccae1017c06efbfd06b9c96791
thomaswollmann
parents:
diff changeset
21
9f01fd145af4 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/wsi_extract_top_view/ commit 42d972afdd700fccae1017c06efbfd06b9c96791
thomaswollmann
parents:
diff changeset
22 wsi_extract_top_view(args.input_file.name, args.out_file)