Skip to content

Commit fb64f91

Browse files
authored
Update NearestNeighborInterpolation.cpp
1 parent 2d84efe commit fb64f91

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

Image Interpolation/NearestNeighborInterpolation.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ Mat NearestNeighborInterpolation(Mat src, float sx, float sy) {
99
Mat dst(dst_row, dst_col, CV_8UC1);
1010
for (int i = 0; i < dst_row; i++) {
1111
for (int j = 0; j < dst_col; j++) {
12-
int pre_i = round(i / sy);
13-
int pre_j = round(j / sx);
12+
int pre_i = floor(i / sy);
13+
int pre_j = floor(j / sx);
1414
if (pre_i > row - 1) pre_i = row - 1;
1515
if (pre_j > col - 1) pre_j = col - 1;
1616
dst.at<uchar>(i, j) = src.at<uchar>(pre_i, pre_j);
@@ -22,8 +22,8 @@ Mat NearestNeighborInterpolation(Mat src, float sx, float sy) {
2222
Mat dst(dst_row, dst_col, CV_8UC3);
2323
for (int i = 0; i < dst_row; i++) {
2424
for (int j = 0; j < dst_col; j++) {
25-
int pre_i = round(i / sy);
26-
int pre_j = round(j / sx);
25+
int pre_i = floor(i / sy);
26+
int pre_j = floor(j / sx);
2727
if (pre_i > row - 1) pre_i = row - 1;
2828
if (pre_j > col - 1) pre_j = col - 1;
2929
dst.at<Vec3b>(i, j)[0] = src.at<Vec3b>(pre_i, pre_j)[0];
@@ -33,4 +33,4 @@ Mat NearestNeighborInterpolation(Mat src, float sx, float sy) {
3333
}
3434
return dst;
3535
}
36-
}
36+
}

0 commit comments

Comments
 (0)