Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void nearest_neighbor(Mat_<Vec3b> img, int w1, int h1, int w2, int h2) {
- Mat_<Vec3b> result(h2, w2);
- double x_ratio = w1 / (double)w2;
- double y_ratio = h1 / (double)h2;
- double px, py;
- for (int i = 0; i < h2; i++) {
- for (int j = 0; j < w2; j++) {
- result(i, j) = 0;
- }
- }
- for (int i = 0; i < h2; i++) {
- for (int j = 0; j < w2; j++) {
- px = floor(j * x_ratio);
- py = floor(i * y_ratio);
- result(i, j) = img((int)(py),(int) px);
- //result(i+1, j+1) = img(1 + round(i/x_ratio),1 + round(j/y_ratio));
- }
- }
- imshow("result", result);
- waitKey(0);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement