(self, iters=2, rand_search_radius=200,queue=None)
Optimize the NNF using PatchMatch Algorithm
        :param iters: number of iterations
        :param rand_search_radius: max radius to use in random search
        :return:
Optimize the NNF using PatchMatch Algorithm
        :param iters: number of iterations
        :param rand_search_radius: max radius to use in random search
        :return:
Optimize the NNF using PatchMatch Algorithm : param iters : number of iterations : param rand_search_radius : max radius to use in random search : return :
def propagate(self, iters=2, rand_search_radius=200,queue=None):
        """
        Optimize the NNF using PatchMatch Algorithm
        :param iters: number of iterations
        :param rand_search_radius: max radius to use in random search
        :return:
        """
        a_cols = self.A.shape[1]
        a_rows = self.A.shape[0]

        b_cols = self.B.shape[1]
        b_rows = self.B.shape[0]

        for it in range(iters):
            ystart = 0
            yend = a_rows
            ychange = 1
            xstart = 0
            xend = a_cols
            xchange = 1

            if it % 2 == 1:
                xstart = xend - 1
                xend = -1
                xchange = -1
                ystart = yend - 1
                yend = -1
                ychange = -1

            ay = ystart
            while ay != yend:

                ax = xstart
                while ax != xend:

                    xbest, ybest = self.nnf[ay, ax]
                    dbest = self.nnd[ay, ax]
                    if ax - xchange < a_cols and ax - xchange >= 0:
                        vp = self.nnf[ay, ax - xchange]
                        xp = vp[0] + xchange
                        yp = vp[1]
                        if xp < b_cols and xp >= 0:
                            val = self.cal_dist(ay, ax, yp, xp)
                            if val < dbest:
                                xbest, ybest, dbest = xp, yp, val

                    if abs(ay - ychange) < a_rows and ay - ychange >= 0:
                        vp = self.nnf[ay - ychange, ax]
                        xp = vp[0]
                        yp = vp[1] + ychange
                        if yp < b_rows and yp >= 0:
                            val = self.cal_dist(ay, ax, yp, xp)
                            if val < dbest:
                                xbest, ybest, dbest = xp, yp, val
                    if rand_search_radius is None:
                        rand_d = max(self.B.shape[0], self.B.shape[1])
                    else:
                        rand_d = rand_search_radius

                    while rand_d >= 1:
                        try:
                            xmin = max(xbest - rand_d, 0)
                            xmax = min(xbest + rand_d, b_cols)

                            ymin = max(ybest - rand_d, 0)
                            ymax = min(ybest + rand_d, b_rows)

                            if xmin > xmax:
                                rx = -np.random.randint(xmax, xmin)
                            if ymin > ymax:
                                ry = -np.random.randint(ymax, ymin)

                            if xmin <= xmax:
                                rx = np.random.randint(xmin, xmax)
                            if ymin <= ymax:
                                ry = np.random.randint(ymin, ymax)

                            val = self.cal_dist(ay, ax, ry, rx)
                            if val < dbest:
                                xbest, ybest, dbest = rx, ry, val

                        except Exception as e:
                            print(e)
                            print(rand_d)
                            print(xmin, xmax)
                            print(ymin, ymax)
                            print(xbest, ybest)
                            print(self.B.shape)

                        rand_d = rand_d // 2

                    self.nnf[ay, ax] = [xbest, ybest]
                    self.nnd[ay, ax] = dbest

                    ax += xchange
                ay += ychange
            print("Done iteration {}".format(it + 1))
        print("Done All Iterations")
        if queue:
            queue.put(self.nnf)
def propagate ( self , iters = 2 , rand_search_radius = 200 , queue = None ) : a_cols = self . A . shape [ 1 ] a_rows = self . A . shape [ 0 ] b_cols = self . B . shape [ 1 ] b_rows = self . B . shape [ 0 ] for it in range ( iters ) : ystart = 0 yend = a_rows ychange = 1 xstart = 0 xend = a_cols xchange = 1 if it % 2 == 1 : xstart = xend - 1 xend = - 1 xchange = - 1 ystart = yend - 1 yend = - 1 ychange = - 1 ay = ystart while ay != yend : ax = xstart while ax != xend : xbest , ybest = self . nnf [ ay , ax ] dbest = self . nnd [ ay , ax ] if ax - xchange < a_cols and ax - xchange >= 0 : vp = self . nnf [ ay , ax - xchange ] xp = vp [ 0 ] + xchange yp = vp [ 1 ] if xp < b_cols and xp >= 0 : val = self . cal_dist ( ay , ax , yp , xp ) if val < dbest : xbest , ybest , dbest = xp , yp , val if abs ( ay - ychange ) < a_rows and ay - ychange >= 0 : vp = self . nnf [ ay - ychange , ax ] xp = vp [ 0 ] yp = vp [ 1 ] + ychange if yp < b_rows and yp >= 0 : val = self . cal_dist ( ay , ax , yp , xp ) if val < dbest : xbest , ybest , dbest = xp , yp , val if rand_search_radius is None : rand_d = max ( self . B . shape [ 0 ] , self . B . shape [ 1 ] ) else : rand_d = rand_search_radius while rand_d >= 1 : try : xmin = max ( xbest - rand_d , 0 ) xmax = min ( xbest + rand_d , b_cols ) ymin = max ( ybest - rand_d , 0 ) ymax = min ( ybest + rand_d , b_rows ) if xmin > xmax : rx = - np . random . randint ( xmax , xmin ) if ymin > ymax : ry = - np . random . randint ( ymax , ymin ) if xmin <= xmax : rx = np . random . randint ( xmin , xmax ) if ymin <= ymax : ry = np . random . randint ( ymin , ymax ) val = self . cal_dist ( ay , ax , ry , rx ) if val < dbest : xbest , ybest , dbest = rx , ry , val except Exception as e : print ( e ) print ( rand_d ) print ( xmin , xmax ) print ( ymin , ymax ) print ( xbest , ybest ) print ( self . B . shape ) rand_d = rand_d // 2 self . nnf [ ay , ax ] = [ xbest , ybest ] self . nnd [ ay , ax ] = dbest ax += xchange ay += ychange print ( "Done iteration {}" . format ( it + 1 ) ) print ( "Done All Iterations" ) if queue : queue . put ( self . nnf )