Skip to content

Commit b9b587a

Browse files
authoredJul 1, 2021
Update BilinearInterpolation.cpp
1 parent fb64f91 commit b9b587a

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed
 

‎Image Interpolation/BilinearInterpolation.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,16 @@ Mat BilinearInterpolation(Mat src, float sx, float sy) {
1010
for (int i = 0; i < dst_row; i++) {
1111
float index_i = (i + 0.5) / sx - 0.5;
1212
if (index_i < 0) index_i = 0;
13-
if (index_i > row - 2) index_i = row - 2;
13+
if (sx < 1.0 && index_i > row - 2) index_i = row - 2;
14+
if (sx >= 1.0 && index_i > row - 1) index_i = row - 1;
1415
int i1 = floor(index_i);
1516
int i2 = ceil(index_i);
1617
float u = index_i - i1;
1718
for (int j = 0; j < dst_col; j++) {
1819
float index_j = (j + 0.5) / sy - 0.5;
1920
if (index_j < 0) index_j = 0;
20-
if (index_j > col - 2) index_j = col - 2;
21+
if (sy < 1.0 && index_j > col - 2) index_j = col - 2;
22+
if (sy >= 1.0 && index_j > col - 1) index_j = col - 1;
2123
int j1 = floor(index_j);
2224
int j2 = ceil(index_j);
2325
float v = index_j - j1;

0 commit comments

Comments
 (0)
Please sign in to comment.