Skip to content

Commit

Permalink
Background scaling, naming, and squeezing (#429)
Browse files Browse the repository at this point in the history
* correctly scale background images

* improve background layer names

* squeeze arrays before adding to viewer

* fix import

* online squeeze first dimension
  • Loading branch information
talonchandler authored Aug 26, 2023
1 parent 7f56ed0 commit 2f5ae16
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
7 changes: 7 additions & 0 deletions recOrder/calib/Calibration.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import numpy as np
from importlib_metadata import version
from iohub import open_ome_zarr
from iohub.ngff_meta import TransformationMeta
from mpl_toolkits.axes_grid1.axes_divider import make_axes_locatable
from napari.utils.notifications import show_warning
from scipy.interpolate import interp1d
Expand Down Expand Up @@ -1081,6 +1082,7 @@ def capture_bg(self, n_avg, directory):
yx_list.append(self._capture_state(f"State{channel}", n_avg))
logging.debug(f"Saving Background State{channel}")
cyx_data = np.array(yx_list)
yx_scale = self.mmc.getPixelSizeUm()

# Save to zarr
with open_ome_zarr(
Expand All @@ -1095,6 +1097,11 @@ def capture_bg(self, n_avg, directory):
shape=(1, num_states, 1, cyx_data.shape[1], cyx_data.shape[2]),
dtype=np.float32,
chunks=(1, 1, 1, cyx_data.shape[1], cyx_data.shape[2]),
transform=[
TransformationMeta(
type="scale", scale=[1, 1, 1, yx_scale, yx_scale]
)
],
)
position["0"][0, :, 0] = cyx_data # save to 1C1YX array

Expand Down
10 changes: 6 additions & 4 deletions recOrder/plugin/main_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -1154,6 +1154,8 @@ def _add_or_update_image_layer(
move_to_top : bool, optional
whether to move the updated layer to the top of layers list, by default True
"""
if image.shape[0] == 1:
image = image.squeeze(axis=0)
scale = scale[-image.ndim :] # match shapes

if name in self.viewer.layers:
Expand Down Expand Up @@ -1181,16 +1183,16 @@ def _add_or_update_image_layer(
@Slot(tuple)
def handle_bg_image_update(self, value):
data, scale = value
self._add_or_update_image_layer(data, "Background Images", scale=scale)
self._add_or_update_image_layer(data, "Raw Background", scale=scale)

@Slot(tuple)
def handle_bg_bire_image_update(self, value):
data, scale = value
self._add_or_update_image_layer(
data[0], "Background Retardance", scale=scale
data[0], "Retardance Background", scale=scale
)
self._add_or_update_image_layer(
data[1], "Background Orientation", cmap="hsv", scale=scale
data[1], "Orientation Background", cmap="hsv", scale=scale
)

def handle_layers_updated(self, event: Event):
Expand All @@ -1209,7 +1211,7 @@ def handle_layers_updated(self, event: Event):
orientation_name = layers[-1].name
suffix = orientation_name.replace("Orientation", "")
retardance_name = "Retardance" + suffix
overlay_name = "BirefringenceOverlay" + suffix
overlay_name = "Birefringence Overlay" + suffix
# if the matching retardance layer is present, generate an overlay
if retardance_name in layers:
logging.info(
Expand Down

0 comments on commit 2f5ae16

Please sign in to comment.