Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <deque>
- #include <algorithm>
- #include "CImg.h"
- using namespace cimg_library;
- inline float max( float a, float b){
- if(a < b){
- return b;
- } else {
- return a;
- }
- }
- class element{
- float s1, s2, s3, s4, s5, s6, s7, s8, s9; //main average and sector averages
- public:
- CImg<float> surface; // base image segment
- element(CImg<float>*, int, int, int);
- float compareSec(element*);
- };
- element::element(CImg<float> * input, int ix, int iy, int size){
- surface = input->get_crop(ix, iy, ix+size, iy+size);
- int div = size/3;
- s1 = surface.get_crop(0, 0, div, div).mean();
- s2 = surface.get_crop(0, div, div, div+div).mean();
- s3 = surface.get_crop(0, div+div, div, size).mean();
- s4 = surface.get_crop(div, 0, div+div, div).mean();
- s5 = surface.get_crop(div, div, div+div, div+div).mean();
- s6 = surface.get_crop(div, div+div, div+div, size).mean();
- s7 = surface.get_crop(div+div, 0, size, div).mean();
- s8 = surface.get_crop(div+div, div, size, div+div).mean();
- s9 = surface.get_crop(div+div, div+div, size, size).mean();
- }
- // maximum sec difference
- float element::compareSec(element * a){
- float maxi = 0;
- maxi = max(maxi, abs(s1 - a->s1));
- maxi = max(maxi, abs(s2 - a->s2));
- maxi = max(maxi, abs(s3 - a->s3));
- maxi = max(maxi, abs(s4 - a->s4));
- maxi = max(maxi, abs(s5 - a->s5));
- maxi = max(maxi, abs(s6 - a->s6));
- maxi = max(maxi, abs(s7 - a->s7));
- maxi = max(maxi, abs(s8 - a->s8));
- maxi = max(maxi, abs(s9 - a->s9));
- return maxi;
- }
- int main(int argc, char** argv){
- CImg<float> image(argv[1]);
- CImg<float> map(argv[2]);
- image.equalize(128);
- map.equalize(128);
- int size = atoi(argv[4]);
- for(int p = 0; p < 2; p++){
- std::deque<element> elements;
- int increment = size*0.5;
- int s = p*(size*0.5);
- for(int x = s; x < image.width(); x+=increment){
- for(int y = s; y < image.height(); y+=increment){
- elements.push_back(element(&image, x, y, size));
- }
- }
- increment = size*0.75;
- int last = 0;
- for(int x = s; x < map.width(); x+=increment){
- for(int y = s; y < map.height(); y+=increment){
- element current = element(&map, x, y, size);
- int pos = 0;
- float maxi = 0;
- for(int z = 0; z < elements.size(); z++){
- float dif = 1/elements[z].compareSec(¤t);
- if(maxi < dif){
- maxi = dif;
- pos = z;
- }
- }
- if(x != 0 and y != 0){
- map.draw_image(x, y, elements[pos].surface, 0.1); // hack-y smooth bliting operation
- for(int z = 1; z < size*0.75 + 1; z++){
- map.draw_image(x+z, y+z, elements[pos].surface.get_crop(z, z, size-z, size-z), 0.18);
- }
- } else {
- map.draw_image(x, y, elements[pos].surface);
- }
- }
- }
- }
- map.save(argv[3]);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement