Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ requires-python = ">=3.11"
dependencies = [
"numpy",
"scipy",
"matplotlib",
"ruptures",
"sknw",
"scikit-image>=0.26,<0.27",
Expand Down Expand Up @@ -67,6 +66,7 @@ classifiers = [
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Programming Language :: Python :: 3.13",
"Topic :: Scientific/Engineering :: Image Processing",
]

Expand All @@ -81,11 +81,16 @@ dev = [
"codespell>=2.3.0",
"mypy==1.11.1",
"nbstripout",
"setuptools_scm",
]

[project.urls]
Homepage = "https://github.com/derollins/Python-Nanolocz-Library"

[project.entry-points."playnano.filters"]
pnanolocz_level = "pnanolocz_lib.level:apply_level"
pnanolocz_level_auto = "pnanolocz_lib.level_auto:apply_level_auto"

[tool.setuptools]
package-dir = { "" = "src" }

Expand Down
36 changes: 32 additions & 4 deletions src/pnanolocz_lib/level.py
Original file line number Diff line number Diff line change
Expand Up @@ -779,8 +779,8 @@ def _log_model(

def apply_level(
img: np.ndarray[Any, np.dtype[np.float64]],
polyx: int,
polyy: int,
polyx: Optional[int] = None,
polyy: Optional[int] = None,
method: Literal[
"plane",
"line",
Expand All @@ -789,7 +789,7 @@ def apply_level(
"smed_line",
"mean_plane",
"log_y",
],
] = "plane",
mask: Optional[np.ndarray[Any, np.dtype[np.bool_]]] = None,
) -> np.ndarray[Any, np.dtype[np.float64]]:
"""
Expand All @@ -814,7 +814,7 @@ def apply_level(
Use ``0`` to disable polynomial fitting along Y where applicable.
method : {"plane", "line", "med_line", "med_line_y", "smed_line", "mean_plane",
"log_y"}
Leveling method to apply.
Leveling method to apply. Defaults to ``"plane"``.
mask : ndarray of bool, optional
Exclusion mask with the same shape as `img` (after any single-image
promotion to ``(1, H, W)``).
Expand Down Expand Up @@ -865,18 +865,46 @@ def apply_level(
frame_mask = mask[idx] if mask is not None else None

if method == "plane":
if polyx is None:
polyx = 1
if polyy is None:
polyy = 1
leveled = level_plane(frame, frame_mask, polyx, polyy)
elif method == "line":
if polyx is None:
polyx = 1
if polyy is None:
polyy = 0
leveled = level_line(frame, frame_mask, polyx, polyy)
elif method == "med_line":
if polyx is None:
polyx = 1
if polyy is None:
polyy = 0
leveled = level_med_line(frame, frame_mask, polyx, polyy)
elif method == "med_line_y":
if polyx is None:
polyx = 0
if polyy is None:
polyy = 0
leveled = level_med_line_y(frame, frame_mask, polyx, polyy)
elif method == "smed_line":
if polyx is None:
polyx = 0
if polyy is None:
polyy = 0
leveled = level_smed_line(frame, frame_mask, polyx, polyy)
elif method == "mean_plane":
if polyx is None:
polyx = 0
if polyy is None:
polyy = 0
leveled = level_mean_plane(frame, frame_mask, polyx, polyy)
elif method == "log_y":
if polyx is None:
polyx = 0
if polyy is None:
polyy = 1
leveled = level_log_y(frame, frame_mask, polyx, polyy)
else:
raise ValueError(f"Unknown leveling method: {method}")
Expand Down