Skip to content

🐍 Geometric Computer Vision Library for Spatial AI

set align_corners=True for F.grid_sample

edgarriba26a9a561eaed
diff --git a/kornia/feature/scale_space_detector.py b/kornia/feature/scale_space_detector.py
index ff623ef7f..0ee8a7e1f 100644
--- a/kornia/feature/scale_space_detector.py
+++ b/kornia/feature/scale_space_detector.py
@@ -44,7 +44,7 @@ def _scale_index_to_scale(max_coords: torch.Tensor, sigmas: torch.Tensor) -> tor
scale_grid = torch.cat([scale_coords_index, dummy_x], dim=3)
# Finally, interpolate the scale value
- scale_val = F.grid_sample(sigmas[0].log2().view(1, 1, 1, -1).expand(scale_grid.size(0), 1, 1, L), scale_grid)
+ scale_val = F.grid_sample(sigmas[0].log2().view(1, 1, 1, -1).expand(scale_grid.size(0), 1, 1, L), scale_grid, align_corners=True)
# Replace the scale_x_y
out = torch.cat([torch.pow(2.0, scale_val).view(B, N, 1), max_coords[:, :, 1:]], dim=2)
diff --git a/kornia/geometry/depth.py b/kornia/geometry/depth.py
index 70d6018e7..f212e9147 100644
--- a/kornia/geometry/depth.py
+++ b/kornia/geometry/depth.py
@@ -163,4 +163,4 @@ def warp_frame_depth(
points_2d_src_norm: torch.Tensor = normalize_pixel_coordinates(
points_2d_src, height, width) # BxHxWx2
- return F.grid_sample(image_src, points_2d_src_norm) # BxDxHxW
+ return F.grid_sample(image_src, points_2d_src_norm, align_corners=True) # BxDxHxW
diff --git a/kornia/geometry/transform/imgwarp.py b/kornia/geometry/transform/imgwarp.py
index 0b0c0366e..00e00891f 100644
--- a/kornia/geometry/transform/imgwarp.py
+++ b/kornia/geometry/transform/imgwarp.py
@@ -447,7 +447,7 @@ def remap(tensor: torch.Tensor, map_x: torch.Tensor,
map_xy_norm = map_xy_norm.expand(batch_size, -1, -1, -1)
# warp ans return
- tensor_warped: torch.Tensor = F.grid_sample(tensor, map_xy_norm)
+ tensor_warped: torch.Tensor = F.grid_sample(tensor, map_xy_norm, align_corners=True)
return tensor_warped
diff --git a/kornia/geometry/warp/depth_warper.py b/kornia/geometry/warp/depth_warper.py
index d5619fcab..8b89d68ed 100644
--- a/kornia/geometry/warp/depth_warper.py
+++ b/kornia/geometry/warp/depth_warper.py
@@ -189,7 +189,8 @@ class DepthWarper(nn.Module):
>>> image_src = warper(depth_src, image_dst) # NxCxHxW
"""
return F.grid_sample(patch_dst, self.warp_grid(depth_src),
- mode=self.mode, padding_mode=self.padding_mode)
+ mode=self.mode, padding_mode=self.padding_mode,
+ align_corners=True)
# functional api
diff --git a/kornia/geometry/warp/homography_warper.py b/kornia/geometry/warp/homography_warper.py
index b039e76a7..693cc35d0 100644
--- a/kornia/geometry/warp/homography_warper.py
+++ b/kornia/geometry/warp/homography_warper.py
@@ -106,8 +106,10 @@ class HomographyWarper(nn.Module):
raise TypeError("Patch and homography must be on the same device. \
Got patch.device: {} dst_H_src.device: {}."
.format(patch_src.device, dst_homo_src.device))
+
return F.grid_sample(patch_src, self.warp_grid(dst_homo_src),
- mode=self.mode, padding_mode=self.padding_mode)
+ mode=self.mode, padding_mode=self.padding_mode,
+ align_corners=True)
# functional api