Functions

balance_lib.c File Reference

simple color balance routines More...

#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <limits.h>
#include <string.h>
#include "balance_lib.h"
Include dependency graph for balance_lib.c:

Go to the source code of this file.

Functions

static void minmax_u8 (const unsigned char *data, size_t size, unsigned char *ptr_min, unsigned char *ptr_max)
 get the min/max of an unsigned char array
static void minmax_f32 (const float *data, size_t size, float *ptr_min, float *ptr_max)
 get the min/max of a float array
static void quantiles_u8 (const unsigned char *data, size_t size, size_t nb_min, size_t nb_max, unsigned char *ptr_min, unsigned char *ptr_max)
 get quantiles from an unsigned char array such that a given number of pixels is out of this interval
static int cmp_f32 (const void *a, const void *b)
 float comparison
static void quantiles_f32 (const float *data, size_t size, size_t nb_min, size_t nb_max, float *ptr_min, float *ptr_max)
 get quantiles from a float array such that a given number of pixels is out of this interval
static unsigned char * rescale_u8 (unsigned char *data, size_t size, unsigned char min, unsigned char max)
 rescale an unsigned char array
static float * rescale_f32 (float *data, size_t size, float min, float max)
 rescale a float array
unsigned char * balance_u8 (unsigned char *data, size_t size, size_t nb_min, size_t nb_max)
 normalize an unsigned char array
float * balance_f32 (float *data, size_t size, size_t nb_min, size_t nb_max)
 normalize a float array

Detailed Description

simple color balance routines

Author:
Nicolas Limare <nicolas.limare@cmla.ens-cachan.fr>
Jose-Luis Lisani <joseluis.lisani@uib.es>
Catalina Sbert <catalina.sbert@uib.es>

Definition in file balance_lib.c.


Function Documentation

float* balance_f32 ( float *  data,
size_t  size,
size_t  nb_min,
size_t  nb_max 
)

normalize a float array

This function operates in-place. It computes the minimum and maximum values of the data, and rescales the data to [0-1], with optionally flattening some extremal pixels.

Parameters:
data input/output array
size array size
nb_min,nb_max number extremal pixels flattened
Returns:
data

Definition at line 342 of file balance_lib.c.

Here is the call graph for this function:

Here is the caller graph for this function:

unsigned char* balance_u8 ( unsigned char *  data,
size_t  size,
size_t  nb_min,
size_t  nb_max 
)

normalize an unsigned char array

This function operates in-place. It computes the minimum and maximum values of the data, and rescales the data to [0-UCHAR_MAX], with optionally flattening some extremal pixels.

Parameters:
data input/output array
size array size
nb_min,nb_max number extremal pixels flattened
Returns:
data

Definition at line 300 of file balance_lib.c.

Here is the call graph for this function:

Here is the caller graph for this function:

static int cmp_f32 ( const void *  a,
const void *  b 
) [static]

float comparison

IEEE754 floats can be compared as integers. Not *converted* to integers, but *read* as integers while maintaining an order. cf. http://www.cygnus-software.com/papers/comparingfloats/Comparing%20floating%20point%20numbers.htm#_Toc135149455

Definition at line 168 of file balance_lib.c.

Here is the caller graph for this function:

static void minmax_f32 ( const float *  data,
size_t  size,
float *  ptr_min,
float *  ptr_max 
) [static]

get the min/max of a float array

Parameters:
data input array
size array size
ptr_min,ptr_max pointers to the returned values, ignored if NULL

Definition at line 74 of file balance_lib.c.

Here is the caller graph for this function:

static void minmax_u8 ( const unsigned char *  data,
size_t  size,
unsigned char *  ptr_min,
unsigned char *  ptr_max 
) [static]

get the min/max of an unsigned char array

Parameters:
data input array
size array size
ptr_min,ptr_max pointers to the returned values, ignored if NULL

Definition at line 43 of file balance_lib.c.

Here is the caller graph for this function:

static void quantiles_f32 ( const float *  data,
size_t  size,
size_t  nb_min,
size_t  nb_max,
float *  ptr_min,
float *  ptr_max 
) [static]

get quantiles from a float array such that a given number of pixels is out of this interval

This function computes min (resp. max) such that the number of pixels < min (resp. > max) is inferior or equal to nb_min (resp. nb_max). It uses a sorting algorithm.

Parameters:
data input/output
size data array size
nb_min,nb_max number of pixels to flatten
ptr_min,ptr_max computed min/max output, ignored if NULL
Todo:
instead of sorting the whole array (expensive), select pertinent values with a 128 bins histogram then sort the bins around the good bin

Definition at line 194 of file balance_lib.c.

Here is the call graph for this function:

Here is the caller graph for this function:

static void quantiles_u8 ( const unsigned char *  data,
size_t  size,
size_t  nb_min,
size_t  nb_max,
unsigned char *  ptr_min,
unsigned char *  ptr_max 
) [static]

get quantiles from an unsigned char array such that a given number of pixels is out of this interval

This function computes min (resp. max) such that the number of pixels < min (resp. > max) is inferior or equal to nb_min (resp. nb_max). It uses an histogram algorithm.

Parameters:
data input/output
size data array size
nb_min,nb_max number of pixels to flatten
ptr_min,ptr_max computed min/max output, ignored if NULL

Definition at line 111 of file balance_lib.c.

Here is the caller graph for this function:

static float* rescale_f32 ( float *  data,
size_t  size,
float  min,
float  max 
) [static]

rescale a float array

This function operates in-place. It rescales the data by a bounded affine function such that min becomes 0 and max becomes 1. Warnings similar to the ones mentioned in rescale_u8() apply about the risks of rounding errors.

Parameters:
data input/output array
size array size
min,max the minimum and maximum of the input array
Returns:
data

Definition at line 272 of file balance_lib.c.

Here is the caller graph for this function:

static unsigned char* rescale_u8 ( unsigned char *  data,
size_t  size,
unsigned char  min,
unsigned char  max 
) [static]

rescale an unsigned char array

This function operates in-place. It rescales the data by a bounded affine function such that min becomes 0 and max becomes UCHAR_MAX.

Parameters:
data input/output array
size array size
min,max the minimum and maximum of the input array
Returns:
data

Definition at line 228 of file balance_lib.c.

Here is the caller graph for this function:

 All Files Functions Variables Defines