示例#1
0
  unsigned mstep(int offset) {
    unsigned E=0;
    bool changed = false;
    for(int j=offset;j<dstim->h;j++)
      for(int i=offset;i<dstim->w;i++) {
        // search k set of all neighborhood pixels to find best matching
        // neighborhood between src and dest(i,j)
        unsigned bestdiff = ~0, bestidx = 0;
        for(int nj=-Nsize;nj<=Nsize;nj++)
          for(int ni=-Nsize;ni<=Nsize;ni++) {
            int x=dstim->wrapw(i+ni), y=dstim->wraph(j+nj);
            nn_search(dstim, i,j, srck[dstz->p(x,y)], -ni,-nj, bestdiff, bestidx);
          }

        E += bestdiff;
        if(dstz->p(i,j) != bestidx) {
          changed = true;
          dstz->p(i,j) = bestidx;
        }
        dstim->p(i,j) = srcim->p(bestidx);
      }
    if(!changed)
      return 0;
    return E;
  }
示例#2
0
 void init(int offset) {
   for(int j=offset;j<dstim->h;j++)
     for(int i=offset;i<dstim->w;i++) {
       int x = rand()%srcim->w;
       int y = rand()%srcim->h;
       dstz->p(i,j) = srcim->ij_to_idx(x,y);
       x = rand()%srcim->w;
       y = rand()%srcim->h;
       //dsto->p(i,j) = srcim->ij_to_idx(x,y);
       dstim->p(i,j) = srcim->p(x,y);
     }
 }
示例#3
0
  unsigned estep(int offset) {
    unsigned E=0;
    for(int j=offset;j<dstim->h;j++)
      for(int i=offset;i<dstim->w;i++) {
        unsigned bestdiff = ~0, bestidx = 0;

        // x,y are the target patch (in the z array)
        //int x,y; srcim->idx_to_ij(dstz->p(i,j),x,y);

        // we search our candidate set k from the pixel's current source
        nn_search(dstim, i,j, srck[dstz->p(i,j)], 0,0, bestdiff, bestidx);
        E += bestdiff;
        dstim->p(i,j) = srcim->p(bestidx);
        dstz->p(i,j) = bestidx;
      }
    return E;
  }