Guest User

Untitled

a guest
Mar 20th, 2018
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.37 KB | None | 0 0
  1. void R2Image::
  2. blendOtherImageTranslated(R2Image * otherImage)
  3. {
  4. R2Image *output = new R2Image(*otherImage);
  5. std::vector<Feature> features = *(this->Harris(3));
  6. int searchSpaceXDim = this->Width() / 10; // half the search space dimension
  7. int searchSpaceYDim = this->Height() / 10;
  8. int windowDimension = 12; // half the window dimension
  9.  
  10. std::vector<Feature>::iterator it;
  11.  
  12. for(it=features.begin(); it != features.end(); it++) {
  13. int i, j, m, n;
  14. double min_ssd = std::numeric_limits<double>::max();
  15. int min_ssd_x = 0, min_ssd_y = 0;
  16.  
  17. Feature ft = *it;
  18.  
  19. // Loop through search space
  20.  
  21. for(
  22. i = std::max(ft.centerX - searchSpaceXDim, windowDimension);
  23. i <= std::min(ft.centerX + searchSpaceXDim, this->Width() - windowDimension);
  24. i++
  25. ) {
  26. for(
  27. j = std::max(ft.centerY - searchSpaceYDim, windowDimension);
  28. j <= std::min(ft.centerY + searchSpaceYDim, this->Height() - windowDimension);
  29. j++
  30. ) {
  31. // For each pixel (i, j) in the search space
  32. double ssd = 0;
  33.  
  34. // Calculate the SSD with the feature assuming (i, j) is the center of the new feature
  35. for(m=-1*windowDimension; m<=windowDimension; m++) {
  36. for(n=-1*windowDimension; n<=windowDimension; n++) {
  37. double oldLuminance = this->Pixel(ft.centerX + m, ft.centerY + n).Luminance();
  38. double newLuminance = otherImage->Pixel(i + m, j + n).Luminance();
  39. double diff = oldLuminance - newLuminance;
  40. ssd += diff * diff;
  41. }
  42. }
  43.  
  44. // If the computed SSD is lower than the current minimum, set the current minimum to (i, j)
  45. if(ssd < min_ssd) {
  46. min_ssd = ssd;
  47. min_ssd_x = i;
  48. min_ssd_y = j;
  49. }
  50. }
  51. }
  52.  
  53. // Line and box drawing
  54. for(m=-4; m<=4; m++) {
  55. for(n=-4; n<=4; n++) {
  56. output->Pixel(min_ssd_x+m, min_ssd_y+n).Reset(1, 1, 0, 1);
  57. }
  58. }
  59.  
  60. int x1 = ft.centerX;
  61. int x2 = min_ssd_x;
  62. int y1 = ft.centerY;
  63. int y2 = min_ssd_y;
  64. int dx = x2 - x1;
  65. int dy = y2 - y1;
  66.  
  67. if(dx != 0) { // avoid div by zero errors
  68. for(int x=std::min(x1, x2); x<=std::max(x1, x2); x++) {
  69. int y = int(std::round(y1 + (double(dy * (x-x1)) / double(dx))));
  70. output->Pixel(x, y).Reset(1, 1, 0, 1);
  71. }
  72. }
  73. }
  74.  
  75. this->pixels = output->pixels;
  76. output->pixels = nullptr;
  77. delete output;
  78. }
Add Comment
Please, Sign In to add comment