Advertisement
Guest User

Untitled

a guest
May 22nd, 2019
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.58 KB | None | 0 0
  1. void nearest_neighbor(Mat_<Vec3b> img, int w1, int h1, int w2, int h2) {
  2. Mat_<Vec3b> result(h2, w2);
  3. double x_ratio = w1 / (double)w2;
  4. double y_ratio = h1 / (double)h2;
  5. double px, py;
  6.  
  7. for (int i = 0; i < h2; i++) {
  8. for (int j = 0; j < w2; j++) {
  9. result(i, j) = 0;
  10.  
  11. }
  12. }
  13.  
  14. for (int i = 0; i < h2; i++) {
  15. for (int j = 0; j < w2; j++) {
  16. px = floor(j * x_ratio);
  17. py = floor(i * y_ratio);
  18. result(i, j) = img((int)(py),(int) px);
  19. //result(i+1, j+1) = img(1 + round(i/x_ratio),1 + round(j/y_ratio));
  20. }
  21. }
  22. imshow("result", result);
  23. waitKey(0);
  24.  
  25.  
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement