From c330cd279b3a61a41cfad54507137f1df88e0219 Mon Sep 17 00:00:00 2001 From: Yohsuke Fukai Date: Mon, 14 Feb 2022 10:42:06 +0900 Subject: [PATCH 1/2] fixing order of row and col --- src/m2stitch/stitching.py | 12 +++++++----- tests/test_stitching.py | 27 +++++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 5 deletions(-) diff --git a/src/m2stitch/stitching.py b/src/m2stitch/stitching.py index d98443d..b906faf 100644 --- a/src/m2stitch/stitching.py +++ b/src/m2stitch/stitching.py @@ -46,10 +46,10 @@ def stitch_images( the images to stitch. rows : list, optional - the row indices (tile position in the last dimension) of the images. + the row indices (tile position in the second last dimension) of the images. cols : list, optional - the column indices (tile position in the second last dimension) of the images + the column indices (tile position in the last dimension) of the images position_indices : np.ndarray, optional the tile position indices in each dimension. @@ -89,9 +89,9 @@ def stitch_images( warnings.warn( "row_col_transpose is True. The default value will be changed to False in the major release." ) - position_indices = np.array([rows, cols]).T - else: position_indices = np.array([cols, rows]).T + else: + position_indices = np.array([rows, cols]).T position_indices = np.array(position_indices) assert images.shape[0] == position_indices.shape[0] assert position_indices.shape[1] == images.ndim - 1 @@ -100,7 +100,7 @@ def stitch_images( assert images.shape[0] == position_indices.shape[0] assert position_initial_guess.shape[1] == images.ndim - 1 assert 0 <= overlap_diff_threshold and overlap_diff_threshold <= 100 - _cols, _rows = position_indices.T + _rows, _cols = position_indices.T sizeY, sizeX = images.shape[1:] @@ -175,6 +175,8 @@ def get_lims(dimension, size): predictor = EllipticEnvelope(contamination=0.4) # TODO make threshold adjustable + assert np.any(grid["top_ncc_first"] > 0.5), "there is no good top pair" + assert np.any(grid["left_ncc_first"] > 0.5), "there is no good left pair" left_displacement = compute_image_overlap2( grid[grid["left_ncc_first"] > 0.5], "left", sizeY, sizeX, predictor ) diff --git a/tests/test_stitching.py b/tests/test_stitching.py index 8de11c4..12b0334 100644 --- a/tests/test_stitching.py +++ b/tests/test_stitching.py @@ -48,3 +48,30 @@ def test_stitching_init_guess( assert np.array_equal(result_df.index, props.index) assert all(np.abs(result_df["y_pos"] - props["y_pos"]) <= props["allowed_error"]) assert all(np.abs(result_df["x_pos"] - props["x_pos"]) <= props["allowed_error"]) + + +def test_stitching_with_pos(test_image_path: Tuple[npt.NDArray, pd.DataFrame]) -> None: + testimages, props = test_image_path + """It exits with a status code of zero.""" + poss = props[["y_pos", "x_pos"]].values + + def get_pos(vals): + vals2 = np.round(np.array(vals) / 500).astype(np.int64) + sorted_vals = np.sort(np.unique(vals2)) + d = dict(zip(sorted_vals, np.arange(len(sorted_vals)))) + return list(map(d.get, vals2)) + + pos_indices = np.array( + [ + get_pos(poss[:, 0]), + get_pos(poss[:, 1]), + ] + ).T + assert all(pos_indices[:, 0] == props["row"]) + assert all(pos_indices[:, 1] == props["col"]) + result_df, _ = stitch_images( + testimages, position_indices=pos_indices, row_col_transpose=False + ) + assert np.array_equal(result_df.index, props.index) + assert all(np.abs(result_df["y_pos"] - props["y_pos"]) <= props["allowed_error"]) + assert all(np.abs(result_df["x_pos"] - props["x_pos"]) <= props["allowed_error"]) From a9f9018ad096f8c76147c7d4156898dc84c4bfbe Mon Sep 17 00:00:00 2001 From: Yohsuke Fukai Date: Mon, 14 Feb 2022 10:42:26 +0900 Subject: [PATCH 2/2] bumped version --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 3c4361b..c987a76 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "m2stitch" -version = "0.5.0" +version = "0.5.1" description = "M2Stitch" authors = ["Yohsuke Fukai "] license = "MIT"