diff --git a/pyproject.toml b/pyproject.toml index 024adad..facb65a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -16,7 +16,6 @@ requires-python = ">=3.11" dependencies = [ "numpy", "scipy", - "matplotlib", "ruptures", "sknw", "scikit-image>=0.26,<0.27", @@ -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", ] @@ -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" } diff --git a/src/pnanolocz_lib/level.py b/src/pnanolocz_lib/level.py index 251a068..c56c05f 100644 --- a/src/pnanolocz_lib/level.py +++ b/src/pnanolocz_lib/level.py @@ -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", @@ -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]]: """ @@ -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)``). @@ -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}")