efros_freeman  0.1
Macros | Functions
patch_search.c File Reference
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <fftw3.h>
#include <assert.h>
#include <float.h>
#include "patch_search.h"
#include "random_number.h"
Include dependency graph for patch_search.c:

Go to the source code of this file.

Macros

#define MAX_DIST   FLT_MAX
#define MIN_DIST   1.0
#define MAX_INT   10000000
#define SMOOTH   1

Functions

static void cross_correlation_fft2_known (float *img1, fftwl_complex *fft2, long double *cross_corr, size_t nx, size_t ny)
 This function computes the cross-correlation between img1 and img2 using FFT, given the fft of img2 as input. The result is a long double image having the same size (already allocated).
void compute_input_patch_norms (Image src_im, long double *patch_normsH, long double *patch_normsV, long double *patch_normsL, int patch_sz, int overlap_sz)
 Computes the squared norms of each RGB patches of the input according to the 3 possible overlap regions.The computation is done in applying the cross-correlation between the extended mask and the sum over the 3 channels of the squares of the pixel values.
static void compute_distance_to_input_patches (Image src_im, Image out_im, Corner temp, int patch_sz, long double *src_patch_normsH, long double *src_patch_normsV, long double *src_patch_normsL, fftwl_complex *fft_srcR, fftwl_complex *fft_srcG, fftwl_complex *fft_srcB, Image_LD *distances)
 This function computes the squared distance between a given patch and all patches of another image. The squared distance is (implicitly) weighted by a binary mask on the patch domain.It does not appear because pixels that are not yet defined (outside the L-shape corner generally) are set to zero, so that multiplying by the binary mask does nàt change the patch.
static void pick_patch (Image_LD *distances, int h, int w, Corner *patch, float tol)
void patch_search (Image src_im, Image out_im, Corner temp, int patch_sz, long double *src_patch_normsH, long double *src_patch_normsV, long double *src_patch_normsL, fftwl_complex *fft_srcR, fftwl_complex *fft_srcG, fftwl_complex *fft_srcB, int h, int w, Corner *patch, float tol)
 This function executes the two steps of the patch search procedure:

Macro Definition Documentation

#define MAX_DIST   FLT_MAX

Definition at line 29 of file patch_search.c.

#define MAX_INT   10000000

Definition at line 31 of file patch_search.c.

#define MIN_DIST   1.0

Definition at line 30 of file patch_search.c.

#define SMOOTH   1

Definition at line 32 of file patch_search.c.

Function Documentation

static void compute_distance_to_input_patches ( Image  src_im,
Image  out_im,
Corner  temp,
int  patch_sz,
long double *  src_patch_normsH,
long double *  src_patch_normsV,
long double *  src_patch_normsL,
fftwl_complex *  fft_srcR,
fftwl_complex *  fft_srcG,
fftwl_complex *  fft_srcB,
Image_LD distances 
)
static

This function computes the squared distance between a given patch and all patches of another image. The squared distance is (implicitly) weighted by a binary mask on the patch domain.It does not appear because pixels that are not yet defined (outside the L-shape corner generally) are set to zero, so that multiplying by the binary mask does nàt change the patch.

Parameters
src_imThe input texture sample
out_imThe currently synthesized texture image (unknown pixels must be set to zero)
tempThe patch from the output image to compare with those in the texture sample (patch to synthesize)
patch_szThe pathc size
src_patch_normsH,src_patch_normsV,src_patch_normsLlong double arrays corresponding to the norm of input patches for the 3 possible overlap regions
fft_srcR,fft_srcG,fft_srcBlong double Fourier transforms of the 3 input channels
distancesImage of distances, WARNING: suppposed to be set to 0 at initialization (result)
Author
Lara Raad, Bruno Galerne
Date
2014/06/10

Definition at line 252 of file patch_search.c.

Here is the call graph for this function:

Here is the caller graph for this function:

void compute_input_patch_norms ( Image  src_im,
long double *  patch_normsH,
long double *  patch_normsV,
long double *  patch_normsL,
int  patch_sz,
int  overlap_sz 
)

Computes the squared norms of each RGB patches of the input according to the 3 possible overlap regions.The computation is done in applying the cross-correlation between the extended mask and the sum over the 3 channels of the squares of the pixel values.

Parameters
src_iminput RGB Image
patch_normsHlong double image for the horizontal overlap (must be allocated)
patch_normsVlong double image for the vertical overlap (must be allocated)
patch_normsLlong double image for the L-shape overlap (must be allocated)
patch_szpatch size
overlap_szsize of the overlap at the edge of the patch
Author
Lara Raad, Bruno Galerne

Definition at line 136 of file patch_search.c.

Here is the call graph for this function:

Here is the caller graph for this function:

static void cross_correlation_fft2_known ( float *  img1,
fftwl_complex *  fft2,
long double *  cross_corr,
size_t  nx,
size_t  ny 
)
static

This function computes the cross-correlation between img1 and img2 using FFT, given the fft of img2 as input. The result is a long double image having the same size (already allocated).

Convention for image sizes w_img = nx = width of image : Indexes x or j h_img = ny = height of image : Indexes y or i

Parameters
img1,img2,twopointers to float images
cross_corrimage of the cross-correlation
nx,nyimage sizes

Definition at line 56 of file patch_search.c.

Here is the caller graph for this function:

void patch_search ( Image  src_im,
Image  out_im,
Corner  temp,
int  patch_sz,
long double *  src_patch_normsH,
long double *  src_patch_normsV,
long double *  src_patch_normsL,
fftwl_complex *  fft_srcR,
fftwl_complex *  fft_srcG,
fftwl_complex *  fft_srcB,
int  h,
int  w,
Corner patch,
float  tol 
)

This function executes the two steps of the patch search procedure:

  1. Compute the distance of the current patch to all the admissible input patches
  2. Randomly pick one of the patch that is close to the minimal distance
    Parameters
    src_imThe input texture sample
    out_imThe currently synthesized texture image (unknown pixels must be set to zero)
    tempThe patch from the output image to compare with those in the texture sample (patch to synthesize)
    patch_szThe pathc size
    src_patch_normsH,src_patch_normsV,src_patch_normsLlong double arrays corresponding to the norm of input patches for the 3 possible overlap regions
    fft_srcR,fft_srcG,fft_srcBlong double Fourier transforms of the 3 input channels
    h,wsize of the domain of admissible patches
    patchThe position of the picked patch (Corner type)
    tolThe threshold used to select patches from the input image
    Date
    2014/06/10

Definition at line 413 of file patch_search.c.

Here is the call graph for this function:

Here is the caller graph for this function:

static void pick_patch ( Image_LD distances,
int  h,
int  w,
Corner patch,
float  tol 
)
static

This function picks a random patch within all the patches of the source image that verify dist(p, current) < dist_min*(1+tolerance) with dist_min the minimum distance between the current patch and the all the patches from the input image

Author
Lara Raad, Bruno Galerne
Parameters
distancesImage containing the distance between the current patch and the patch of source image (distance has the same size as the input image, but the bottom-right border must be discarded)
h,wsize of the domain of admissible patches
patchThe position of the picked patch (Corner type)
tolThe threshold used to select patches from the input
Date
2014/06/10

Definition at line 338 of file patch_search.c.

Here is the call graph for this function:

Here is the caller graph for this function: