simple color balance routines More...
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <limits.h>
#include <string.h>
#include "balance_lib.h"
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 |
simple color balance routines
Definition in file balance_lib.c.
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.
data | input/output array | |
size | array size | |
nb_min,nb_max | number extremal pixels flattened |
Definition at line 342 of file balance_lib.c.
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.
data | input/output array | |
size | array size | |
nb_min,nb_max | number extremal pixels flattened |
Definition at line 300 of file balance_lib.c.
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.
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
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.
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
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.
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.
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 194 of file balance_lib.c.
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.
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.
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.
data | input/output array | |
size | array size | |
min,max | the minimum and maximum of the input array |
Definition at line 272 of file balance_lib.c.
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.
data | input/output array | |
size | array size | |
min,max | the minimum and maximum of the input array |
Definition at line 228 of file balance_lib.c.