Commit 7d4fe0c5 authored by Richard Ling's avatar Richard Ling Committed by Paul B Mahol

avfilter: add normalize filter

parent 279d2599
......@@ -19,6 +19,7 @@ version <next>:
- acontrast audio filter
- OpenCL overlay filter
- video mix filter
- video normalize filter
version 3.4:
......
......@@ -10867,6 +10867,86 @@ Add temporal and uniform noise to input video:
noise=alls=20:allf=t+u
@end example
@section normalize
Normalize RGB video (aka histogram stretching, contrast stretching).
See: https://en.wikipedia.org/wiki/Normalization_(image_processing)
For each channel of each frame, the filter computes the input range and maps
it linearly to the user-specified output range. The output range defaults
to the full dynamic range from pure black to pure white.
Temporal smoothing can be used on the input range to reduce flickering (rapid
changes in brightness) caused when small dark or bright objects enter or leave
the scene. This is similar to the auto-exposure (automatic gain control) on a
video camera, and, like a video camera, it may cause a period of over- or
under-exposure of the video.
The R,G,B channels can be normalized independently, which may cause some
color shifting, or linked together as a single channel, which prevents
color shifting. Linked normalization preserves hue. Independent normalization
does not, so it can be used to remove some color casts. Independent and linked
normalization can be combined in any ratio.
The normalize filter accepts the following options:
@table @option
@item blackpt
@item whitept
Colors which define the output range. The minimum input value is mapped to
the @var{blackpt}. The maximum input value is mapped to the @var{whitept}.
The defaults are black and white respectively. Specifying white for
@var{blackpt} and black for @var{whitept} will give color-inverted,
normalized video. Shades of grey can be used to reduce the dynamic range
(contrast). Specifying saturated colors here can create some interesting
effects.
@item smoothing
The number of previous frames to use for temporal smoothing. The input range
of each channel is smoothed using a rolling average over the current frame
and the @var{smoothing} previous frames. The default is 0 (no temporal
smoothing).
@item independence
Controls the ratio of independent (color shifting) channel normalization to
linked (color preserving) normalization. 0.0 is fully linked, 1.0 is fully
independent. Defaults to 1.0 (fully independent).
@item strength
Overall strength of the filter. 1.0 is full strength. 0.0 is a rather
expensive no-op. Defaults to 1.0 (full strength).
@end table
@subsection Examples
Stretch video contrast to use the full dynamic range, with no temporal
smoothing; may flicker depending on the source content:
@example
normalize=blackpt=black:whitept=white:smoothing=0
@end example
As above, but with 50 frames of temporal smoothing; flicker should be
reduced, depending on the source content:
@example
normalize=blackpt=black:whitept=white:smoothing=50
@end example
As above, but with hue-preserving linked channel normalization:
@example
normalize=blackpt=black:whitept=white:smoothing=50:independence=0
@end example
As above, but with half strength:
@example
normalize=blackpt=black:whitept=white:smoothing=50:independence=0:strength=0.5
@end example
Map the darkest input color to red, the brightest input color to cyan:
@example
normalize=blackpt=red:whitept=cyan
@end example
@section null
Pass the video source unchanged to the output.
......
......@@ -247,6 +247,7 @@ OBJS-$(CONFIG_NLMEANS_FILTER) += vf_nlmeans.o
OBJS-$(CONFIG_NNEDI_FILTER) += vf_nnedi.o
OBJS-$(CONFIG_NOFORMAT_FILTER) += vf_format.o
OBJS-$(CONFIG_NOISE_FILTER) += vf_noise.o
OBJS-$(CONFIG_NORMALIZE_FILTER) += vf_normalize.o
OBJS-$(CONFIG_NULL_FILTER) += vf_null.o
OBJS-$(CONFIG_OCR_FILTER) += vf_ocr.o
OBJS-$(CONFIG_OCV_FILTER) += vf_libopencv.o
......
......@@ -257,6 +257,7 @@ static void register_all(void)
REGISTER_FILTER(NNEDI, nnedi, vf);
REGISTER_FILTER(NOFORMAT, noformat, vf);
REGISTER_FILTER(NOISE, noise, vf);
REGISTER_FILTER(NORMALIZE, normalize, vf);
REGISTER_FILTER(NULL, null, vf);
REGISTER_FILTER(OCR, ocr, vf);
REGISTER_FILTER(OCV, ocv, vf);
......
......@@ -30,7 +30,7 @@
#include "libavutil/version.h"
#define LIBAVFILTER_VERSION_MAJOR 7
#define LIBAVFILTER_VERSION_MINOR 3
#define LIBAVFILTER_VERSION_MINOR 4
#define LIBAVFILTER_VERSION_MICRO 100
#define LIBAVFILTER_VERSION_INT AV_VERSION_INT(LIBAVFILTER_VERSION_MAJOR, \
......
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment