Mercurial > repos > perssond > s3segmenter
annotate save_tifffile_pyramid.py @ 1:41e8efe8df43 draft
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit c8f72e04db2cc6cc26f0359d5aa3b1a972bc6d53"
author | watsocam |
---|---|
date | Fri, 11 Mar 2022 23:37:49 +0000 |
parents | |
children |
rev | line source |
---|---|
1
41e8efe8df43
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit c8f72e04db2cc6cc26f0359d5aa3b1a972bc6d53"
watsocam
parents:
diff
changeset
|
1 import numpy as np |
41e8efe8df43
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit c8f72e04db2cc6cc26f0359d5aa3b1a972bc6d53"
watsocam
parents:
diff
changeset
|
2 import tifffile |
41e8efe8df43
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit c8f72e04db2cc6cc26f0359d5aa3b1a972bc6d53"
watsocam
parents:
diff
changeset
|
3 import skimage.transform |
41e8efe8df43
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit c8f72e04db2cc6cc26f0359d5aa3b1a972bc6d53"
watsocam
parents:
diff
changeset
|
4 |
41e8efe8df43
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit c8f72e04db2cc6cc26f0359d5aa3b1a972bc6d53"
watsocam
parents:
diff
changeset
|
5 PHYSICAL_SIZE_UNIT = ['Ym', 'Zm', 'Em', 'Pm', 'Tm', 'Gm', 'Mm', 'km', 'hm', 'dam', 'm', 'dm', 'cm', 'mm', 'µm', 'nm', 'pm', 'fm', 'am', 'zm', 'ym', 'Å', 'thou', 'li', 'in', 'ft', 'yd', 'mi', 'ua', 'ly', 'pc', 'pt', 'pixel', 'reference frame'] |
41e8efe8df43
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit c8f72e04db2cc6cc26f0359d5aa3b1a972bc6d53"
watsocam
parents:
diff
changeset
|
6 |
41e8efe8df43
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit c8f72e04db2cc6cc26f0359d5aa3b1a972bc6d53"
watsocam
parents:
diff
changeset
|
7 def normalize_image_shape(img): |
41e8efe8df43
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit c8f72e04db2cc6cc26f0359d5aa3b1a972bc6d53"
watsocam
parents:
diff
changeset
|
8 assert img.ndim in (2, 3), ( |
41e8efe8df43
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit c8f72e04db2cc6cc26f0359d5aa3b1a972bc6d53"
watsocam
parents:
diff
changeset
|
9 'image must be 2D (Y, X) or 3D (C, Y, X)' |
41e8efe8df43
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit c8f72e04db2cc6cc26f0359d5aa3b1a972bc6d53"
watsocam
parents:
diff
changeset
|
10 ) |
41e8efe8df43
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit c8f72e04db2cc6cc26f0359d5aa3b1a972bc6d53"
watsocam
parents:
diff
changeset
|
11 if img.ndim == 2: |
41e8efe8df43
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit c8f72e04db2cc6cc26f0359d5aa3b1a972bc6d53"
watsocam
parents:
diff
changeset
|
12 img = img.reshape(1, *img.shape) |
41e8efe8df43
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit c8f72e04db2cc6cc26f0359d5aa3b1a972bc6d53"
watsocam
parents:
diff
changeset
|
13 assert np.argmin(img.shape) == 0, ( |
41e8efe8df43
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit c8f72e04db2cc6cc26f0359d5aa3b1a972bc6d53"
watsocam
parents:
diff
changeset
|
14 '3D image must be in (C, Y, X) order' |
41e8efe8df43
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit c8f72e04db2cc6cc26f0359d5aa3b1a972bc6d53"
watsocam
parents:
diff
changeset
|
15 ) |
41e8efe8df43
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit c8f72e04db2cc6cc26f0359d5aa3b1a972bc6d53"
watsocam
parents:
diff
changeset
|
16 return img |
41e8efe8df43
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit c8f72e04db2cc6cc26f0359d5aa3b1a972bc6d53"
watsocam
parents:
diff
changeset
|
17 |
41e8efe8df43
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit c8f72e04db2cc6cc26f0359d5aa3b1a972bc6d53"
watsocam
parents:
diff
changeset
|
18 def save_pyramid( |
41e8efe8df43
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit c8f72e04db2cc6cc26f0359d5aa3b1a972bc6d53"
watsocam
parents:
diff
changeset
|
19 out_img, output_path, |
41e8efe8df43
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit c8f72e04db2cc6cc26f0359d5aa3b1a972bc6d53"
watsocam
parents:
diff
changeset
|
20 pixel_sizes=(1, 1), |
41e8efe8df43
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit c8f72e04db2cc6cc26f0359d5aa3b1a972bc6d53"
watsocam
parents:
diff
changeset
|
21 pixel_size_units=('µm', 'µm'), |
41e8efe8df43
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit c8f72e04db2cc6cc26f0359d5aa3b1a972bc6d53"
watsocam
parents:
diff
changeset
|
22 channel_names=None, |
41e8efe8df43
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit c8f72e04db2cc6cc26f0359d5aa3b1a972bc6d53"
watsocam
parents:
diff
changeset
|
23 software=None, |
41e8efe8df43
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit c8f72e04db2cc6cc26f0359d5aa3b1a972bc6d53"
watsocam
parents:
diff
changeset
|
24 is_mask=False |
41e8efe8df43
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit c8f72e04db2cc6cc26f0359d5aa3b1a972bc6d53"
watsocam
parents:
diff
changeset
|
25 ): |
41e8efe8df43
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit c8f72e04db2cc6cc26f0359d5aa3b1a972bc6d53"
watsocam
parents:
diff
changeset
|
26 assert '.ome.tif' in str(output_path) |
41e8efe8df43
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit c8f72e04db2cc6cc26f0359d5aa3b1a972bc6d53"
watsocam
parents:
diff
changeset
|
27 assert len(pixel_sizes) == len(pixel_size_units) == 2 |
41e8efe8df43
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit c8f72e04db2cc6cc26f0359d5aa3b1a972bc6d53"
watsocam
parents:
diff
changeset
|
28 assert out_img.ndim in (2, 3), ( |
41e8efe8df43
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit c8f72e04db2cc6cc26f0359d5aa3b1a972bc6d53"
watsocam
parents:
diff
changeset
|
29 'image must be either 2D (Y, X) or 3D (C, Y, X)' |
41e8efe8df43
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit c8f72e04db2cc6cc26f0359d5aa3b1a972bc6d53"
watsocam
parents:
diff
changeset
|
30 ) |
41e8efe8df43
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit c8f72e04db2cc6cc26f0359d5aa3b1a972bc6d53"
watsocam
parents:
diff
changeset
|
31 |
41e8efe8df43
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit c8f72e04db2cc6cc26f0359d5aa3b1a972bc6d53"
watsocam
parents:
diff
changeset
|
32 img_shape_ori = out_img.shape |
41e8efe8df43
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit c8f72e04db2cc6cc26f0359d5aa3b1a972bc6d53"
watsocam
parents:
diff
changeset
|
33 out_img = normalize_image_shape(out_img) |
41e8efe8df43
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit c8f72e04db2cc6cc26f0359d5aa3b1a972bc6d53"
watsocam
parents:
diff
changeset
|
34 img_shape = out_img.shape |
41e8efe8df43
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit c8f72e04db2cc6cc26f0359d5aa3b1a972bc6d53"
watsocam
parents:
diff
changeset
|
35 |
41e8efe8df43
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit c8f72e04db2cc6cc26f0359d5aa3b1a972bc6d53"
watsocam
parents:
diff
changeset
|
36 size_x, size_y = np.array(pixel_sizes, dtype=float) |
41e8efe8df43
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit c8f72e04db2cc6cc26f0359d5aa3b1a972bc6d53"
watsocam
parents:
diff
changeset
|
37 unit_x, unit_y = pixel_size_units |
41e8efe8df43
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit c8f72e04db2cc6cc26f0359d5aa3b1a972bc6d53"
watsocam
parents:
diff
changeset
|
38 |
41e8efe8df43
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit c8f72e04db2cc6cc26f0359d5aa3b1a972bc6d53"
watsocam
parents:
diff
changeset
|
39 assert (unit_x in PHYSICAL_SIZE_UNIT) & (unit_y in PHYSICAL_SIZE_UNIT), ( |
41e8efe8df43
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit c8f72e04db2cc6cc26f0359d5aa3b1a972bc6d53"
watsocam
parents:
diff
changeset
|
40 f'pixel_size_units must be a tuple of the followings: ' |
41e8efe8df43
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit c8f72e04db2cc6cc26f0359d5aa3b1a972bc6d53"
watsocam
parents:
diff
changeset
|
41 f'{", ".join(PHYSICAL_SIZE_UNIT)}' |
41e8efe8df43
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit c8f72e04db2cc6cc26f0359d5aa3b1a972bc6d53"
watsocam
parents:
diff
changeset
|
42 ) |
41e8efe8df43
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit c8f72e04db2cc6cc26f0359d5aa3b1a972bc6d53"
watsocam
parents:
diff
changeset
|
43 |
41e8efe8df43
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit c8f72e04db2cc6cc26f0359d5aa3b1a972bc6d53"
watsocam
parents:
diff
changeset
|
44 n_channels = img_shape[0] |
41e8efe8df43
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit c8f72e04db2cc6cc26f0359d5aa3b1a972bc6d53"
watsocam
parents:
diff
changeset
|
45 if channel_names == None: |
41e8efe8df43
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit c8f72e04db2cc6cc26f0359d5aa3b1a972bc6d53"
watsocam
parents:
diff
changeset
|
46 channel_names = [f'Channel {i}' for i in range(n_channels)] |
41e8efe8df43
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit c8f72e04db2cc6cc26f0359d5aa3b1a972bc6d53"
watsocam
parents:
diff
changeset
|
47 else: |
41e8efe8df43
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit c8f72e04db2cc6cc26f0359d5aa3b1a972bc6d53"
watsocam
parents:
diff
changeset
|
48 if type(channel_names) == str: |
41e8efe8df43
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit c8f72e04db2cc6cc26f0359d5aa3b1a972bc6d53"
watsocam
parents:
diff
changeset
|
49 channel_names = [channel_names] |
41e8efe8df43
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit c8f72e04db2cc6cc26f0359d5aa3b1a972bc6d53"
watsocam
parents:
diff
changeset
|
50 n_channel_names = len(channel_names) |
41e8efe8df43
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit c8f72e04db2cc6cc26f0359d5aa3b1a972bc6d53"
watsocam
parents:
diff
changeset
|
51 assert n_channel_names == n_channels, ( |
41e8efe8df43
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit c8f72e04db2cc6cc26f0359d5aa3b1a972bc6d53"
watsocam
parents:
diff
changeset
|
52 f'number of channel_names ({n_channel_names}) must match ' |
41e8efe8df43
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit c8f72e04db2cc6cc26f0359d5aa3b1a972bc6d53"
watsocam
parents:
diff
changeset
|
53 f'number of channels ({n_channels})' |
41e8efe8df43
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit c8f72e04db2cc6cc26f0359d5aa3b1a972bc6d53"
watsocam
parents:
diff
changeset
|
54 ) |
41e8efe8df43
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit c8f72e04db2cc6cc26f0359d5aa3b1a972bc6d53"
watsocam
parents:
diff
changeset
|
55 |
41e8efe8df43
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit c8f72e04db2cc6cc26f0359d5aa3b1a972bc6d53"
watsocam
parents:
diff
changeset
|
56 if software == None: |
41e8efe8df43
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit c8f72e04db2cc6cc26f0359d5aa3b1a972bc6d53"
watsocam
parents:
diff
changeset
|
57 software = '' |
41e8efe8df43
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit c8f72e04db2cc6cc26f0359d5aa3b1a972bc6d53"
watsocam
parents:
diff
changeset
|
58 |
41e8efe8df43
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit c8f72e04db2cc6cc26f0359d5aa3b1a972bc6d53"
watsocam
parents:
diff
changeset
|
59 metadata = { |
41e8efe8df43
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit c8f72e04db2cc6cc26f0359d5aa3b1a972bc6d53"
watsocam
parents:
diff
changeset
|
60 'Creator': software, |
41e8efe8df43
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit c8f72e04db2cc6cc26f0359d5aa3b1a972bc6d53"
watsocam
parents:
diff
changeset
|
61 'Pixels': { |
41e8efe8df43
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit c8f72e04db2cc6cc26f0359d5aa3b1a972bc6d53"
watsocam
parents:
diff
changeset
|
62 'PhysicalSizeX': size_x, |
41e8efe8df43
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit c8f72e04db2cc6cc26f0359d5aa3b1a972bc6d53"
watsocam
parents:
diff
changeset
|
63 'PhysicalSizeXUnit': unit_x, |
41e8efe8df43
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit c8f72e04db2cc6cc26f0359d5aa3b1a972bc6d53"
watsocam
parents:
diff
changeset
|
64 'PhysicalSizeY': size_y, |
41e8efe8df43
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit c8f72e04db2cc6cc26f0359d5aa3b1a972bc6d53"
watsocam
parents:
diff
changeset
|
65 'PhysicalSizeYUnit': unit_y, |
41e8efe8df43
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit c8f72e04db2cc6cc26f0359d5aa3b1a972bc6d53"
watsocam
parents:
diff
changeset
|
66 }, |
41e8efe8df43
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit c8f72e04db2cc6cc26f0359d5aa3b1a972bc6d53"
watsocam
parents:
diff
changeset
|
67 'Channel': {'Name': channel_names}, |
41e8efe8df43
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit c8f72e04db2cc6cc26f0359d5aa3b1a972bc6d53"
watsocam
parents:
diff
changeset
|
68 |
41e8efe8df43
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit c8f72e04db2cc6cc26f0359d5aa3b1a972bc6d53"
watsocam
parents:
diff
changeset
|
69 } |
41e8efe8df43
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit c8f72e04db2cc6cc26f0359d5aa3b1a972bc6d53"
watsocam
parents:
diff
changeset
|
70 |
41e8efe8df43
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit c8f72e04db2cc6cc26f0359d5aa3b1a972bc6d53"
watsocam
parents:
diff
changeset
|
71 max_size = np.max(img_shape) |
41e8efe8df43
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit c8f72e04db2cc6cc26f0359d5aa3b1a972bc6d53"
watsocam
parents:
diff
changeset
|
72 subifds = np.ceil(np.log2(max_size / 1024)).astype(int) |
41e8efe8df43
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit c8f72e04db2cc6cc26f0359d5aa3b1a972bc6d53"
watsocam
parents:
diff
changeset
|
73 |
41e8efe8df43
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit c8f72e04db2cc6cc26f0359d5aa3b1a972bc6d53"
watsocam
parents:
diff
changeset
|
74 # use optimal tile size for disk space |
41e8efe8df43
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit c8f72e04db2cc6cc26f0359d5aa3b1a972bc6d53"
watsocam
parents:
diff
changeset
|
75 tile_size = 16*np.ceil( |
41e8efe8df43
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit c8f72e04db2cc6cc26f0359d5aa3b1a972bc6d53"
watsocam
parents:
diff
changeset
|
76 np.array(img_shape[1:]) / (2**subifds) / 16 |
41e8efe8df43
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit c8f72e04db2cc6cc26f0359d5aa3b1a972bc6d53"
watsocam
parents:
diff
changeset
|
77 ).astype(int) |
41e8efe8df43
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit c8f72e04db2cc6cc26f0359d5aa3b1a972bc6d53"
watsocam
parents:
diff
changeset
|
78 options = { |
41e8efe8df43
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit c8f72e04db2cc6cc26f0359d5aa3b1a972bc6d53"
watsocam
parents:
diff
changeset
|
79 'tile': tuple(tile_size) |
41e8efe8df43
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit c8f72e04db2cc6cc26f0359d5aa3b1a972bc6d53"
watsocam
parents:
diff
changeset
|
80 } |
41e8efe8df43
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit c8f72e04db2cc6cc26f0359d5aa3b1a972bc6d53"
watsocam
parents:
diff
changeset
|
81 |
41e8efe8df43
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit c8f72e04db2cc6cc26f0359d5aa3b1a972bc6d53"
watsocam
parents:
diff
changeset
|
82 with tifffile.TiffWriter(output_path, bigtiff=True) as tiff_out: |
41e8efe8df43
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit c8f72e04db2cc6cc26f0359d5aa3b1a972bc6d53"
watsocam
parents:
diff
changeset
|
83 tiff_out.write( |
41e8efe8df43
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit c8f72e04db2cc6cc26f0359d5aa3b1a972bc6d53"
watsocam
parents:
diff
changeset
|
84 data=out_img, |
41e8efe8df43
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit c8f72e04db2cc6cc26f0359d5aa3b1a972bc6d53"
watsocam
parents:
diff
changeset
|
85 metadata=metadata, |
41e8efe8df43
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit c8f72e04db2cc6cc26f0359d5aa3b1a972bc6d53"
watsocam
parents:
diff
changeset
|
86 software=software, |
41e8efe8df43
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit c8f72e04db2cc6cc26f0359d5aa3b1a972bc6d53"
watsocam
parents:
diff
changeset
|
87 subifds=subifds, |
41e8efe8df43
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit c8f72e04db2cc6cc26f0359d5aa3b1a972bc6d53"
watsocam
parents:
diff
changeset
|
88 **options |
41e8efe8df43
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit c8f72e04db2cc6cc26f0359d5aa3b1a972bc6d53"
watsocam
parents:
diff
changeset
|
89 ) |
41e8efe8df43
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit c8f72e04db2cc6cc26f0359d5aa3b1a972bc6d53"
watsocam
parents:
diff
changeset
|
90 for i in range(subifds): |
41e8efe8df43
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit c8f72e04db2cc6cc26f0359d5aa3b1a972bc6d53"
watsocam
parents:
diff
changeset
|
91 if i == 0: |
41e8efe8df43
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit c8f72e04db2cc6cc26f0359d5aa3b1a972bc6d53"
watsocam
parents:
diff
changeset
|
92 down_2x_img = downsize_img_channels(out_img, is_mask=is_mask) |
41e8efe8df43
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit c8f72e04db2cc6cc26f0359d5aa3b1a972bc6d53"
watsocam
parents:
diff
changeset
|
93 else: |
41e8efe8df43
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit c8f72e04db2cc6cc26f0359d5aa3b1a972bc6d53"
watsocam
parents:
diff
changeset
|
94 down_2x_img = downsize_img_channels(down_2x_img, is_mask=is_mask) |
41e8efe8df43
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit c8f72e04db2cc6cc26f0359d5aa3b1a972bc6d53"
watsocam
parents:
diff
changeset
|
95 tiff_out.write( |
41e8efe8df43
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit c8f72e04db2cc6cc26f0359d5aa3b1a972bc6d53"
watsocam
parents:
diff
changeset
|
96 data=down_2x_img, |
41e8efe8df43
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit c8f72e04db2cc6cc26f0359d5aa3b1a972bc6d53"
watsocam
parents:
diff
changeset
|
97 subfiletype=1, |
41e8efe8df43
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit c8f72e04db2cc6cc26f0359d5aa3b1a972bc6d53"
watsocam
parents:
diff
changeset
|
98 **options |
41e8efe8df43
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit c8f72e04db2cc6cc26f0359d5aa3b1a972bc6d53"
watsocam
parents:
diff
changeset
|
99 ) |
41e8efe8df43
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit c8f72e04db2cc6cc26f0359d5aa3b1a972bc6d53"
watsocam
parents:
diff
changeset
|
100 |
41e8efe8df43
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit c8f72e04db2cc6cc26f0359d5aa3b1a972bc6d53"
watsocam
parents:
diff
changeset
|
101 out_img = out_img.reshape(img_shape_ori) |
41e8efe8df43
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit c8f72e04db2cc6cc26f0359d5aa3b1a972bc6d53"
watsocam
parents:
diff
changeset
|
102 return |
41e8efe8df43
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit c8f72e04db2cc6cc26f0359d5aa3b1a972bc6d53"
watsocam
parents:
diff
changeset
|
103 |
41e8efe8df43
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit c8f72e04db2cc6cc26f0359d5aa3b1a972bc6d53"
watsocam
parents:
diff
changeset
|
104 def downsize_channel(img, is_mask): |
41e8efe8df43
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit c8f72e04db2cc6cc26f0359d5aa3b1a972bc6d53"
watsocam
parents:
diff
changeset
|
105 if is_mask: |
41e8efe8df43
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit c8f72e04db2cc6cc26f0359d5aa3b1a972bc6d53"
watsocam
parents:
diff
changeset
|
106 return img[::2, ::2] |
41e8efe8df43
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit c8f72e04db2cc6cc26f0359d5aa3b1a972bc6d53"
watsocam
parents:
diff
changeset
|
107 else: |
41e8efe8df43
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit c8f72e04db2cc6cc26f0359d5aa3b1a972bc6d53"
watsocam
parents:
diff
changeset
|
108 return skimage.transform.downscale_local_mean(img, (2, 2)).astype(img.dtype) |
41e8efe8df43
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit c8f72e04db2cc6cc26f0359d5aa3b1a972bc6d53"
watsocam
parents:
diff
changeset
|
109 |
41e8efe8df43
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit c8f72e04db2cc6cc26f0359d5aa3b1a972bc6d53"
watsocam
parents:
diff
changeset
|
110 def downsize_img_channels(img, is_mask): |
41e8efe8df43
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit c8f72e04db2cc6cc26f0359d5aa3b1a972bc6d53"
watsocam
parents:
diff
changeset
|
111 return np.array([ |
41e8efe8df43
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit c8f72e04db2cc6cc26f0359d5aa3b1a972bc6d53"
watsocam
parents:
diff
changeset
|
112 downsize_channel(c, is_mask=is_mask) |
41e8efe8df43
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit c8f72e04db2cc6cc26f0359d5aa3b1a972bc6d53"
watsocam
parents:
diff
changeset
|
113 for c in img |
41e8efe8df43
"planemo upload for repository https://github.com/ohsu-comp-bio/S3segmenter commit c8f72e04db2cc6cc26f0359d5aa3b1a972bc6d53"
watsocam
parents:
diff
changeset
|
114 ]) |