diff --git a/pyproject.toml b/pyproject.toml index ba645f8..0345e69 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "m2stitch" -version = "0.1.1" +version = "0.2.0" description = "M2Stitch" authors = ["Yohsuke Fukai "] license = "MIT" diff --git a/src/m2stitch/_stage_model.py b/src/m2stitch/_stage_model.py index ec44d1f..238f1a9 100644 --- a/src/m2stitch/_stage_model.py +++ b/src/m2stitch/_stage_model.py @@ -124,7 +124,9 @@ def compute_image_overlap( return tuple(map(float, model["x"])) elif model["fun"] < best_model["fun"]: best_model = model - assert not best_model is None + assert ( + not best_model is None + ), "Overlap model estimation failed, try raising the value of overlap_prob_uniform_threshold" # noqa : # best_model_params : Tuple[Float,Float,Float] = tuple(best_model["x"]) assert len(best_model["x"]) == 3 return tuple(map(float, best_model["x"])) diff --git a/src/m2stitch/stitching.py b/src/m2stitch/stitching.py index be26dde..1e7d347 100644 --- a/src/m2stitch/stitching.py +++ b/src/m2stitch/stitching.py @@ -27,6 +27,7 @@ def stitch_images( rows: Sequence[Any], cols: Sequence[Any], pou: Float = 3, + overlap_prob_uniform_threshold: Float = 80, full_output: bool = False, ) -> Tuple[pd.DataFrame, dict]: """Compute image positions for stitching. @@ -45,6 +46,11 @@ def stitch_images( pou : Float, default 3 the "percent overlap uncertainty" parameter + overlap_prob_uniform_threshold : Float, default 80 + the upper threshold for "uniform probability". + raise this value to ease assumption + that the displacement is following non-uniform distribution. + full_output : bool, default False if True, returns the full computation result in the pd.DataFrame @@ -105,9 +111,13 @@ def get_index(row, col): for j, key in enumerate(["ncc", "x", "y"]): grid.loc[i2, f"{direction}_{key}_first"] = max_peak[j] - prob_uniform_n, mu_n, sigma_n = compute_image_overlap(grid, "top", W, H) + prob_uniform_n, mu_n, sigma_n = compute_image_overlap( + grid, "top", W, H, prob_uniform_threshold=overlap_prob_uniform_threshold + ) overlap_n = 100 - mu_n - prob_uniform_w, mu_w, sigma_w = compute_image_overlap(grid, "left", W, H) + prob_uniform_w, mu_w, sigma_w = compute_image_overlap( + grid, "left", W, H, prob_uniform_threshold=overlap_prob_uniform_threshold + ) overlap_w = 100 - mu_w overlap_n = np.clip(overlap_n, pou, 100 - pou)