Image Demosaicking with Contour Stencils
|
Contour stencils weighted L1 demosaicing. More...
#include <math.h>
#include <string.h>
#include "basic.h"
#include "conv.h"
#include "inv3x3.h"
#include "dmbilinear.h"
#include "mstencils.h"
#include "dmcswl1.h"
Go to the source code of this file.
Macros | |
#define | GAMMA1 4 |
Penalty term weight to enforce . More... | |
#define | GAMMA2 256 |
Penalty term weight to enforce observation constraint. More... | |
#define | NUMNEIGH 8 |
How many adjacent neighbors a node has. More... | |
#define | NUMORIENTATIONS 8 |
How many distinct orientations are detected. More... | |
#define | MU (GAMMA2/(2*NUMNEIGH*GAMMA1)) |
mu = gamma_2 / (2 NUMNEIGH gamma_1) More... | |
Functions | |
void | DShrink (float(*d)[NUMNEIGH][3], float(*dtilde)[NUMNEIGH][3], const float *Image, float(*Weight)[NUMNEIGH], int Width, int Height, float Alpha) |
Solves the d-subproblem. More... | |
float | UGaussSeidel (float *Image, float *b, float(*dtilde)[NUMNEIGH][3], const float *Mosaic, int Width, int Height, int RedX, int RedY) |
Solves the u-subproblem. More... | |
int | ConstructGraph (float(*Weight)[NUMNEIGH], const float *Mosaic, int Width, int Height, int RedX, int RedY, float Epsilon, float Sigma) |
Construct the weighted graph according to contour orientations. More... | |
void | CopyCfaValues (float *Image, const float *Mosaic, int Width, int Height, int RedX, int RedY) |
Copy image components that are known from the input mosaiced data. More... | |
float | EvaluateCSWL1Energy (const float *Image, int Width, int Height, int RedX, int RedY, float Alpha, float(*Weight)[NUMNEIGH], const float *Mosaic) |
Evaluate the contour stencils demosaicking energy function. More... | |
int | CSWL1Demosaic (float *Image, int Width, int Height, int RedX, int RedY, float Alpha, float Epsilon, float Sigma, float Tol, int MaxIter, int ShowEnergy) |
Contour stencils weighted L1 demosaicing. More... | |
Contour stencils weighted L1 demosaicing.
This file implements the image demosaicing method as described in IPOL article "Image Demosaicking with Contour Stencils." The main computation is in routine CSWL1Demosaic.
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 dmcswl1.c.
#define GAMMA2 256 |
#define NUMNEIGH 8 |
#define NUMORIENTATIONS 8 |
int ConstructGraph | ( | float(*) | Weight[NUMNEIGH], |
const float * | Mosaic, | ||
int | Width, | ||
int | Height, | ||
int | RedX, | ||
int | RedY, | ||
float | Epsilon, | ||
float | Sigma | ||
) |
Construct the weighted graph according to contour orientations.
Weight | the edge weights of the graph |
Mosaic | the input mosaiced image |
Width,Height | the image dimensions |
RedX,RedY | the coordinates of the upper-leftmost red pixel |
Epsilon | edge weight for weak links in the graph |
Sigma | graph filtering parameter |
This function constructs the weighted graph that will be used for the graph regularization in the contour stencil demosaicking.
Each interior pixel has eight neighbors. The neighborhood is enumerated in counter-clockwise order beginning with the right adjacent neighbor.
3 2 1 `. | .` `. | .` 4 -----+----- 0 .` | `. .` | `. 5 6 7
The graph edge weights over this neighborhood for different local contour orientations are stored in NeighWeights.
Definition at line 545 of file dmcswl1.c.
void CopyCfaValues | ( | float * | Image, |
const float * | Mosaic, | ||
int | Width, | ||
int | Height, | ||
int | RedX, | ||
int | RedY | ||
) |
Copy image components that are known from the input mosaiced data.
Image | the input RGB image in planar row-major order |
Mosaic | the input mosaiced image |
Width,Height | the image dimensions |
RedX,RedY | the coordinates of the upper-leftmost red pixel |
This function is used to set the components of Image equal to the values that are known from the input mosaiced image,
Definition at line 624 of file dmcswl1.c.
int CSWL1Demosaic | ( | float * | Image, |
int | Width, | ||
int | Height, | ||
int | RedX, | ||
int | RedY, | ||
float | Alpha, | ||
float | Epsilon, | ||
float | Sigma, | ||
float | Tol, | ||
int | MaxIter, | ||
int | ShowEnergy | ||
) |
Contour stencils weighted L1 demosaicing.
Image | the input RGB image in planar row-major order |
Width,Height | the image dimensions |
RedX,RedY | the coordinates of the upper-leftmost red pixel |
Alpha | weight on the chromatic term |
Epsilon | edge weight for weak links in the graph |
Sigma | graph filtering parameter |
Tol | stopping tolerance |
MaxIter | maximum number of iterations |
ShowEnergy | if nonzero, display the energy value after each iteration |
This is the main computation routine for contour stencils demosaicing. It solves the minimization
by Bregman iteration. This is done by alternatingly solving the D-subproblem with DShrink and the U-subproblem with UGaussSeidel.
Definition at line 750 of file dmcswl1.c.
void DShrink | ( | float(*) | d[NUMNEIGH][3], |
float(*) | dtilde[NUMNEIGH][3], | ||
const float * | Image, | ||
float(*) | Weight[NUMNEIGH], | ||
int | Width, | ||
int | Height, | ||
float | Alpha | ||
) |
Solves the d-subproblem.
d | the previous solution of d, updated by this routine |
dtilde | the previous dtilde, updated by this routine |
Image | the current solution of the demosaiced image |
Weight | the edge weights of the graph |
Width,Height | the image dimensions |
Alpha | weight on the chromatic term |
The d variable subproblem is
where is the color transform matrix, and denote the graph weights between pixels and . The problem decouples over m and also decouples between the luminosity channel L and the chromatic channels C1 and C2. This leads to subproblems of the form
The minimizer of this problem satisfies
We can approximate the solution by fixed point iteration,
where is computed using on the solution from the previous Bregman iteration or, if it is the first iteration or the previous solution was 0, as .
The update of is computed as
Definition at line 259 of file dmcswl1.c.
float EvaluateCSWL1Energy | ( | const float * | Image, |
int | Width, | ||
int | Height, | ||
int | RedX, | ||
int | RedY, | ||
float | Alpha, | ||
float(*) | Weight[NUMNEIGH], | ||
const float * | Mosaic | ||
) |
Evaluate the contour stencils demosaicking energy function.
Image | the input RGB image in planar row-major order |
Width,Height | the image dimensions |
RedX,RedY | the coordinates of the upper-leftmost red pixel |
Alpha | weight on the chromatic term |
Weight | the edge weights of the graph |
Mosaic | the input mosaiced image |
This routine evaluates the energy function to be minimized by the contour stencil weighted-L1 demosaicking,
where in this computation, u is forced to agree with the mosaiced input data on the CFA, .
When the CSWL1Demosaic() is called with ShowEnergy set to a nonzero value, the energy value is displayed after each Bregman iteration. This can be used to check the convergence of the minimization.
Definition at line 670 of file dmcswl1.c.
float UGaussSeidel | ( | float * | Image, |
float * | b, | ||
float(*) | dtilde[NUMNEIGH][3], | ||
const float * | Mosaic, | ||
int | Width, | ||
int | Height, | ||
int | RedX, | ||
int | RedY | ||
) |
Solves the u-subproblem.
Image | the demosaiced image solution (u), updated by this routine |
b | the Bregman auxiliary variable, updated by this routine |
dtilde | current dtilde |
Mosaic | the input mosaiced image |
Width,Height | the image dimensions |
RedX,RedY | the coordinates of the upper-leftmost red pixel |
The current demosaicking solution, Image (u), is updated by approximately solving the u subproblem using Gauss-Seidel. The solution satisfies
where is the color transform matrix, is the input mosaiced image (Mosaic
), and is respectively at red, green, and blue locations. Inverses of the matrices
are precomputed.
Definition at line 384 of file dmcswl1.c.