Skip to content

Commit

Permalink
Add one extra pixel to block for cv2.warpAffine
Browse files Browse the repository at this point in the history
  • Loading branch information
Yu-AnChen committed Sep 6, 2023
1 parent b887680 commit 942ed3b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
11 changes: 8 additions & 3 deletions palom/block_affine.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,11 @@ def block_affine(
)

x1_src, y1_src = np.ceil(
np.clip(inversed_corners.max(axis=0), 0, None)
# Add one additional pixel to handle border/edge effect
np.clip(inversed_corners.max(axis=0) + 1, 0, None)
).astype(int)
x0_src, y0_src = np.floor(
np.clip(inversed_corners.min(axis=0), 0, None)
np.clip(inversed_corners.min(axis=0) - 1, 0, None)
).astype(int)

if multichannel:
Expand All @@ -85,7 +86,11 @@ def block_affine(
rotation=transformation.rotation,
shear=transformation.shear
)
order = cv2.INTER_NEAREST if is_mask else cv2.INTER_AREA

# INTER_AREA is not supported
# https://github.com/opencv/opencv/blob/1ebea1e0f0a4b95515f3e701c5e4243b31f82705/modules/imgproc/src/imgwarp.cpp#L2726-L2756
# https://medium.com/@wenrudong/what-is-opencvs-inter-area-actually-doing-282a626a09b3
order = cv2.INTER_NEAREST if is_mask else cv2.INTER_LINEAR
try:
warped_src_img_block = cv2.warpAffine(
src_img_block, block_tform.params[:2, :],
Expand Down
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 = "palom"
version = "2023.8.1"
version = "2023.8.2"
description = "Piecewise alignment for layers of mosaics"
authors = ["Yu-An Chen <[email protected]>"]
readme = "README.md"
Expand Down

0 comments on commit 942ed3b

Please sign in to comment.