Automatic Color Enhancement
Functions
ace.c File Reference

ACE automatic color enhancement. More...

#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <fftw3.h>

Go to the source code of this file.

Functions

int ace_enhance_image_interp (float *u, const float *f, int width, int height, float alpha, const char *omega_string, int num_levels)
 ACE automatic color enhancement using level interpolation. More...
 
int ace_enhance_image_poly (float *u, const float *f, int width, int height, float alpha, const char *omega_string, int degree)
 ACE automatic color enhancement using a polynomial slope function. More...
 
static int compute_omega_trans (float *omega_trans, float *omega, int width, int height, const char *omega_string)
 Compute the FFT of omega(x,y) More...
 
static void get_min_max (float *min_ptr, float *max_ptr, const float *data, size_t num_samples)
 Find the min and max value of an array. More...
 
static void int_pow (float *dest, const float *src, size_t num_samples, int m)
 Evaluate integer power, hardcoded for degrees 1 to 11. More...
 
static void stretch (float *image, long num_pixels)
 Stetch image to [0,1]. More...
 
static void convolve (float *blurred_trans, const float *omega_trans, long num_pixels, fftwf_plan forward_plan, fftwf_plan inverse_plan)
 FFT-based convolution.
 
static int alloc_buffers_and_plans (float ***buffers_ptr, fftwf_plan(**plans_ptr)[2], int width, int height, int num_buffers)
 Allocate buffers and FFTW plans for DCT transforms.
 
static void free_buffers_and_plans (float **buffers, fftwf_plan(*plans)[2], int num_buffers)
 Free resources allocated by alloc_buffers_and_plans()
 
static double binom_coeff (int m, int n)
 Compute binomial coefficient for small m and n. More...
 
static double factorial (int n)
 Compute small factorial. More...
 

Detailed Description

ACE automatic color enhancement.

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

Copyright (c) 2012, Pascal Getreuer All rights reserved.

This program is free software: you can redistribute it and/or modify it under, at your option, the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version, or the terms of the simplified BSD license.

You should have received a copy of these licenses along with this program. If not, see http://www.gnu.org/licenses/ and http://www.opensource.org/licenses/bsd-license.html.

Definition in file ace.c.

Function Documentation

int ace_enhance_image_interp ( float *  u,
const float *  f,
int  width,
int  height,
float  alpha,
const char *  omega_string,
int  num_levels 
)

ACE automatic color enhancement using level interpolation.

Parameters
uthe enhanced output image
fthe input image in planar row-major order
width,heightimage dimensions
alphathe slope parameter (>=1), larger implies stronger enhancement
omega_stringstring specifying the spatial weighting function
num_levelsnumber of interpolation levels (>=2)
Returns
1 on success, 0 on failure

This routine perform ACE enhancement by computing

\[ \omega(x) * s_\alpha(L - I(x)) \]

for fixed levels L. The $ R_L $ are then piecewise linearly interpolated to approximate R. The parameter num_levels determines the number of L values used. Increasing num_levels improves quality but increases computation time.

If non-null, parameter omega_string specifies the spatial weighting function $ \omega(x,y) $. Valid choices are

  • "1/r" default ACE, $ \omega(x,y) = 1/\sqrt{x^2 + y^2} $
  • "1" constant, $ \omega(x,y) = 1 $
  • "G:#" Gaussian where # is a number specifying $ \sigma $, $ \omega(x,y) = \exp(-\tfrac{x^2 + y^2}{2\sigma^2}) $

If OpenMP is enabled, the main computation loop is parallelized.

Definition at line 78 of file ace.c.

int ace_enhance_image_poly ( float *  u,
const float *  f,
int  width,
int  height,
float  alpha,
const char *  omega_string,
int  degree 
)

ACE automatic color enhancement using a polynomial slope function.

Parameters
uthe enhanced output image
fthe input image in planar row-major order
width,heightimage dimensions
alphathe slope parameter (>=1), larger implies stronger enhancement
omega_stringstring specifying the spatial weighting function
degreepolynomial degree (can be 3, 5, 7, 9, or 11)
Returns
1 on success, 0 on failure

This routine perform ACE enhancement using the fast O(N log N) algorithm of Bertalmio et al. The slope parameter must be an integer or half-integer between 1 and 8 (1, 1.5, 2, 2.5, ..., 7.5, 8). The slope function is approximated by an $ L^\infty $-optimal polynomial of degree degree.

If non-null, parameter omega_string specifies the spatial weighting function $ \omega(x,y) $. Valid choices are

  • "1/r" default ACE, $ \omega(x,y) = 1/\sqrt{x^2 + y^2} $
  • "1" constant, $ \omega(x,y) = 1 $
  • "G:#" Gaussian where # is a number specifying $ \sigma $, $ \omega(x,y) = \exp(-\tfrac{x^2 + y^2}{2\sigma^2}) $

If OpenMP is enabled, the main computation loop is parallelized.

note: In the parallel computation, values are summed in a nondeterministic order (i.e., in whichever order threads complete). Due to rounding effects, addition is not exactly associative and the output varies slightly between runs (+/- 1 intensity level).

Definition at line 266 of file ace.c.

static double binom_coeff ( int  m,
int  n 
)
static

Compute binomial coefficient for small m and n.

Parameters
m,nbinomial arguments
Returns
binomial coefficient $ {m \choose n} $

Uses factorial() to compute the binomial coefficient

\[ {m \choose n} := \frac{m!}{n!(m-n)!}. \]

Definition at line 734 of file ace.c.

static int compute_omega_trans ( float *  omega_trans,
float *  omega,
int  width,
int  height,
const char *  omega_string 
)
static

Compute the FFT of omega(x,y)

Parameters
omega_transdestination array
omegaworkspace array (overwritten by computation)
width,heightimage dimensions
omega_stringstring specifying the spatial weighting function
Returns
1 on success, 0 on failure

Definition at line 427 of file ace.c.

static double factorial ( int  n)
static

Compute small factorial.

Parameters
nfactorial argument
Returns
n!

Computes factorial for small n. factorials 0!, 1!, ..., 14! are hardcoded and recursion is used for general n. Beware that large factorials overflow numerical limits.

Definition at line 748 of file ace.c.

static void get_min_max ( float *  min_ptr,
float *  max_ptr,
const float *  data,
size_t  num_samples 
)
static

Find the min and max value of an array.

Parameters
min_ptrset to minimum value
max_ptrset to maximum value
datasource data
num_samplesnumber of data elements

Definition at line 491 of file ace.c.

static void int_pow ( float *  dest,
const float *  src,
size_t  num_samples,
int  m 
)
static

Evaluate integer power, hardcoded for degrees 1 to 11.

Parameters
destdestination data
srcsource data
num_samplesnumber of data elements
minteger power

Definition at line 523 of file ace.c.

static void stretch ( float *  image,
long  num_pixels 
)
static

Stetch image to [0,1].

Parameters
imageimage data in planar order
num_pixelsnumber of pixels

Linearly stretches each color channel so that min and max values are respectively 0 and 1.

Definition at line 629 of file ace.c.