nearest neighbor
| 90 | |
| 91 | // nearest neighbor |
| 92 | void resize_nearest_8u(const Mat8u& src, Mat8u& dst) { |
| 93 | AlignedVector<int> tabx(dst.rows()); |
| 94 | AlignedVector<int> taby(dst.cols()); |
| 95 | const double fx = static_cast<double>(dst.rows()) / src.rows(); |
| 96 | const double fy = static_cast<double>(dst.cols()) / src.cols(); |
| 97 | const double ifx = 1.0f / fx; |
| 98 | const double ify = 1.0f / fy; |
| 99 | const size_t ch = src.channels(); |
| 100 | for (size_t dx = 0; dx < tabx.size(); ++dx) { |
| 101 | double rx = dx * ifx; |
| 102 | int sx = static_cast<int>(floor(rx)); |
| 103 | sx = megcv::saturate(sx, 0, static_cast<int>(src.rows())); |
| 104 | tabx[dx] = sx; |
| 105 | } |
| 106 | for (size_t dy = 0; dy < taby.size(); ++dy) { |
| 107 | double ry = dy * ify; |
| 108 | int sy = static_cast<int>(floor(ry)); |
| 109 | sy = megcv::saturate(sy, 0, static_cast<int>(src.cols())); |
| 110 | taby[dy] = sy; |
| 111 | } |
| 112 | |
| 113 | int tabxsize = tabx.size(); |
| 114 | int tabysize = taby.size(); |
| 115 | if (ch == 1) { |
| 116 | for (int dx = 0; dx < tabxsize; ++dx) { |
| 117 | uchar* pdst = dst.ptr(dx); |
| 118 | const uchar* psrc = src.ptr(tabx[dx]); |
| 119 | for (int dy = 0; dy < tabysize; ++dy) { |
| 120 | uchar* pcdst = pdst + dy; |
| 121 | const uchar* pcsrc = psrc + taby[dy]; |
| 122 | pcdst[0] = pcsrc[0]; |
| 123 | } |
| 124 | } |
| 125 | } else if (ch == 3) { |
| 126 | for (int dx = 0; dx < tabxsize; ++dx) { |
| 127 | uchar* pdst = dst.ptr(dx); |
| 128 | const uchar* psrc = src.ptr(tabx[dx]); |
| 129 | int dy3 = 0; |
| 130 | for (int dy = 0; dy < tabysize; ++dy, dy3 += 3) { |
| 131 | uchar* pcdst = pdst + dy3; |
| 132 | const uchar* pcsrc = psrc + taby[dy] * 3; |
| 133 | pcdst[0] = pcsrc[0]; |
| 134 | pcdst[1] = pcsrc[1]; |
| 135 | pcdst[2] = pcsrc[2]; |
| 136 | } |
| 137 | } |
| 138 | } |
| 139 | } |
| 140 | |
| 141 | void resize_nearest_32f(const Mat32f& src, Mat32f& dst) { |
| 142 | AlignedVector<int> tabx(dst.rows()); |