Skip to content

Commit

Permalink
Update setup.cfg fiexes @2 / Expose normalization parameter of phase_…
Browse files Browse the repository at this point in the history
…cross_correlation() to user
  • Loading branch information
sommerc committed Oct 16, 2023
1 parent 2ac39f6 commit 793237f
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 5 deletions.
6 changes: 4 additions & 2 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/napari_correct_drift/__init__.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
20 changes: 18 additions & 2 deletions src/napari_correct_drift/_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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))
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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")
Expand Down
14 changes: 14 additions & 0 deletions src/napari_correct_drift/_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -426,6 +439,7 @@ def estimate_drift(self):
upsample_factor=upsample_factor,
roi=roi,
mode=estimate_mode,
normalization=normalization,
)

if increment > 1:
Expand Down

0 comments on commit 793237f

Please sign in to comment.