From 793237fda62ed683f8ba305703ed0958cb1a1c37 Mon Sep 17 00:00:00 2001 From: Christoph Sommer Date: Mon, 16 Oct 2023 16:16:20 +0200 Subject: [PATCH] Update setup.cfg fiexes @2 / Expose normalization parameter of phase_cross_correlation() to user --- setup.cfg | 6 ++++-- src/napari_correct_drift/__init__.py | 2 +- src/napari_correct_drift/_core.py | 20 ++++++++++++++++++-- src/napari_correct_drift/_widget.py | 14 ++++++++++++++ 4 files changed, 37 insertions(+), 5 deletions(-) diff --git a/setup.cfg b/setup.cfg index e352200..a9065ec 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,6 +1,6 @@ [metadata] name = napari-correct-drift -version = 0.0.2 +version = 0.2.0 description = Drift correction 2D/3D for Napari similar to Fijis Correct 3D drift long_description = file: README.md long_description_content_type = text/markdown @@ -32,8 +32,10 @@ project_urls = packages = find: install_requires = numpy - magicgui qtpy + pandas + scikit-image + scipy python_requires = >=3.8 include_package_data = True diff --git a/src/napari_correct_drift/__init__.py b/src/napari_correct_drift/__init__.py index d006a79..08ae347 100644 --- a/src/napari_correct_drift/__init__.py +++ b/src/napari_correct_drift/__init__.py @@ -1,4 +1,4 @@ -__version__ = "0.0.2" +__version__ = "0.2.0" from ._core import ArrayAxesStandardizer, CorrectDrift, ROIRect from ._sample_data import sample_2d, sample_3d, sample_3d_ch diff --git a/src/napari_correct_drift/_core.py b/src/napari_correct_drift/_core.py index 32d86b4..5972b7c 100644 --- a/src/napari_correct_drift/_core.py +++ b/src/napari_correct_drift/_core.py @@ -380,16 +380,27 @@ def estimate_drift( increment: int = 1, upsample_factor: int = 1, roi: ROIRect = None, + normalization: str = "phase", mode: str = "relative", ): if mode == "relative": return self._estimate_drift_relative( - t0, channel, increment, upsample_factor, roi + t0, + channel, + increment, + upsample_factor, + normalization, + roi, ) elif mode == "absolute": return self._estimate_drift_absolute( - t0, channel, increment, upsample_factor, roi + t0, + channel, + increment, + upsample_factor, + normalization, + roi, ) else: @@ -401,6 +412,7 @@ def _estimate_drift_relative( channel: int = 0, increment: int = 1, upsample_factor: int = 1, + normalization: str = "phase", roi: ROIRect = None, ): offsets_rel = np.zeros((self.T, 3)) @@ -451,12 +463,14 @@ def _estimate_drift_relative( action="ignore", category=RuntimeWarning, ) + offset, _, _ = phase_cross_correlation( ref_img, mov_img, upsample_factor=upsample_factor, return_error="always", disambiguate=True, + normalization=normalization, ) offset = np.asarray(offset, dtype="float32") @@ -491,6 +505,7 @@ def _estimate_drift_absolute( channel: int = 0, increment: int = 1, upsample_factor: int = 1, + normalization: str = "phase", roi: ROIRect = None, ): if not self.is_multi_channel: @@ -533,6 +548,7 @@ def _estimate_drift_absolute( upsample_factor=upsample_factor, return_error="always", disambiguate=True, + normalization=normalization, ) offset = -np.asarray(offset, dtype="float32") diff --git a/src/napari_correct_drift/_widget.py b/src/napari_correct_drift/_widget.py index 22a1337..e1e334a 100644 --- a/src/napari_correct_drift/_widget.py +++ b/src/napari_correct_drift/_widget.py @@ -347,6 +347,14 @@ def _init_other_params(self): parameter_layout.addWidget(self.extend_output, i, 1) i += 1 + # phase normalization + self.normalization_box = QCheckBox() + self.normalization_box.setChecked(True) + + parameter_layout.addWidget(QLabel("Use phase normalization"), i, 0) + parameter_layout.addWidget(self.normalization_box, i, 1) + i += 1 + parameter_panel.setLayout(parameter_layout) self.main_layout.addWidget(parameter_panel) @@ -395,6 +403,11 @@ def estimate_drift(self): # get increment upsample_factor = self.upsample_box.value() + # get increment + normalization = None + if self.normalization_box.isChecked(): + normalization = "phase" + use_roi = self.roi_checkbox.isChecked() roi = None @@ -426,6 +439,7 @@ def estimate_drift(self): upsample_factor=upsample_factor, roi=roi, mode=estimate_mode, + normalization=normalization, ) if increment > 1: