Efros-Leung
Exemplar-basedtexturesynthesis(Efros-Leung)
Functions
inc/synthesis.h File Reference

Sub-functions for texture synthesis. More...

#include <stdlib.h>
#include "pca.h"
#include "mt.h"

Go to the source code of this file.

Functions

int compare_pixel (const void *a, const void *b)
 Comparison between pixel's number of neighbors.
int compare_cand_dist (const void *a, const void *b)
 Comparison between candidates' distances.
int known_neighbours (ImageF w, unsigned char *mask, Pixel current, int i, int t, int larg, int haut, unsigned short *mask_neighb, float *curr_patch)
 Extract the neighbors' mask and values at a given pixel.
int known_neighboursRL (unsigned char *mask, Pixel current, int i, int t, int larg, unsigned short *mask_neighb)
 Extract neighbors on the centered column of a patch.
int known_neighboursUD (unsigned char *mask, Pixel current, int i, int t, int larg, unsigned short *mask_neighb)
 Extract neighbors on the centered row of a patch.
int find_candidatesU (ImageF v, float *weights_pca, float *dictionary, Pixel current, int i, int totalPatches, unsigned short *mask_neighb, int total_neighb, int t, float *WU, float *mean, int m, int n, float tolerance, Cand_dist cand_list)
 Get the set of candidates for a given pixel to be filled.
int find_candidatesD (ImageF v, float *weights_pca, float *dictionary, Pixel current, int i, int totalPatches, unsigned short *mask_neighb, int total_neighb, int t, float *WU, float *mean, int m, int n, float tolerance, Cand_dist cand_list)
 Get the set of candidates for a given pixel to be filled.
int find_candidatesR (ImageF v, float *weights_pca, float *dictionary, Pixel current, int i, int totalPatches, unsigned short *mask_neighb, int total_neighb, int t, float *WU, float *mean, int m, int n, float tolerance, Cand_dist cand_list)
 Get the set of candidates for a given pixel to be filled.
int find_candidatesL (ImageF v, float *weights_pca, float *dictionary, Pixel current, int i, int totalPatches, unsigned short *mask_neighb, int total_neighb, int t, float *WU, float *mean, int m, int n, float tolerance, Cand_dist cand_list)
 Get the set of candidates for a given pixel to be filled.
int find_candidates (float *patch_list, float *patch_list_mask, float *curr_patch, int totalPatchs, int t, unsigned short *mask_neighb, int voisins_updated, float tolerance, Cand_dist cand_list, float *weights)
 Get the set of candidates for a given pixel to be filled.
float * load_patch_list (ImageF w, int t)
 Load the patch of an image into an array.
long int generate_current_list (int cote, int coin, Pixel current, unsigned char *mask, int t, int larg, int haut)
 Generate the current list of pixels to be filled.
long int random_choose (Cand_dist cand_list, long int size_list)
 Randomly choose an element from a list.
void retrieve_coords (int p, int larg, int tx, int ty, int *x, int *y)
 Retrieve the coordinates in the example image from a patch index.
int compute_distances_pca (int totalPatches, int t, float tolerance, int total_neighb, unsigned short *mask_neighb, float *patch, float *patch_pca, float *dictionary, int n, Cand_dist cand_list, float *radius_out)
 Compute (using the PCA) the distances between a patch and all the others ones.
int compute_distances (int totalPatchs, int t, int voisins_updated, unsigned short *mask_neighb, float *patch_list, float *patch_list_mask, float *curr_patch, float tolerance, Cand_dist cand_list, float *radius_out, float *weights)
 Compute (without PCA) the distances between a patch and all the others ones.
float * gaussian_weights (int patchSize, int t)
 Pre-compute Gaussian weights.
float * gaussian_weights_pca (int patchSize, int t)
 Pre-compute the root square of Gaussian weights.
float * uniform_weights_pca (int patchSize)
 Pre-compute uniform weights.

Detailed Description

Sub-functions for texture synthesis.

Author:
Cecilia Aguerrebere

Function Documentation

int compare_cand_dist ( const void *  a,
const void *  b 
)

Comparison between candidates' distances.

This function is used by qsort to sort a list of candidates.

Parameters:
apointer to a candidate
bpointer to another candidate
Returns:
a negative, zero, or positive value respectively if the distance of a is smaller than, equal to, or greater than the distance of b.
int compare_pixel ( const void *  a,
const void *  b 
)

Comparison between pixel's number of neighbors.

This function is used by qsort to sort a list of pixel in decreasing order of known neighbors.

Parameters:
apointer to a pixel
bpointer to another pixel
Returns:
a negative, zero, or positive value respectively if the number of known neighbors is more, the same, or less for a than for b.
int compute_distances ( int  totalPatchs,
int  t,
int  neighbs_updated,
unsigned short *  mask_neighb,
float *  patch_list,
float *  patch_list_mask,
float *  curr_patch,
float  tolerance,
Cand_dist  cand_list,
float *  radius_out,
float *  weights 
)

Compute (without PCA) the distances between a patch and all the others ones.

Parameters:
totalPatchsnumber of patches in the dictionary
thalf-size of the patch
neighbs_updatednumber of known neighbors
mask_neighbmask of known neighbors
patch_listthe list of patches
curr_patchthe current patch
tolerancevalue of $(1+\varepsilon)^2$
cand_listoutput for the distances
radius_outthreshold for distance (computation stops if reached)
weightsweights used for the distance between patches
int compute_distances_pca ( int  totalPatches,
int  t,
float  tolerance,
int  total_neighb,
unsigned short *  mask_neighb,
float *  patch,
float *  patch_pca,
float *  dictionary,
int  n,
Cand_dist  cand_list,
float *  radius_out 
)

Compute (using the PCA) the distances between a patch and all the others ones.

Each considered element has two parts: the first part corresponds to the central part of the patch (central column or central row) of size (2t + 1); the second part corresponds to the PCA projection of one of four patch subregions (up, down, right or left), it is of size equal to the PCA chosen dimensions n.

Parameters:
totalPatchesnumber of patches in the dictionary
thalf-size of the patch
tolerancevalue of $(1+\varepsilon)^2$
total_neighbnumber of known neighbors
mask_neighbmask of known neighbors
patch
patch_pcathe current patch coordinates in the PCA basis
dictionarydictionary of patches in the PCA basis
nnumber of dimension kept by PCA
cand_listoutput for the distances
radius_outthreshold for distance (computation stops if reached)
Todo:
uncommented parameter patch
int find_candidates ( float *  patch_list,
float *  patch_list_mask,
float *  curr_patch,
int  totalPatchs,
int  t,
unsigned short *  mask_neighb,
int  neighbs_updated,
float  tolerance,
Cand_dist  cand_list,
float *  weights 
)

Get the set of candidates for a given pixel to be filled.

Don't use the PCA. The dictionary is simply the patch list.

See also:
find_candidatesU
int find_candidatesD ( ImageF  v,
float *  weights_pca,
float *  dictionary,
Pixel  current,
int  i,
int  totalPatches,
unsigned short *  mask_neighb,
int  total_neighb,
int  t,
float *  WU,
float *  mean,
int  m,
int  n,
float  tolerance,
Cand_dist  cand_list 
)

Get the set of candidates for a given pixel to be filled.

Only for a patch with a known down part.

See also:
find_candidatesU
int find_candidatesL ( ImageF  v,
float *  weights_pca,
float *  dictionary,
Pixel  current,
int  i,
int  totalPatches,
unsigned short *  mask_neighb,
int  total_neighb,
int  t,
float *  WU,
float *  mean,
int  m,
int  n,
float  tolerance,
Cand_dist  cand_list 
)

Get the set of candidates for a given pixel to be filled.

Only for a patch with a known left part.

See also:
find_candidatesU
int find_candidatesR ( ImageF  v,
float *  weights_pca,
float *  dictionary,
Pixel  current,
int  i,
int  totalPatches,
unsigned short *  mask_neighb,
int  total_neighb,
int  t,
float *  WU,
float *  mean,
int  m,
int  n,
float  tolerance,
Cand_dist  cand_list 
)

Get the set of candidates for a given pixel to be filled.

Only for a patch with a known right part.

See also:
find_candidatesU
int find_candidatesU ( ImageF  v,
float *  weights_pca,
float *  dictionary,
Pixel  current,
int  i,
int  totalPatches,
unsigned short *  mask_neighb,
int  total_neighb,
int  t,
float *  WU,
float *  mean,
int  m,
int  n,
float  tolerance,
Cand_dist  cand_list 
)

Get the set of candidates for a given pixel to be filled.

Only for a patch with a known upper-part.

The candidate pixels $q$ for a pixel $p$ is the set:

\[\Omega_p=\left\{q\;\middle|\;d(p,q)\leq (1+\varepsilon)\cdot d_{min}(p)\right\}\]

where

\[d_{min}(p)=\min_q\left\{d(p,q)\right\}\]

and the $l^2$ distance $d(p,q)$ is computed on the known part of the patches centered at $p$ and $q$.

Parameters:
vthe example image
weights_pcaweights used for the distance between patches
dictionarydictionary of patches extracted from v
currentlist of pixels
iindex of the current pixel $p$ in current list
totalPatchesnumber of patches in the dictionary
mask_neighbmask of the known pixels in the current patch
total_neighbnumber of known neighbors
thalf-size of the patch
meanmean vector for patches dictionary
WUprojection axis for the patches
mdimension of the patch
nnumber of dimension kept by PCA
tolerancevalue of $(1+\varepsilon)^2$
cand_listutput for the candidates (sorted from closest)
Returns:
the number of candidates
float* gaussian_weights ( int  patchSize,
int  t 
)

Pre-compute Gaussian weights.

Parameters:
patchSizesize of the patch
thalf-size of the patch (should have patchSize = 2t+1)
Returns:
array of Gaussian weights, length = patchSize x patchSize
float* gaussian_weights_pca ( int  patchSize,
int  t 
)

Pre-compute the root square of Gaussian weights.

Parameters:
patchSizesize of the patch
thalf-size of the patch (should have patchSize = 2t+1)
Returns:
array of root square of Gaussian weights, length = patchSize x patchSize
long int generate_current_list ( int  side,
int  corner,
Pixel  current,
unsigned char *  mask,
int  t,
int  ncols,
int  nrows 
)

Generate the current list of pixels to be filled.

Parameters:
side
corner
currentoutput list of pixels
maskmask of already filled pixels
thalf-size of patches
ncolsnumber of columns (dx) for mask
nrowsnumber of rows (dy) for mask
Todo:
argument side and corner: still undocumented
Returns:
size of the list
int known_neighbours ( ImageF  v,
unsigned char *  mask,
Pixel  current,
int  i,
int  t,
int  ncols,
int  nrows,
unsigned short *  mask_neighb,
float *  curr_patch 
)

Extract the neighbors' mask and values at a given pixel.

Parameters:
vthe image
maskthe mask for the partially synthesized image v
currentlist of pixels
iindex of the pixel in the current list
tsize of the half-patch
ncolsnumber of columns (dx) v
nrowsnumber of rows (dy) in v
mask_neighboutput array for the neighbors' mask
curr_patchoutput array for the neighbors' values
Returns:
number of known neighbors
int known_neighboursRL ( unsigned char *  mask,
Pixel  current,
int  i,
int  t,
int  ncols,
unsigned short *  mask_neighb 
)

Extract neighbors on the centered column of a patch.

See also:
known_neighbours
int known_neighboursUD ( unsigned char *  mask,
Pixel  current,
int  i,
int  t,
int  ncols,
unsigned short *  mask_neighb 
)

Extract neighbors on the centered row of a patch.

See also:
known_neighbours
float* load_patch_list ( ImageF  w,
int  t 
)

Load the patch of an image into an array.

Facilitate posterior access.

Parameters:
wimage
thalf-size of patches
Returns:
the patches array extracted from the image
long int random_choose ( Cand_dist  cand_list,
long int  size_list 
)

Randomly choose an element from a list.

The choice is uniform.

Parameters:
cand_lista list of candidates
size_listthe number of candidates
Returns:
the index of a random candidate
void retrieve_coords ( int  p,
int  ncols,
int  tx,
int  ty,
int *  x,
int *  y 
)

Retrieve the coordinates in the example image from a patch index.

Parameters:
ppatch index
ncolsnumber of columns (dx) in the image
thalf-size of the patch
xoutput for x position in the image
youtput for y position in the image
float* uniform_weights_pca ( int  patchSize)

Pre-compute uniform weights.

Parameters:
patchSizesize of the patch
Returns:
array of uniform weights, length = patchSize x patchSize
 All Classes Files Functions Variables