Advertisement
Guest User

Untitled

a guest
Jul 22nd, 2017
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.72 KB | None | 0 0
  1. #include <iostream>
  2. #include <deque>
  3. #include <algorithm>
  4. #include "CImg.h"
  5.  
  6. using namespace cimg_library;
  7.  
  8. inline float max( float a, float b){
  9.     if(a < b){
  10.         return b;
  11.     } else {
  12.         return a;
  13.     }
  14. }
  15.  
  16. class element{
  17.     float s1, s2, s3, s4, s5, s6, s7, s8, s9; //main average and sector averages
  18.     public:
  19.         CImg<float> surface; // base image segment
  20.         element(CImg<float>*, int, int, int);
  21.         float compareSec(element*);
  22. };
  23.  
  24. element::element(CImg<float> * input, int ix, int iy, int size){
  25.     surface = input->get_crop(ix, iy, ix+size, iy+size);
  26.     int div = size/3;
  27.     s1 = surface.get_crop(0, 0, div, div).mean();
  28.     s2 = surface.get_crop(0, div, div, div+div).mean();
  29.     s3 = surface.get_crop(0, div+div, div, size).mean();
  30.     s4 = surface.get_crop(div, 0, div+div, div).mean();
  31.     s5 = surface.get_crop(div, div, div+div, div+div).mean();
  32.     s6 = surface.get_crop(div, div+div, div+div, size).mean();
  33.     s7 = surface.get_crop(div+div, 0, size, div).mean();
  34.     s8 = surface.get_crop(div+div, div, size, div+div).mean();
  35.     s9 = surface.get_crop(div+div, div+div, size, size).mean();
  36. }
  37.  
  38. // maximum sec difference
  39. float element::compareSec(element * a){
  40.     float maxi = 0;
  41.     maxi = max(maxi, abs(s1 - a->s1));
  42.     maxi = max(maxi, abs(s2 - a->s2));
  43.     maxi = max(maxi, abs(s3 - a->s3));
  44.     maxi = max(maxi, abs(s4 - a->s4));
  45.     maxi = max(maxi, abs(s5 - a->s5));
  46.     maxi = max(maxi, abs(s6 - a->s6));
  47.     maxi = max(maxi, abs(s7 - a->s7));
  48.     maxi = max(maxi, abs(s8 - a->s8));
  49.     maxi = max(maxi, abs(s9 - a->s9));
  50.     return maxi;
  51. }
  52.  
  53. int main(int argc, char** argv){
  54.     CImg<float> image(argv[1]);
  55.     CImg<float> map(argv[2]);
  56.     image.equalize(128);
  57.     map.equalize(128);
  58.     int size = atoi(argv[4]);
  59.     for(int p = 0; p < 2; p++){
  60.         std::deque<element> elements;
  61.         int increment = size*0.5;
  62.         int s = p*(size*0.5);
  63.         for(int x = s; x < image.width(); x+=increment){
  64.             for(int y = s; y < image.height(); y+=increment){
  65.                 elements.push_back(element(&image, x, y, size));
  66.             }
  67.         }
  68.         increment = size*0.75;
  69.         int last = 0;
  70.         for(int x = s; x < map.width(); x+=increment){
  71.             for(int y = s; y < map.height(); y+=increment){
  72.                 element current = element(&map, x, y, size);
  73.                 int pos = 0;
  74.                 float maxi = 0;
  75.                 for(int z = 0; z < elements.size(); z++){
  76.                     float dif = 1/elements[z].compareSec(&current);
  77.                     if(maxi < dif){
  78.                         maxi = dif;
  79.                         pos = z;
  80.                     }
  81.                 }
  82.                 if(x != 0 and y != 0){
  83.                     map.draw_image(x, y, elements[pos].surface, 0.1); // hack-y smooth bliting operation
  84.                     for(int z = 1; z < size*0.75 + 1; z++){
  85.                         map.draw_image(x+z, y+z, elements[pos].surface.get_crop(z, z, size-z, size-z), 0.18);
  86.                     }
  87.                 } else {
  88.                     map.draw_image(x, y, elements[pos].surface);
  89.                 }
  90.             }
  91.         }
  92.     }
  93.     map.save(argv[3]);
  94.    
  95.     return 0;
  96. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement