Image Interpolation with Geometric Contour Stencils
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros
Data Structures | Macros | Typedefs | Functions
sinterp.c File Reference

Contour stencil interpolation. More...

#include <string.h>
#include "invmat.h"
#include "sinterp.h"
Include dependency graph for sinterp.c:

Go to the source code of this file.

Data Structures

struct  sinterpentry
 Data for interpolating with a contour stencil. More...
 
struct  sinterpstruct
 Data for interpolating with a contour stencil set. More...
 

Macros

#define NEIGHRADIUS   1
 The size of the synthesis neighborhood $\mathcal{N}$. More...
 
#define QUAD_RES   8
 Quadrature resolution to use for integrals. More...
 
#define TRIG_TABLE_SIZE   256
 Size of the trignometry tables used in RhoFast. More...
 
#define EXP_TABLE_SIZE   1024
 Size of the exponential table used in RhoFast. More...
 
#define WINDOWRADIUS   (1 + NEIGHRADIUS)
 Support radius of the window function $w(x)$. More...
 
#define NEIGHDIAMETER   (1 + 2*NEIGHRADIUS)
 Diameter of the neighborhood. More...
 
#define NEIGHCENTER   (NEIGHRADIUS + NEIGHRADIUS*NEIGHDIAMETER)
 Index of the neighborhood center. More...
 
#define NUMNEIGH   (NEIGHDIAMETER*NEIGHDIAMETER)
 Number of neighbors in the neighborhood, $|\mathcal{N}|$. More...
 

Typedefs

typedef struct sinterpstruct sinterptype
 Data for interpolating with a contour stencil set. More...
 

Functions

int InterpolateStencil (sinterp *SInterp, int S, const double *PsfSamples)
 Compute interpolation information for a stencil. More...
 
sinterpNewSInterp (const sset *StencilSet, float RhoSigmaTangent, float RhoSigmaNormal)
 Create a new sinterp object. More...
 
void FreeSInterp (sinterp *SInterp)
 Free an sinterp object. More...
 
int ArbitraryScale (float *Output, int OutputWidth, int OutputHeight, const int *Stencil, const sinterp *SInterp, const float *Input, int InputWidth, int InputHeight, float ScaleFactor, int CenteredGrid)
 Scale a color image by a possibly non-integer scale factor. More...
 
float * ComputeRhoSamples (const sinterp *SInterp, int ScaleFactor, int CenteredGrid)
 Precompute samples of $\Tilde\rho$ for an integer scale factor. More...
 
void IntegerScalePass (float *Output, const int *Stencil, const float *RhoSamples, const float *Input, int InputWidth, int InputHeight, int ScaleFactor, int CenteredGrid)
 Scale a color image by an integer factor. More...
 
int Prefilter (float *Filtered, const int *Stencil, const float *RhoSamples, const float *Input, int InputWidth, int InputHeight, int ScaleFactor, int CenteredGrid, float PsfSigma, int NumPasses)
 Prefilter a color image to improve deconvolution accuracy. More...
 
float DeconvResidual (float *Residual, const float *Coarse, int CoarseWidth, int CoarseHeight, const float *Interp, int InterpWidth, int InterpHeight, float ScaleFactor, int CenteredGrid, float PsfSigma)
 Compute deconvolution residual for prefiltering. More...
 

Detailed Description

Contour stencil interpolation.

Author
Pascal Getreuer getre.nosp@m.uer@.nosp@m.gmail.nosp@m..com

This file implements contour stencil interpolation for color images by integer and non-integer scale factors. The main routines are

Copyright (c) 2010-2011, Pascal Getreuer All rights reserved.

This program is free software: you can use, modify and/or redistribute it under the terms of the simplified BSD License. You should have received a copy of this license along this program. If not, see http://www.opensource.org/licenses/bsd-license.html.

Definition in file sinterp.c.

Macro Definition Documentation

#define EXP_TABLE_SIZE   1024

Size of the exponential table used in RhoFast.

Definition at line 35 of file sinterp.c.

#define NEIGHCENTER   (NEIGHRADIUS + NEIGHRADIUS*NEIGHDIAMETER)

Index of the neighborhood center.

Definition at line 43 of file sinterp.c.

#define NEIGHDIAMETER   (1 + 2*NEIGHRADIUS)

Diameter of the neighborhood.

Definition at line 41 of file sinterp.c.

#define NEIGHRADIUS   1

The size of the synthesis neighborhood $\mathcal{N}$.

Definition at line 29 of file sinterp.c.

#define NUMNEIGH   (NEIGHDIAMETER*NEIGHDIAMETER)

Number of neighbors in the neighborhood, $|\mathcal{N}|$.

Definition at line 45 of file sinterp.c.

#define QUAD_RES   8

Quadrature resolution to use for integrals.

Definition at line 31 of file sinterp.c.

#define TRIG_TABLE_SIZE   256

Size of the trignometry tables used in RhoFast.

Definition at line 33 of file sinterp.c.

#define WINDOWRADIUS   (1 + NEIGHRADIUS)

Support radius of the window function $w(x)$.

Definition at line 39 of file sinterp.c.

Typedef Documentation

typedef struct sinterpstruct sinterptype

Data for interpolating with a contour stencil set.

Function Documentation

int ArbitraryScale ( float *  Output,
int  OutputWidth,
int  OutputHeight,
const int *  Stencil,
const sinterp SInterp,
const float *  Input,
int  InputWidth,
int  InputHeight,
float  ScaleFactor,
int  CenteredGrid 
)

Scale a color image by a possibly non-integer scale factor.

Parameters
Outputthe output image
OutputWidth,OutputHeightdimensions of the output image
Stencilthe best-fitting stencils $\mathcal{S}^\star$
SInterpstencil interpolation data
Inputthe input image in row-major interleaved order
InputWidth,InputHeightdimensions of the input image
ScaleFactorscale factor between input and output images
CenteredGriduse centered grid if nonzero or top-left otherwise
Returns
1 on success, 0 on failure

This routine implements for a possibly non-integer scale factor the interpolation formula

\[ u(x) = \sum_{k \in \mathbb{Z}^2} w(x-k) \Bigl[ v_k + \sum_{m\in\mathcal{N}} c_m^k \, \rho_{\mathcal{S}^\star(k)}^m(x - m - k) \Bigr], \]

where the coefficients $c_m^k$ are computed as

\[ c_m^k = \sum_{n\in\mathcal{N}} (A_{\mathcal{S}^\star(k)}^{-1})_{m,n} (v_{k+n} - v_k), \quad m \in \mathcal{N}. \]

For more accurate deconvolution, Prefilter() should be called first to prefilter the input image.

In the code, the mathematical meanings of the variables are as follows:

  • Output: $u$
  • Input: $v$
  • Coeff[3*(NUMNEIGH + 1)*k + m]: $c_m^k$
  • SInterp->StencilInterp[S].Matrix: $A_{\mathcal{S}}^{-1}$
  • WindowWeight: $w(x-k)$

For computational efficiency, RhoFast() is used to evaluate $\rho$ instead of Rho(), as $\rho$ needs to be evaluated here many times.

Definition at line 400 of file sinterp.c.

float* ComputeRhoSamples ( const sinterp SInterp,
int  ScaleFactor,
int  CenteredGrid 
)

Precompute samples of $\Tilde\rho$ for an integer scale factor.

Parameters
SInterpstencil interpolation data
ScaleFactorthe integer scale factor
CenteredGriduse centered grid if nonzero or top-left otherwise
Returns
pointer to samples, or NULL on failure

This routine evaluates samples of

\[ \Tilde{\rho}_{\mathcal{S}}^n(x) = w(x) \sum_{m\in\mathcal{N}} (A_{\mathcal{S}}^{-1})_{m,n} \, \rho_{\mathcal{S}}^m(x-m). \]

at locations on a fine grid with step size 1/ScaleFactor, where ScaleFactor is an integer. This precomputation significantly accelerates image scaling by an integer factor.

The samples are computed for every stencil $\mathcal{S}\in\Sigma$ for every neighbor $m\in\mathcal{N}$ over a square window of size SupportWidth by SupportWidth, where SupportWidth = 2*WINDOWRADIUS*ScaleFactor or this value minus 1, depending on the choice of grid and the oddness of ScaleFactor.

Definition at line 566 of file sinterp.c.

float DeconvResidual ( float *  Residual,
const float *  Coarse,
int  CoarseWidth,
int  CoarseHeight,
const float *  Interp,
int  InterpWidth,
int  InterpHeight,
float  ScaleFactor,
int  CenteredGrid,
float  PsfSigma 
)

Compute deconvolution residual for prefiltering.

Parameters
Residualthe residual image
Coarsethe coarse image
CoarseWidth,CoarseHeightdimensions of the coarse image
Interpthe interpolated image
InterpWidth,InterpHeightdimensions of the interpolated image
ScaleFactorscale factor between coarse and interpolated images
CenteredGriduse centered grid if nonzero or top-left otherwise
PsfSigmaGaussian PSF standard deviation in units of input pixels

This routine computes the deconvolution residual

\[ r = v - \operatorname{sample}(h * u), \]

where v is the coarse image and u is the interpolation. This residual is used in the iterative refinement procedure implemented in Prefilter().

Definition at line 880 of file sinterp.c.

void FreeSInterp ( sinterp SInterp)

Free an sinterp object.

Parameters
SInterpthe sinterp to free

Frees all memory associated with SInterp.

Definition at line 340 of file sinterp.c.

void IntegerScalePass ( float *  Output,
const int *  Stencil,
const float *  RhoSamples,
const float *  Input,
int  InputWidth,
int  InputHeight,
int  ScaleFactor,
int  CenteredGrid 
)

Scale a color image by an integer factor.

Parameters
Outputthe output image
Stencilthe best-fitting stencils $\mathcal{S}^\star$
RhoSamplesprecomputed samples of $\Tilde\rho$
Inputthe input image in row-major interleaved order
InputWidth,InputHeightdimensions of the input image
ScaleFactorscale factor between input and output images
CenteredGriduse centered grid if nonzero or top-left otherwise

This routine implements for a integer scale factor the interpolation formula

\[ u(x) = \sum_{k \in \mathbb{Z}^2} \biggl[ w(x-k) v_k + \sum_{n \in\mathcal{N}\backslash\{0\}} (v_{k+n} - v_k) \, \Tilde{\rho}_{\mathcal{S}^\star(k)}^n(x-k) \biggr]. \]

Definition at line 660 of file sinterp.c.

int InterpolateStencil ( sinterp SInterp,
int  S,
const double *  PsfSamples 
)

Compute interpolation information for a stencil.

Parameters
SInterpstencil set interpolation data
Sindex of the stencil to interpolate
PsfSamplesprecomputed samples of the PSF
Returns
1 on success, 0 on failure

The orientation and anisotropy of the $\rho_\mathcal{S}^n$ synthesis functions are computed,

\[\begin{aligned} \theta_\mathcal{S}^n &= \angle \int_{[-\frac{1}{2},+\frac{1}{2}]^2} \nabla\varphi_\mathcal{S}^\perp \bigl(x - n) \, dx, \\ \mu_\mathcal{S} &= \min_{n\in \mathcal{N}}\, \Bigl\lvert\int_{[-\frac{1}{2},+\frac{1}{2}]^2} \nabla\varphi_\mathcal{S} \bigl(x - n) \, dx\Bigr\rvert. \end{aligned}\]

The interpolation matrix

\[ (A_\mathcal{S})_{m,n} = (h * \rho^n_\mathcal{S})(m - n), \quad m,n\in\mathcal{N} \]

is computed and inverted with InvertMatrix().

Definition at line 170 of file sinterp.c.

sinterp* NewSInterp ( const sset StencilSet,
float  RhoSigmaTangent,
float  RhoSigmaNormal 
)

Create a new sinterp object.

Parameters
StencilSetstencil set $\Sigma$ to perform interpolation with
RhoSigmaTangent,RhoSigmaNormalparameters for Rho
Returns
an sinterp*, or NULL on failure

Given a stencil set $\Sigma$, this routine performs the necessary precomputations for interpolation and stores it in an sinterp data structure. Each stencil $\mathcal{S}\in\Sigma$ is processed with InterpolateStencil() to create an sinterpentry.

Definition at line 298 of file sinterp.c.

int Prefilter ( float *  Filtered,
const int *  Stencil,
const float *  RhoSamples,
const float *  Input,
int  InputWidth,
int  InputHeight,
int  ScaleFactor,
int  CenteredGrid,
float  PsfSigma,
int  NumPasses 
)

Prefilter a color image to improve deconvolution accuracy.

Parameters
Filteredthe prefiltered image
Stencilthe best-fitting stencils $\mathcal{S}^\star$
RhoSamplesprecomputed samples of $\Tilde\rho$
Inputthe input image in row-major interleaved order
InputWidth,InputHeightdimensions of the input image
ScaleFactorscale factor between input and output images
CenteredGriduse centered grid if nonzero or top-left otherwise
PsfSigmaGaussian PSF standard deviation in units of input pixels
NumPassesnumber of passes of iterative refinement to perform

This routine performs the iterative refinement prefiltering

\[ v^0 = v, \quad v^{i+1} = v^i + \bigl(v - \operatorname{sample}(h*\mathcal{R}v^i)\bigr). \]

Interpolation with a prefiltered image improves the resulting deconvolution accuracy. Interpolation is performed using the prefiltered image as input with either IntegerScalePass() for an integer scale factor or by ArbitraryScale() for a non-integer scale factor.

Prefiltering is implemented with IntegerScalePass() to perform the interpolations $\mathcal{R}v^i$ and DeconvResidual() to compute the deconvolution residuals $v - \operatorname{sample}(h*\mathcal{R}v^i)$.

Definition at line 802 of file sinterp.c.