示例#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
 // nearest neighbor search, using a given coherence set
 void nn_search(Img *destim, int di, int dj, const Kcoherence<K> &kset,
                int offx, int offy,
                unsigned &bestdiff,unsigned &bestidx)
 {
   for(int k=0;k<kset.n;k++) {
     int i,j;
     srcim->idx_to_ij(kset[k],i,j);
     i = srcim->wrapw(i+offx);
     j = srcim->wraph(j+offy);
     if(!srcwrap && (i<Nsize || i>=srcim->w-Nsize))
       continue;
     if(!srcwrap && (j<Nsize || j>=srcim->h-Nsize))
       continue;
     unsigned diff = neighbor_diff(destim, srcim, di,dj, i,j, Nsize);
     if(diff < bestdiff) {
       bestdiff = diff;
       bestidx = srcim->ij_to_idx(i,j);
     }
   }
 }