driftlessmap 1.1.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- driftlessmap/__init__.py +16 -0
- driftlessmap/__main__.py +5 -0
- driftlessmap/about.py +24 -0
- driftlessmap/allen_downloader.py +908 -0
- driftlessmap/app.py +8085 -0
- driftlessmap/atlas_downloader.py +370 -0
- driftlessmap/atlas_loader.py +526 -0
- driftlessmap/atlas_processor.py +784 -0
- driftlessmap/atlas_transform.py +111 -0
- driftlessmap/atlas_view.py +1435 -0
- driftlessmap/cell_detection.py +27 -0
- driftlessmap/coordinate_validation.py +19 -0
- driftlessmap/czi_reader.py +236 -0
- driftlessmap/data/WHS_atlas_labels.pkl +0 -0
- driftlessmap/data/allen_mice_atlas_labels.pkl +0 -0
- driftlessmap/data/atlas_labels.pkl +0 -0
- driftlessmap/data/query.csv +1328 -0
- driftlessmap/download_utils.py +85 -0
- driftlessmap/herbs.png +0 -0
- driftlessmap/icons/backward.svg +15 -0
- driftlessmap/icons/dot.svg +11 -0
- driftlessmap/icons/down-arrow.svg +10 -0
- driftlessmap/icons/fast_backward.svg +14 -0
- driftlessmap/icons/fast_forward.svg +14 -0
- driftlessmap/icons/forward.svg +14 -0
- driftlessmap/icons/layers/add.png +0 -0
- driftlessmap/icons/layers/ai.png +0 -0
- driftlessmap/icons/layers/eye_off.png +0 -0
- driftlessmap/icons/layers/eye_on.png +0 -0
- driftlessmap/icons/layers/eye_white.png +0 -0
- driftlessmap/icons/layers/hi.png +0 -0
- driftlessmap/icons/layers/trash.png +0 -0
- driftlessmap/icons/object.svg +22 -0
- driftlessmap/icons/sidebar/add.png +0 -0
- driftlessmap/icons/sidebar/atlascontrol.png +0 -0
- driftlessmap/icons/sidebar/atlascontrol.svg +32 -0
- driftlessmap/icons/sidebar/bnd.svg +14 -0
- driftlessmap/icons/sidebar/c_section.png +0 -0
- driftlessmap/icons/sidebar/c_section2.png +0 -0
- driftlessmap/icons/sidebar/cell.svg +24 -0
- driftlessmap/icons/sidebar/check.svg +9 -0
- driftlessmap/icons/sidebar/compare.svg +18 -0
- driftlessmap/icons/sidebar/contour.svg +14 -0
- driftlessmap/icons/sidebar/h_section.png +0 -0
- driftlessmap/icons/sidebar/info.svg +14 -0
- driftlessmap/icons/sidebar/layers.png +0 -0
- driftlessmap/icons/sidebar/layers.svg +23 -0
- driftlessmap/icons/sidebar/line.svg +10 -0
- driftlessmap/icons/sidebar/link.svg +18 -0
- driftlessmap/icons/sidebar/link_off.svg +18 -0
- driftlessmap/icons/sidebar/merge.svg +11 -0
- driftlessmap/icons/sidebar/object.svg +13 -0
- driftlessmap/icons/sidebar/probe.png +0 -0
- driftlessmap/icons/sidebar/probe.svg +23 -0
- driftlessmap/icons/sidebar/rotation_horizontal.svg +14 -0
- driftlessmap/icons/sidebar/rotation_vertical.svg +14 -0
- driftlessmap/icons/sidebar/s_section.png +0 -0
- driftlessmap/icons/sidebar/tool.png +0 -0
- driftlessmap/icons/sidebar/tool.svg +19 -0
- driftlessmap/icons/sidebar/trash.png +0 -0
- driftlessmap/icons/sidebar/tree_checked.svg +10 -0
- driftlessmap/icons/sidebar/treeview.png +0 -0
- driftlessmap/icons/sidebar/treeview.svg +10 -0
- driftlessmap/icons/sidebar/treeview2.png +0 -0
- driftlessmap/icons/sidebar/virus.svg +24 -0
- driftlessmap/icons/tdown.svg +16 -0
- driftlessmap/icons/toolbar/accept.svg +18 -0
- driftlessmap/icons/toolbar/accept2.svg +24 -0
- driftlessmap/icons/toolbar/aim.svg +44 -0
- driftlessmap/icons/toolbar/aim_not.svg +28 -0
- driftlessmap/icons/toolbar/anchor.svg +14 -0
- driftlessmap/icons/toolbar/anticlockwise_rotation.svg +12 -0
- driftlessmap/icons/toolbar/atlas_icon.png +0 -0
- driftlessmap/icons/toolbar/boundary_register.svg +18 -0
- driftlessmap/icons/toolbar/cancel.svg +32 -0
- driftlessmap/icons/toolbar/cell_select.svg +22 -0
- driftlessmap/icons/toolbar/cell_select_not.svg +12 -0
- driftlessmap/icons/toolbar/check.svg +9 -0
- driftlessmap/icons/toolbar/clockwise_rotation.svg +11 -0
- driftlessmap/icons/toolbar/closed_path.svg +16 -0
- driftlessmap/icons/toolbar/closed_path2 copy.svg +19 -0
- driftlessmap/icons/toolbar/closed_path2.svg +20 -0
- driftlessmap/icons/toolbar/eraser.png +0 -0
- driftlessmap/icons/toolbar/eraser.svg +19 -0
- driftlessmap/icons/toolbar/eye.svg +17 -0
- driftlessmap/icons/toolbar/eye_closed.svg +19 -0
- driftlessmap/icons/toolbar/fill.svg +12 -0
- driftlessmap/icons/toolbar/gps.svg +15 -0
- driftlessmap/icons/toolbar/h_flip.png +0 -0
- driftlessmap/icons/toolbar/handle.png +0 -0
- driftlessmap/icons/toolbar/image_icon.png +0 -0
- driftlessmap/icons/toolbar/image_icon.svg +25 -0
- driftlessmap/icons/toolbar/info.svg +14 -0
- driftlessmap/icons/toolbar/inpart.png +0 -0
- driftlessmap/icons/toolbar/inpart.svg +17 -0
- driftlessmap/icons/toolbar/lasso.png +0 -0
- driftlessmap/icons/toolbar/lasso.svg +14 -0
- driftlessmap/icons/toolbar/left90.png +0 -0
- driftlessmap/icons/toolbar/line.svg +10 -0
- driftlessmap/icons/toolbar/line_sites.svg +11 -0
- driftlessmap/icons/toolbar/linear_silicon.png +0 -0
- driftlessmap/icons/toolbar/linear_silicon.svg +88 -0
- driftlessmap/icons/toolbar/list.svg +14 -0
- driftlessmap/icons/toolbar/location.svg +14 -0
- driftlessmap/icons/toolbar/magic-wand.svg +16 -0
- driftlessmap/icons/toolbar/magic_white.png +0 -0
- driftlessmap/icons/toolbar/mask.svg +10 -0
- driftlessmap/icons/toolbar/match.svg +20 -0
- driftlessmap/icons/toolbar/matchbnd.svg +18 -0
- driftlessmap/icons/toolbar/matching.svg +36 -0
- driftlessmap/icons/toolbar/merge.svg +11 -0
- driftlessmap/icons/toolbar/move_down.png +0 -0
- driftlessmap/icons/toolbar/move_left.png +0 -0
- driftlessmap/icons/toolbar/move_right.png +0 -0
- driftlessmap/icons/toolbar/move_up.png +0 -0
- driftlessmap/icons/toolbar/moving.png +0 -0
- driftlessmap/icons/toolbar/multi-probe.svg +119 -0
- driftlessmap/icons/toolbar/multi_pencil.svg +23 -0
- driftlessmap/icons/toolbar/multi_probe.png +0 -0
- driftlessmap/icons/toolbar/object.svg +13 -0
- driftlessmap/icons/toolbar/open_path.svg +22 -0
- driftlessmap/icons/toolbar/outpart.png +0 -0
- driftlessmap/icons/toolbar/outpart.svg +26 -0
- driftlessmap/icons/toolbar/pencil.png +0 -0
- driftlessmap/icons/toolbar/pencil.svg +19 -0
- driftlessmap/icons/toolbar/plasso.png +0 -0
- driftlessmap/icons/toolbar/probe.svg +19 -0
- driftlessmap/icons/toolbar/radar.svg +32 -0
- driftlessmap/icons/toolbar/rotation.svg +45 -0
- driftlessmap/icons/toolbar/rotation_clockwise.svg +18 -0
- driftlessmap/icons/toolbar/rotation_counter_clockwise.svg +18 -0
- driftlessmap/icons/toolbar/ruler.svg +27 -0
- driftlessmap/icons/toolbar/separate_sites.svg +13 -0
- driftlessmap/icons/toolbar/single_pencil.svg +16 -0
- driftlessmap/icons/toolbar/toa.svg +11 -0
- driftlessmap/icons/toolbar/toa_delete.svg +36 -0
- driftlessmap/icons/toolbar/toaa.svg +11 -0
- driftlessmap/icons/toolbar/toh.svg +11 -0
- driftlessmap/icons/toolbar/toh_delete.svg +36 -0
- driftlessmap/icons/toolbar/tohh.svg +11 -0
- driftlessmap/icons/toolbar/trans.png +0 -0
- driftlessmap/icons/toolbar/trans.svg +16 -0
- driftlessmap/icons/toolbar/triangulation.svg +10 -0
- driftlessmap/icons/toolbar/two_window.png +0 -0
- driftlessmap/icons/toolbar/unmerge.svg +16 -0
- driftlessmap/icons/toolbar/v_flip.png +0 -0
- driftlessmap/icons/toolbar/virus.svg +24 -0
- driftlessmap/icons/toolbar/virus_register.svg +31 -0
- driftlessmap/icons/toolbar/vis2d.svg +29 -0
- driftlessmap/icons/toolbar/window2.png +0 -0
- driftlessmap/icons/toolbar/window3.png +0 -0
- driftlessmap/icons/toolbar/window4.png +0 -0
- driftlessmap/icons/tree_close.svg +14 -0
- driftlessmap/icons/tree_open.svg +14 -0
- driftlessmap/icons/up-arrow.svg +10 -0
- driftlessmap/image_curves.py +579 -0
- driftlessmap/image_reader.py +186 -0
- driftlessmap/image_stacks.py +359 -0
- driftlessmap/image_view.py +646 -0
- driftlessmap/images_reader.py +5 -0
- driftlessmap/label_tree.py +278 -0
- driftlessmap/layer_validation.py +25 -0
- driftlessmap/layers_control.py +554 -0
- driftlessmap/main_window.ui +883 -0
- driftlessmap/movable_points.py +254 -0
- driftlessmap/obj_items.py +122 -0
- driftlessmap/object_control.py +1762 -0
- driftlessmap/persistence.py +376 -0
- driftlessmap/popup_message.py +16 -0
- driftlessmap/probe_csv.py +319 -0
- driftlessmap/probe_reconstruction.py +409 -0
- driftlessmap/probe_utiles.py +1442 -0
- driftlessmap/qss/atlas_view_group_box.qss +15 -0
- driftlessmap/qss/box_label.qss +7 -0
- driftlessmap/qss/channel_selector.qss +19 -0
- driftlessmap/qss/color_combo.qss +121 -0
- driftlessmap/qss/decor_label.qss +9 -0
- driftlessmap/qss/dialogs.qss +11 -0
- driftlessmap/qss/hidden_line_edit.qss +5 -0
- driftlessmap/qss/label_tree.qss +123 -0
- driftlessmap/qss/main_window.qss +243 -0
- driftlessmap/qss/menu_bar.qss +42 -0
- driftlessmap/qss/multi_handle_slider.qss +14 -0
- driftlessmap/qss/obj_ctrl_bottom_button.qss +29 -0
- driftlessmap/qss/object_text_button.qss +19 -0
- driftlessmap/qss/page_control.qss +36 -0
- driftlessmap/qss/rotation_button.qss +9 -0
- driftlessmap/qss/side_bar.qss +23 -0
- driftlessmap/qss/spinbox.qss +106 -0
- driftlessmap/qss/tabs.qss +211 -0
- driftlessmap/qss/tool_bar.qss +77 -0
- driftlessmap/resources.py +34 -0
- driftlessmap/roi_analysis.py +375 -0
- driftlessmap/run_driftlessmap.py +4 -0
- driftlessmap/slice_stacks.py +268 -0
- driftlessmap/slice_validation.py +20 -0
- driftlessmap/toolbox.py +569 -0
- driftlessmap/triangulation.py +517 -0
- driftlessmap/triangulation_points.py +108 -0
- driftlessmap/user_settings.py +92 -0
- driftlessmap/uuuuuu.py +1168 -0
- driftlessmap/version.py +3 -0
- driftlessmap/widgets_utils.py +140 -0
- driftlessmap/wtiles.py +715 -0
- driftlessmap-1.1.0.dist-info/METADATA +186 -0
- driftlessmap-1.1.0.dist-info/RECORD +210 -0
- driftlessmap-1.1.0.dist-info/WHEEL +5 -0
- driftlessmap-1.1.0.dist-info/entry_points.txt +2 -0
- driftlessmap-1.1.0.dist-info/licenses/LICENSE.txt +23 -0
- driftlessmap-1.1.0.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"""Pure image preparation helpers for cell detection."""
|
|
2
|
+
|
|
3
|
+
import cv2
|
|
4
|
+
import numpy as np
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
def select_detection_channel(image, is_rgb, channel_visible):
|
|
8
|
+
"""Return an 8-bit detection plane and its DriftlessMap cell-layer index."""
|
|
9
|
+
image = np.asarray(image)
|
|
10
|
+
if image.ndim != 3:
|
|
11
|
+
raise ValueError("Cell detection requires a channel-last image.")
|
|
12
|
+
if is_rgb:
|
|
13
|
+
if image.shape[2] < 3:
|
|
14
|
+
raise ValueError("RGB cell detection requires three color channels.")
|
|
15
|
+
plane = cv2.cvtColor(image[..., :3], cv2.COLOR_RGB2GRAY)
|
|
16
|
+
layer_index = 0
|
|
17
|
+
else:
|
|
18
|
+
visible = np.flatnonzero(np.asarray(channel_visible)[: image.shape[2]])
|
|
19
|
+
if len(visible) != 1:
|
|
20
|
+
raise ValueError("Select exactly one image channel for cell detection.")
|
|
21
|
+
channel_index = int(visible[0])
|
|
22
|
+
plane = image[..., channel_index]
|
|
23
|
+
layer_index = channel_index + 1
|
|
24
|
+
|
|
25
|
+
if plane.dtype != np.uint8:
|
|
26
|
+
plane = cv2.normalize(plane, None, 0, 255, cv2.NORM_MINMAX).astype(np.uint8)
|
|
27
|
+
return plane, layer_index
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"""Validation helpers for voxel and image coordinates."""
|
|
2
|
+
|
|
3
|
+
import numpy as np
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
def coordinates_in_bounds(coordinates, shape):
|
|
7
|
+
"""Return whether every coordinate lies inside an array of ``shape``."""
|
|
8
|
+
coordinates = np.asarray(coordinates)
|
|
9
|
+
shape = np.asarray(shape)
|
|
10
|
+
if shape.ndim != 1 or coordinates.ndim == 0:
|
|
11
|
+
return False
|
|
12
|
+
if coordinates.shape[-1] != len(shape):
|
|
13
|
+
return False
|
|
14
|
+
return bool(np.all(coordinates >= 0) and np.all(coordinates < shape))
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
def coordinate_groups_in_bounds(coordinate_groups, shape):
|
|
18
|
+
"""Validate a sequence of coordinate arrays against one array shape."""
|
|
19
|
+
return all(coordinates_in_bounds(group, shape) for group in coordinate_groups)
|
|
@@ -0,0 +1,236 @@
|
|
|
1
|
+
import cv2
|
|
2
|
+
from aicspylibczi import CziFile
|
|
3
|
+
from pathlib import Path
|
|
4
|
+
from os.path import dirname, realpath, join
|
|
5
|
+
import pickle
|
|
6
|
+
import numpy as np
|
|
7
|
+
import colorsys
|
|
8
|
+
from .uuuuuu import hex2rgb
|
|
9
|
+
from .image_reader import MAX_CHANNELS
|
|
10
|
+
|
|
11
|
+
# czi_path = '~/Work/Kavli/Data/HERBS_DATA/abraham/Pecorino_mec_slide_1.czi'
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
class CZIReader(object):
|
|
15
|
+
def __init__(self, czi_path):
|
|
16
|
+
self.error_index = 0
|
|
17
|
+
self.is_czi = True
|
|
18
|
+
self.status = None
|
|
19
|
+
self.file_name_list = [czi_path[:-4]]
|
|
20
|
+
self.czi = CziFile(czi_path)
|
|
21
|
+
self.czi_info = self.czi.dims
|
|
22
|
+
self.dimensions = self.czi.get_dims_shape()
|
|
23
|
+
self.is_mosaic = self.czi.is_mosaic()
|
|
24
|
+
self.pixel_type = self.czi.pixel_type
|
|
25
|
+
self.n_pages = 1
|
|
26
|
+
self.data = {}
|
|
27
|
+
self.scale = {}
|
|
28
|
+
|
|
29
|
+
if "T" in self.czi_info:
|
|
30
|
+
if self.dimensions[0]["T"][1] != 1:
|
|
31
|
+
self.status = "multi-T"
|
|
32
|
+
|
|
33
|
+
if "A" in self.czi_info:
|
|
34
|
+
self.is_rgb = True
|
|
35
|
+
self.n_channels = 3
|
|
36
|
+
if self.pixel_type == "bgr24":
|
|
37
|
+
self.pixel_type = "rgb24"
|
|
38
|
+
self.level = 255
|
|
39
|
+
self.data_type = "uint8"
|
|
40
|
+
else:
|
|
41
|
+
da_power = int(self.pixel_type[-2:]) / 3
|
|
42
|
+
self.pixel_type = "rgb" + self.pixel_type[-2:]
|
|
43
|
+
self.level = int(np.power(2, da_power)) - 1
|
|
44
|
+
self.data_type = "uint" + str(int(da_power))
|
|
45
|
+
else:
|
|
46
|
+
self.is_rgb = False
|
|
47
|
+
if self.pixel_type == "gray16":
|
|
48
|
+
self.level = 65535
|
|
49
|
+
self.data_type = "uint16"
|
|
50
|
+
elif self.pixel_type == "gray8":
|
|
51
|
+
self.level = 255
|
|
52
|
+
self.data_type = "uint8"
|
|
53
|
+
else:
|
|
54
|
+
self.error_index = 2
|
|
55
|
+
return
|
|
56
|
+
self.n_channels = self.dimensions[0]["C"][1]
|
|
57
|
+
if self.n_channels > MAX_CHANNELS:
|
|
58
|
+
self.error_index = 8
|
|
59
|
+
return
|
|
60
|
+
|
|
61
|
+
self.n_scenes = len(self.dimensions)
|
|
62
|
+
self.has_fixed_box = False
|
|
63
|
+
if self.n_scenes == 1:
|
|
64
|
+
if self.dimensions[0]["S"][1] != 1:
|
|
65
|
+
self.n_scenes = self.dimensions[0]["S"][1]
|
|
66
|
+
self.has_fixed_box = True
|
|
67
|
+
self.scene_bbox = []
|
|
68
|
+
if self.is_mosaic:
|
|
69
|
+
for i in range(self.n_scenes):
|
|
70
|
+
bbox = self.czi.get_mosaic_scene_bounding_box(index=i)
|
|
71
|
+
self.scene_bbox.append((bbox.x, bbox.y, bbox.w, bbox.h))
|
|
72
|
+
else:
|
|
73
|
+
for i in range(self.n_scenes):
|
|
74
|
+
bbox = self.czi.get_scene_bounding_box(index=i)
|
|
75
|
+
self.scene_bbox.append((bbox.x, bbox.y, bbox.w, bbox.h))
|
|
76
|
+
|
|
77
|
+
# get colors from metadata
|
|
78
|
+
metadata = self.czi.meta[0]
|
|
79
|
+
all_tags = [metadata[i].tag for i in range(len(metadata))]
|
|
80
|
+
ds_ind = [
|
|
81
|
+
ind for ind in range(len(all_tags)) if all_tags[ind] == "DisplaySetting"
|
|
82
|
+
][0]
|
|
83
|
+
ds_tags = [metadata[ds_ind][i].tag for i in range(len(metadata[ds_ind]))]
|
|
84
|
+
ch_ind = [ind for ind in range(len(ds_tags)) if ds_tags[ind] == "Channels"][0]
|
|
85
|
+
ch_tags = [
|
|
86
|
+
metadata[ds_ind][ch_ind][i].tag
|
|
87
|
+
for i in range(len(metadata[ds_ind][ch_ind]))
|
|
88
|
+
]
|
|
89
|
+
|
|
90
|
+
scale_ind = [ind for ind in range(len(all_tags)) if all_tags[ind] == "Scaling"][
|
|
91
|
+
0
|
|
92
|
+
]
|
|
93
|
+
scale_tags = [
|
|
94
|
+
metadata[scale_ind][i].tag for i in range(len(metadata[scale_ind]))
|
|
95
|
+
]
|
|
96
|
+
scale_item_ind = [
|
|
97
|
+
ind for ind in range(len(scale_tags)) if scale_tags[ind] == "Items"
|
|
98
|
+
][0]
|
|
99
|
+
scale_item_tags = [
|
|
100
|
+
metadata[scale_ind][scale_item_ind][i].tag
|
|
101
|
+
for i in range(len(metadata[scale_ind][scale_item_ind]))
|
|
102
|
+
]
|
|
103
|
+
|
|
104
|
+
scaling_vals = []
|
|
105
|
+
for i in range(len(scale_item_tags)):
|
|
106
|
+
scale_info = metadata[scale_ind][scale_item_ind]
|
|
107
|
+
single_scaling_tags = [
|
|
108
|
+
scale_info[i][ind].tag for ind in range(len(scale_info[i]))
|
|
109
|
+
]
|
|
110
|
+
for j in range(len(single_scaling_tags)):
|
|
111
|
+
scaling_vals.append(metadata[scale_ind][scale_item_ind][i][j].text)
|
|
112
|
+
|
|
113
|
+
self.scaling_val = float(scaling_vals[0]) * 1e6
|
|
114
|
+
|
|
115
|
+
self.rgb_colors = []
|
|
116
|
+
self.hsv_colors = []
|
|
117
|
+
self.channel_name = []
|
|
118
|
+
self.gamma_val = []
|
|
119
|
+
|
|
120
|
+
if self.is_rgb:
|
|
121
|
+
self.rgb_colors = [(255, 0, 0), (0, 255, 0), (0, 0, 255)]
|
|
122
|
+
self.channel_name = ["Red", "Green", "Blue"]
|
|
123
|
+
for i in range(3):
|
|
124
|
+
chsv = colorsys.rgb_to_hsv(
|
|
125
|
+
self.rgb_colors[i][0], self.rgb_colors[i][1], self.rgb_colors[i][2]
|
|
126
|
+
)
|
|
127
|
+
hsv_color = (chsv[0], chsv[1], chsv[2] / 255)
|
|
128
|
+
self.hsv_colors.append(hsv_color)
|
|
129
|
+
for i in range(len(ch_tags)):
|
|
130
|
+
chn_info = metadata[ds_ind][ch_ind]
|
|
131
|
+
single_channel_tags = [
|
|
132
|
+
chn_info[i][ind].tag for ind in range(len(chn_info[i]))
|
|
133
|
+
]
|
|
134
|
+
channel_vals = []
|
|
135
|
+
for j in range(len(single_channel_tags)):
|
|
136
|
+
channel_vals.append(metadata[ds_ind][ch_ind][i][j].text)
|
|
137
|
+
if len(np.where(np.ravel(single_channel_tags) == "Gamma")[0]) > 0:
|
|
138
|
+
self.gamma_val.append(
|
|
139
|
+
channel_vals[
|
|
140
|
+
np.where(np.ravel(single_channel_tags) == "Gamma")[0][0]
|
|
141
|
+
]
|
|
142
|
+
)
|
|
143
|
+
else:
|
|
144
|
+
for i in range(len(ch_tags)):
|
|
145
|
+
chn_info = metadata[ds_ind][ch_ind]
|
|
146
|
+
single_channel_tags = [
|
|
147
|
+
chn_info[i][ind].tag for ind in range(len(chn_info[i]))
|
|
148
|
+
]
|
|
149
|
+
channel_vals = []
|
|
150
|
+
for j in range(len(single_channel_tags)):
|
|
151
|
+
channel_vals.append(metadata[ds_ind][ch_ind][i][j].text)
|
|
152
|
+
hex_color = channel_vals[
|
|
153
|
+
np.where(np.ravel(single_channel_tags) == "Color")[0][0]
|
|
154
|
+
]
|
|
155
|
+
self.channel_name.append(
|
|
156
|
+
channel_vals[
|
|
157
|
+
np.where(np.ravel(single_channel_tags) == "ShortName")[0][0]
|
|
158
|
+
]
|
|
159
|
+
)
|
|
160
|
+
if len(np.where(np.ravel(single_channel_tags) == "Gamma")[0]) > 0:
|
|
161
|
+
self.gamma_val.append(
|
|
162
|
+
channel_vals[
|
|
163
|
+
np.where(np.ravel(single_channel_tags) == "Gamma")[0][0]
|
|
164
|
+
]
|
|
165
|
+
)
|
|
166
|
+
da_color = hex_color[0] + hex_color[3:]
|
|
167
|
+
r, g, b = hex2rgb(da_color)
|
|
168
|
+
chsv = colorsys.rgb_to_hsv(r, g, b)
|
|
169
|
+
hsv_color = (chsv[0], chsv[1], chsv[2] / 255)
|
|
170
|
+
self.hsv_colors.append(hsv_color)
|
|
171
|
+
self.rgb_colors.append((r, g, b))
|
|
172
|
+
|
|
173
|
+
def read_data(self, scale, scene_index=None):
|
|
174
|
+
if scene_index is None:
|
|
175
|
+
scene_index = np.arange(self.n_scenes)
|
|
176
|
+
else:
|
|
177
|
+
scene_index = [scene_index]
|
|
178
|
+
|
|
179
|
+
for scind in scene_index:
|
|
180
|
+
if self.is_rgb:
|
|
181
|
+
if self.is_mosaic:
|
|
182
|
+
image_data = self.czi.read_mosaic(
|
|
183
|
+
C=0, scale_factor=scale, region=self.scene_bbox[scind]
|
|
184
|
+
)
|
|
185
|
+
if len(image_data.shape) == 4:
|
|
186
|
+
image_data = image_data[0]
|
|
187
|
+
else:
|
|
188
|
+
image_data_full = self.czi.read_image(
|
|
189
|
+
region=self.scene_bbox[scind], S=scind
|
|
190
|
+
)
|
|
191
|
+
image_data = image_data_full[0]
|
|
192
|
+
image_info = image_data_full[1]
|
|
193
|
+
if image_info[0][0] == "C":
|
|
194
|
+
image_data = image_data[0]
|
|
195
|
+
img = image_data.copy()
|
|
196
|
+
if self.pixel_type == "rgb24":
|
|
197
|
+
img_data_temp = img.astype(np.uint8)
|
|
198
|
+
else:
|
|
199
|
+
img_data_temp = img.astype(np.uint16)
|
|
200
|
+
img_data_temp = cv2.cvtColor(img_data_temp, cv2.COLOR_BGR2RGB)
|
|
201
|
+
self.data["scene %d" % scind] = img_data_temp
|
|
202
|
+
self.scale["scene %d" % scind] = scale
|
|
203
|
+
else:
|
|
204
|
+
if self.n_channels != 1:
|
|
205
|
+
temp = []
|
|
206
|
+
for j in range(self.n_channels):
|
|
207
|
+
img = self._read_grayscale_plane(j, scale, scind)
|
|
208
|
+
temp.append(img)
|
|
209
|
+
img_data_temp = np.dstack(temp)
|
|
210
|
+
self.data["scene %d" % scind] = img_data_temp
|
|
211
|
+
self.scale["scene %d" % scind] = scale
|
|
212
|
+
else:
|
|
213
|
+
img = self._read_grayscale_plane(0, scale, scind)
|
|
214
|
+
img_data_temp = img
|
|
215
|
+
self.data["scene %d" % scind] = img_data_temp.reshape(
|
|
216
|
+
img.shape[0], img.shape[1], 1
|
|
217
|
+
)
|
|
218
|
+
self.scale["scene %d" % scind] = scale
|
|
219
|
+
|
|
220
|
+
def _read_grayscale_plane(self, channel, scale, scene_index):
|
|
221
|
+
if self.is_mosaic:
|
|
222
|
+
data = self.czi.read_mosaic(
|
|
223
|
+
C=channel,
|
|
224
|
+
scale_factor=scale,
|
|
225
|
+
region=self.scene_bbox[scene_index],
|
|
226
|
+
)
|
|
227
|
+
else:
|
|
228
|
+
data = self.czi.read_image(
|
|
229
|
+
C=channel,
|
|
230
|
+
S=scene_index,
|
|
231
|
+
region=self.scene_bbox[scene_index],
|
|
232
|
+
)[0]
|
|
233
|
+
image = np.squeeze(np.asarray(data))
|
|
234
|
+
if image.ndim != 2:
|
|
235
|
+
raise ValueError("CZI channel did not decode to a two-dimensional image.")
|
|
236
|
+
return image.copy()
|
|
Binary file
|
|
Binary file
|
|
Binary file
|