(self, img, patch_size=5)
return final
Reconstruct image using average voting.
        :param img: the image to reconstruct from. Numpy array of dim H*W*3
        :param patch_size: the patch size to use

        :return: reconstructed image
Reconstruct image using average voting.
        :param img: the image to reconstruct from. Numpy array of dim H*W*3
        :param patch_size: the patch size to use
Reconstruct image using average voting . : param img : the image to reconstruct from . Numpy array of dim H * W * 3 : param patch_size : the patch size to use
def reconstruct_avg(self, img, patch_size=5):
        """
        Reconstruct image using average voting.
        :param img: the image to reconstruct from. Numpy array of dim H*W*3
        :param patch_size: the patch size to use

        :return: reconstructed image
        """

        final = np.zeros_like(img)
        for i in range(img.shape[0]):
            for j in range(img.shape[1]):

                dx0 = dy0 = patch_size // 2
                dx1 = dy1 = patch_size // 2 + 1
                dx0 = min(j, dx0)
                dx1 = min(img.shape[0] - j, dx1)
                dy0 = min(i, dy0)
                dy1 = min(img.shape[1] - i, dy1)

                patch = self.nnf[i - dy0:i + dy1, j - dx0:j + dx1]

                lookups = np.zeros(shape=(patch.shape[0], patch.shape[1], img.shape[2]), dtype=np.float32)

                for ay in range(patch.shape[0]):
                    for ax in range(patch.shape[1]):
                        x, y = patch[ay, ax]
                        lookups[ay, ax] = img[y, x]

                if lookups.size > 0:
                    value = np.mean(lookups, axis=(0, 1))
                    final[i, j] = value

        return final
def reconstruct_avg ( self , img , patch_size = 5 ) : final = np . zeros_like ( img ) for i in range ( img . shape [ 0 ] ) : for j in range ( img . shape [ 1 ] ) : dx0 = dy0 = patch_size // 2 dx1 = dy1 = patch_size // 2 + 1 dx0 = min ( j , dx0 ) dx1 = min ( img . shape [ 0 ] - j , dx1 ) dy0 = min ( i , dy0 ) dy1 = min ( img . shape [ 1 ] - i , dy1 ) patch = self . nnf [ i - dy0 : i + dy1 , j - dx0 : j + dx1 ] lookups = np . zeros ( shape = ( patch . shape [ 0 ] , patch . shape [ 1 ] , img . shape [ 2 ] ) , dtype = np . float32 ) for ay in range ( patch . shape [ 0 ] ) : for ax in range ( patch . shape [ 1 ] ) : x , y = patch [ ay , ax ] lookups [ ay , ax ] = img [ y , x ] if lookups . size > 0 : value = np . mean ( lookups , axis = ( 0 , 1 ) ) final [ i , j ] = value return final