Skip to content

Commit

Permalink
Merge pull request #184 from yfukai/update_example
Browse files Browse the repository at this point in the history
updated example
  • Loading branch information
yfukai authored Feb 13, 2022
2 parents 4d391c9 + 42a0084 commit 192880b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 14 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ __pycache__/
tests/data/testimages_lowncc.npy
tests/data/testimages_lowncc2.npy
tests/data/testimages_lowncc2.csv
examples/stitched_image.npy
30 changes: 16 additions & 14 deletions examples/stitching_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,40 +12,42 @@
props_file_path = path.join(script_path, "../tests/data/testimages_props.csv")
images = np.load(image_file_path)
props = pd.read_csv(props_file_path, index_col=0)
rows = props["col"].to_list()
cols = props["row"].to_list()

rows = props["row"].to_list()
cols = props["col"].to_list()

print(images.shape)
# must be 3-dim, with each dimension meaning (tile_index,x,y)
print(rows)
# the row indices for each tile index. for example, [1,1,2,2,2,...]
# the row (second-last dim.) indices for each tile index. for example, [1,1,2,2,2,...]
print(cols)
# the column indices for each tile index. for example, [2,3,1,2,3,...]
# the column (last dim.) indices for each tile index. for example, [2,3,1,2,3,...]

result_df, _ = m2stitch.stitch_images(images, rows, cols)
# Note : the row_col_transpose=True is kept only for the sake of version compatibility.
# In the mejor version, the row_col_transpose=False will be the default.
result_df, _ = m2stitch.stitch_images(images, rows, cols, row_col_transpose=False)

print(result_df["x_pos"])
# the absolute x positions of the tiles
print(result_df["y_pos"])
# the absolute y positions of the tiles

# the absolute y (second last dim.) positions of the tiles
print(result_df["x_pos"])
# the absolute x (last dim.) positions of the tiles

# stitching example
result_df["x_pos2"] = result_df["x_pos"] - result_df["x_pos"].min()
result_df["y_pos2"] = result_df["y_pos"] - result_df["y_pos"].min()
result_df["x_pos2"] = result_df["x_pos"] - result_df["x_pos"].min()

size_x = images.shape[1]
size_y = images.shape[2]
size_y = images.shape[1]
size_x = images.shape[2]

stitched_image_size = (
result_df["x_pos2"].max() + size_x,
result_df["y_pos2"].max() + size_y,
result_df["x_pos2"].max() + size_x,
)
stitched_image = np.zeros_like(images, shape=stitched_image_size)
for i, row in result_df.iterrows():
stitched_image[
row["x_pos2"] : row["x_pos2"] + size_x,
row["y_pos2"] : row["y_pos2"] + size_y,
row["x_pos2"] : row["x_pos2"] + size_x,
] = images[i]

result_image_file_path = path.join(script_path, "stitched_image.npy")
Expand Down

0 comments on commit 192880b

Please sign in to comment.