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

Contour stencil interpolation. More...

#include "sset.h"
Include dependency graph for sinterp.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Typedefs

typedef struct sinterpstruct sinterp
 

Functions

sinterpNewSInterp (const sset *StencilSet, float RhoSigmaTangent, float RhoSigmaNormal)
 Create a new sinterp object. More...
 
void FreeSInterp (sinterp *SInterp)
 Free an sinterp object. More...
 
float * ComputeRhoSamples (const sinterp *SInterp, int ScaleFactor, int CenteredGrid)
 Precompute samples of $\Tilde\rho$ for an integer scale 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...
 
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 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...
 

Detailed Description

Contour stencil interpolation.

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

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.h.

Typedef Documentation

typedef struct sinterpstruct sinterp

Definition at line 23 of file sinterp.h.

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.

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.