diff --git a/Image Interpolation/BilinearInterpolation.cpp b/Image Interpolation/BilinearInterpolation.cpp index a754e7d..91c9a25 100644 --- a/Image Interpolation/BilinearInterpolation.cpp +++ b/Image Interpolation/BilinearInterpolation.cpp @@ -8,16 +8,18 @@ Mat BilinearInterpolation(Mat src, float sx, float sy) { int dst_col = round(col * sy); Mat dst(dst_row, dst_col, CV_8UC3); for (int i = 0; i < dst_row; i++) { - int index_i = (i + 0.5) / sx - 0.5; + float index_i = (i + 0.5) / sx - 0.5; if (index_i < 0) index_i = 0; - if (index_i > row - 2) index_i = row - 2; + if (sx < 1.0 && index_i > row - 2) index_i = row - 2; + if (sx >= 1.0 && index_i > row - 1) index_i = row - 1; int i1 = floor(index_i); int i2 = ceil(index_i); - float u = index_i - i; + float u = index_i - i1; for (int j = 0; j < dst_col; j++) { float index_j = (j + 0.5) / sy - 0.5; if (index_j < 0) index_j = 0; - if (index_j > col - 2) index_j = col - 2; + if (sy < 1.0 && index_j > col - 2) index_j = col - 2; + if (sy >= 1.0 && index_j > col - 1) index_j = col - 1; int j1 = floor(index_j); int j2 = ceil(index_j); float v = index_j - j1; @@ -28,4 +30,4 @@ Mat BilinearInterpolation(Mat src, float sx, float sy) { } } return dst; -} \ No newline at end of file +} diff --git a/Image Interpolation/NearestNeighborInterpolation.cpp b/Image Interpolation/NearestNeighborInterpolation.cpp index 892561e..c62b5d2 100644 --- a/Image Interpolation/NearestNeighborInterpolation.cpp +++ b/Image Interpolation/NearestNeighborInterpolation.cpp @@ -9,8 +9,8 @@ Mat NearestNeighborInterpolation(Mat src, float sx, float sy) { Mat dst(dst_row, dst_col, CV_8UC1); for (int i = 0; i < dst_row; i++) { for (int j = 0; j < dst_col; j++) { - int pre_i = round(i / sy); - int pre_j = round(j / sx); + int pre_i = floor(i / sy); + int pre_j = floor(j / sx); if (pre_i > row - 1) pre_i = row - 1; if (pre_j > col - 1) pre_j = col - 1; dst.at(i, j) = src.at(pre_i, pre_j); @@ -22,8 +22,8 @@ Mat NearestNeighborInterpolation(Mat src, float sx, float sy) { Mat dst(dst_row, dst_col, CV_8UC3); for (int i = 0; i < dst_row; i++) { for (int j = 0; j < dst_col; j++) { - int pre_i = round(i / sy); - int pre_j = round(j / sx); + int pre_i = floor(i / sy); + int pre_j = floor(j / sx); if (pre_i > row - 1) pre_i = row - 1; if (pre_j > col - 1) pre_j = col - 1; dst.at(i, j)[0] = src.at(pre_i, pre_j)[0]; @@ -33,4 +33,4 @@ Mat NearestNeighborInterpolation(Mat src, float sx, float sy) { } return dst; } -} \ No newline at end of file +} diff --git a/README.md b/README.md index 0aa7953..3c598d5 100644 --- a/README.md +++ b/README.md @@ -38,9 +38,3 @@ - MedianSideWindowFilter.cpp C++复现了CVPR2019《Side Window Filter》论文(Median Filter),实现霸气的强制保边,原理请看:https://blog.csdn.net/just_sort/article/details/93664078 - RectangleDetection.cpp C++复现了StackOverFlow上面的一个有趣的矩形检测算法,并且配合Side Window Filter可以取得更好的效果,原理请看:https://blog.csdn.net/just_sort/article/details/104754937 - - - - -![我的公众号,欢迎关注](image/weixin.jpg) -