FFmpeg
Data Structures | Functions | Variables
vf_grayworld.c File Reference
#include "libavutil/imgutils.h"
#include "libavutil/mem.h"
#include "avfilter.h"
#include "filters.h"
#include "video.h"

Go to the source code of this file.

Data Structures

struct  ThreadData
 Used for passing data between threads. More...
 
struct  GrayWorldContext
 

Functions

static void apply_matrix (const float matrix[3][3], const float input[3], float output[3])
 
static void rgb2lab (const float rgb[3], float lab[3])
 Convert from Linear RGB to logspace LAB. More...
 
static void lab2rgb (const float lab[3], float rgb[3])
 Convert from Logspace LAB to Linear RGB. More...
 
static int convert_frame (AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
 Convert a frame from linear RGB to logspace LAB, and accumulate channel totals for each row Convert from RGB -> lms using equation 4 in color transfer paper. More...
 
static void compute_correction (GrayWorldContext *s, ThreadData *td)
 Sum the channel totals and compute the mean for each channel. More...
 
static int correct_frame (AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
 Subtract the mean logspace AB values from each pixel. More...
 
static int config_input (AVFilterLink *inlink)
 
static av_cold void uninit (AVFilterContext *ctx)
 
static int filter_frame (AVFilterLink *inlink, AVFrame *in)
 

Variables

static const float lms2lab [3][3]
 
static const float lab2lms [3][3]
 
static const float rgb2lms [3][3]
 
static const float lms2rgb [3][3]
 
static const AVFilterPad grayworld_inputs []
 
const AVFilter ff_vf_grayworld
 

Detailed Description

Color correction filter based on https://www.researchgate.net/publication/275213614_A_New_Color_Correction_Method_for_Underwater_Imaging

Definition in file vf_grayworld.c.

Function Documentation

◆ apply_matrix()

static void apply_matrix ( const float  matrix[3][3],
const float  input[3],
float  output[3] 
)
static

Definition at line 48 of file vf_grayworld.c.

Referenced by lab2rgb(), and rgb2lab().

◆ rgb2lab()

static void rgb2lab ( const float  rgb[3],
float  lab[3] 
)
static

Convert from Linear RGB to logspace LAB.

Parameters
rgbInput array of rgb components
laboutput array of lab components

Definition at line 85 of file vf_grayworld.c.

Referenced by convert_frame().

◆ lab2rgb()

static void lab2rgb ( const float  lab[3],
float  rgb[3] 
)
static

Convert from Logspace LAB to Linear RGB.

Parameters
labinput array of lab components
rgboutput array of rgb components

Definition at line 102 of file vf_grayworld.c.

Referenced by correct_frame().

◆ convert_frame()

static int convert_frame ( AVFilterContext ctx,
void *  arg,
int  jobnr,
int  nb_jobs 
)
static

Convert a frame from linear RGB to logspace LAB, and accumulate channel totals for each row Convert from RGB -> lms using equation 4 in color transfer paper.

Parameters
ctxFilter context
argThread data pointer
jobnrjob number
nb_jobsnumber of jobs

Definition at line 122 of file vf_grayworld.c.

Referenced by filter_frame().

◆ compute_correction()

static void compute_correction ( GrayWorldContext s,
ThreadData td 
)
static

Sum the channel totals and compute the mean for each channel.

Parameters
sFrame context
tdthread data

Definition at line 167 of file vf_grayworld.c.

Referenced by filter_frame().

◆ correct_frame()

static int correct_frame ( AVFilterContext ctx,
void *  arg,
int  jobnr,
int  nb_jobs 
)
static

Subtract the mean logspace AB values from each pixel.

Parameters
ctxFilter context
argThread data pointer
jobnrjob number
nb_jobsnumber of jobs

Definition at line 190 of file vf_grayworld.c.

Referenced by filter_frame().

◆ config_input()

static int config_input ( AVFilterLink inlink)
static

Definition at line 227 of file vf_grayworld.c.

◆ uninit()

static av_cold void uninit ( AVFilterContext ctx)
static

Definition at line 240 of file vf_grayworld.c.

◆ filter_frame()

static int filter_frame ( AVFilterLink inlink,
AVFrame in 
)
static

Definition at line 249 of file vf_grayworld.c.

Variable Documentation

◆ lms2lab

const float lms2lab[3][3]
static
Initial value:
= {
{0.5774, 0.5774, 0.5774},
{0.40825, 0.40825, -0.816458},
{0.707, -0.707, 0}
}

Definition at line 55 of file vf_grayworld.c.

Referenced by rgb2lab().

◆ lab2lms

const float lab2lms[3][3]
static
Initial value:
= {
{0.57735, 0.40825, 0.707},
{0.57735, 0.40825, -0.707},
{0.57735, -0.8165, 0}
}

Definition at line 61 of file vf_grayworld.c.

Referenced by lab2rgb().

◆ rgb2lms

const float rgb2lms[3][3]
static
Initial value:
= {
{0.3811, 0.5783, 0.0402},
{0.1967, 0.7244, 0.0782},
{0.0241, 0.1288, 0.8444}
}

Definition at line 67 of file vf_grayworld.c.

Referenced by rgb2lab().

◆ lms2rgb

const float lms2rgb[3][3]
static
Initial value:
= {
{4.4679, -3.5873, 0.1193},
{-1.2186, 2.3809, -0.1624},
{0.0497, -0.2439, 1.2045}
}

Definition at line 73 of file vf_grayworld.c.

Referenced by lab2rgb().

◆ grayworld_inputs

const AVFilterPad grayworld_inputs[]
static
Initial value:
= {
{
.name = "default",
.filter_frame = filter_frame,
.config_props = config_input,
}
}

Definition at line 291 of file vf_grayworld.c.

◆ ff_vf_grayworld

const AVFilter ff_vf_grayworld
Initial value:
= {
.name = "grayworld",
.description = NULL_IF_CONFIG_SMALL("Adjust white balance using LAB gray world algorithm"),
.priv_size = sizeof(GrayWorldContext),
.uninit = uninit,
}

Definition at line 300 of file vf_grayworld.c.

FILTER_INPUTS
#define FILTER_INPUTS(array)
Definition: filters.h:262
uninit
static av_cold void uninit(AVFilterContext *ctx)
Definition: vf_grayworld.c:240
filter_frame
static int filter_frame(AVFilterLink *inlink, AVFrame *in)
Definition: vf_grayworld.c:249
ff_video_default_filterpad
const AVFilterPad ff_video_default_filterpad[1]
An AVFilterPad array whose only entry has name "default" and is of type AVMEDIA_TYPE_VIDEO.
Definition: video.c:37
FILTER_OUTPUTS
#define FILTER_OUTPUTS(array)
Definition: filters.h:263
NULL_IF_CONFIG_SMALL
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
Definition: internal.h:94
config_input
static int config_input(AVFilterLink *inlink)
Definition: vf_grayworld.c:227
AV_PIX_FMT_GBRPF32
#define AV_PIX_FMT_GBRPF32
Definition: pixfmt.h:517
GrayWorldContext
Definition: vf_grayworld.c:42
AVFILTER_FLAG_SUPPORT_TIMELINE_GENERIC
#define AVFILTER_FLAG_SUPPORT_TIMELINE_GENERIC
Some filters support a generic "enable" expression option that can be used to enable or disable a fil...
Definition: avfilter.h:182
FILTER_PIXFMTS
#define FILTER_PIXFMTS(...)
Definition: filters.h:248
AV_PIX_FMT_GBRAPF32
#define AV_PIX_FMT_GBRAPF32
Definition: pixfmt.h:518
AVFILTER_FLAG_SLICE_THREADS
#define AVFILTER_FLAG_SLICE_THREADS
The filter supports multithreading by splitting frames into multiple parts and processing them concur...
Definition: avfilter.h:152
AVMEDIA_TYPE_VIDEO
@ AVMEDIA_TYPE_VIDEO
Definition: avutil.h:201
grayworld_inputs
static const AVFilterPad grayworld_inputs[]
Definition: vf_grayworld.c:291