Skip to content

Commit da74a64

Browse files
committed
working now
1 parent 77dcf9e commit da74a64

1 file changed

Lines changed: 16 additions & 54 deletions

File tree

spimquant/workflow/scripts/qc_segmentation_roi_zoom.py

Lines changed: 16 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66
quality within individual brain regions, complementing the whole-brain
77
overview in ``qc_segmentation_overview``.
88
9-
Voxel dimensions from the OME-Zarr image are used to preserve the correct
10-
physical aspect ratio in each panel.
119
1210
This is a Snakemake script that expects the ``snakemake`` object to be
1311
available, which is automatically provided when executed as part of a
@@ -82,26 +80,13 @@ def main():
8280

8381
dseg_data = atlas.dseg.data.compute()
8482

85-
#spim_data = spim_nib.get_fdata()
86-
#ff_data = nib.load(snakemake.input.fieldfrac).get_fdata()
87-
#dseg_data = nib.load(snakemake.input.dseg).get_fdata().astype(int)
8883

89-
# Voxel dimensions (mm) for physical aspect-ratio correction
90-
#zooms = spim_nib.header.get_zooms()
91-
#dx, dy = float(zooms[0]), float(zooms[1])
92-
## Axial (Z) slice: after rot90, rows=y, cols=x → aspect = dy/dx
93-
#aspect_axial = dy / dx
84+
# Voxel dimensions (mm) for physical aspect-ratio correction - not implemented yet
85+
# but should be easy with ZarrNii image .scale
86+
aspect_axial = 1
9487

9588

96-
97-
# Bring all volumes to the SPIM grid
98-
#ff_data = _match_shape(ff_data, spim_data.shape, order=1)
99-
#dseg_data = _match_shape(dseg_data, spim_data.shape, order=0).astype(int)
100-
101-
# Global normalisations
102-
#spim_norm = _percentile_norm(spim_data)
103-
# Field fraction values are 0–100; normalise to 0–1 for display
104-
#ff_norm = np.clip(ff_data / 100.0, 0.0, 1.0)
89+
# Global normalisations - not implemented yet
10590

10691
# Load atlas label table
10792
label_df = atlas.labels_df
@@ -117,7 +102,7 @@ def main():
117102
n_rois = len(roi_rows)
118103

119104
if n_rois == 0:
120-
fig, ax = plt.subplots(figsize=(6, 4))
105+
fig, ax = plt.subplots(figsize=(18, 12))
121106
ax.text(
122107
0.5,
123108
0.5,
@@ -163,40 +148,17 @@ def main():
163148

164149
#get cropped images for this label
165150
bbox_min, bbox_max = atlas.get_region_bounding_box(region_ids=label_id)
166-
center_coord = bbox_max - bbox_min
167-
spim_crop = spim_img.crop_centered(center_coord, patch_size=(256,256,1))[0]
168-
mask_crop = mask_img.crop_centered(center_coord, patch_size=(256,256,1))[0]
169-
170-
# roi_mask = dseg_data == label_id
171-
#
172-
# bbox = _get_bounding_box(roi_mask, pad=5)
173-
# if bbox is None:
174-
# ax.text(
175-
# 0.5,
176-
# 0.5,
177-
# f"{label_name}\n(empty)",
178-
# ha="center",
179-
# va="center",
180-
# transform=ax.transAxes,
181-
# fontsize=7,
182-
# color="gray",
183-
# )
184-
# ax.axis("off")
185-
# continue
186-
187-
# Crop to ROI bounding box
188-
# spim_crop = spim_norm[bbox]
189-
# ff_crop = ff_norm[bbox]
190-
191-
# Choose the Z-slice within the crop with the most field-fraction signal
192-
# z_best = _select_best_z_slice(ff_crop)
193-
194-
spim_sl = np.rot90(spim_crop[:, :, 0])
195-
mask_sl = np.rot90(mask_crop[:, :, 0])
196-
197-
ax.imshow(spim_sl, cmap="gray", vmin=0, vmax=1, aspect=aspect_axial)
198-
mask_masked = np.ma.masked_where(mask_sl < 0.01, mask_sl)
199-
ax.imshow(mask_masked, cmap="hot", alpha=0.6, vmin=0, vmax=1, aspect=aspect_axial)
151+
center_coord = tuple((x + y) / 2 for x, y in zip(bbox_min, bbox_max))
152+
spim_crop = spim_img.crop_centered(center_coord, patch_size=(2000,2000,1))
153+
mask_crop = mask_img.crop_centered(center_coord, patch_size=(2000,2000,1))
154+
155+
156+
spim_sl = np.rot90(spim_crop.data[0, :, :].squeeze().compute())
157+
mask_sl = np.rot90(mask_crop.data[0, :, :].squeeze().compute())
158+
159+
ax.imshow(spim_sl, cmap="gray")
160+
mask_masked = np.ma.masked_where(mask_sl < 100, mask_sl)
161+
ax.imshow(mask_masked, cmap="spring", alpha=0.6, vmin=0, vmax=100, aspect=aspect_axial)
200162
ax.set_title(label_name, fontsize=7, pad=2)
201163
ax.set_xticks([])
202164
ax.set_yticks([])

0 commit comments

Comments
 (0)