Skip to content

Commit

Permalink
Merge pull request #189 from yfukai/fixing_row_col_def
Browse files Browse the repository at this point in the history
Fixing row col def
  • Loading branch information
yfukai authored Feb 14, 2022
2 parents c20a8c8 + a9f9018 commit 4fd12ea
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 6 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "m2stitch"
version = "0.5.0"
version = "0.5.1"
description = "M2Stitch"
authors = ["Yohsuke Fukai <[email protected]>"]
license = "MIT"
Expand Down
12 changes: 7 additions & 5 deletions src/m2stitch/stitching.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand All @@ -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:]

Expand Down Expand Up @@ -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
)
Expand Down
27 changes: 27 additions & 0 deletions tests/test_stitching.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"])

0 comments on commit 4fd12ea

Please sign in to comment.