[FFmpeg-devel] [PATCH] lavfi: port ow from libmpcodecs.
Michael Niedermayer
michaelni at gmx.at
Fri May 10 22:42:14 CEST 2013
On Fri, May 10, 2013 at 10:10:15PM +0200, Clément Bœsch wrote:
> TODO: Changelog & minor bump
>
> ---
> Feel free to bikeshed for a new name.
>
> mp=ow will be dropped in the same time.
> ---
> doc/filters.texi | 26 ++++
> libavfilter/Makefile | 1 +
> libavfilter/allfilters.c | 1 +
> libavfilter/vf_ow.c | 344 +++++++++++++++++++++++++++++++++++++++++++++++
> 4 files changed, 372 insertions(+)
> create mode 100644 libavfilter/vf_ow.c
>
> diff --git a/doc/filters.texi b/doc/filters.texi
> index fe38b7f..8b9fb4a 100644
> --- a/doc/filters.texi
> +++ b/doc/filters.texi
> @@ -5103,6 +5103,32 @@ testsrc=s=100x100, split=4 [in0][in1][in2][in3];
>
> @end itemize
>
> + at section ow
> +
> +Overcomplete Wavelet denoiser.
> +
> +The filter accepts the following options:
> +
> + at table @option
> + at item depth
> +Set depth.
> +
> +Larger depth values will denoise lower frequency components more, but
> +slow down filtering
> +
> +Default is @code{8}.
> +
> + at item luma_strength
> +Set luma strength.
> +
> +Default is @code{1.0}
> +
> + at item chroma_strength
> +Set chroma strength.
> +
> +Default is @code{1.0}
> + at end table
> +
> @section pad
>
> Add paddings to the input image, and place the original input at the
> diff --git a/libavfilter/Makefile b/libavfilter/Makefile
> index 73a24dd..f6daed1 100644
> --- a/libavfilter/Makefile
> +++ b/libavfilter/Makefile
> @@ -154,6 +154,7 @@ OBJS-$(CONFIG_NULL_FILTER) += vf_null.o
> OBJS-$(CONFIG_OCV_FILTER) += vf_libopencv.o
> OBJS-$(CONFIG_OPENCL) += deshake_opencl.o unsharp_opencl.o
> OBJS-$(CONFIG_OVERLAY_FILTER) += vf_overlay.o
> +OBJS-$(CONFIG_OW_FILTER) += vf_ow.o
> OBJS-$(CONFIG_PAD_FILTER) += vf_pad.o
> OBJS-$(CONFIG_PERMS_FILTER) += f_perms.o
> OBJS-$(CONFIG_PIXDESCTEST_FILTER) += vf_pixdesctest.o
> diff --git a/libavfilter/allfilters.c b/libavfilter/allfilters.c
> index b8f273d..8986547 100644
> --- a/libavfilter/allfilters.c
> +++ b/libavfilter/allfilters.c
> @@ -151,6 +151,7 @@ void avfilter_register_all(void)
> REGISTER_FILTER(NULL, null, vf);
> REGISTER_FILTER(OCV, ocv, vf);
> REGISTER_FILTER(OVERLAY, overlay, vf);
> + REGISTER_FILTER(OW, ow, vf);
> REGISTER_FILTER(PAD, pad, vf);
> REGISTER_FILTER(PERMS, perms, vf);
> REGISTER_FILTER(PIXDESCTEST, pixdesctest, vf);
> diff --git a/libavfilter/vf_ow.c b/libavfilter/vf_ow.c
> new file mode 100644
> index 0000000..97c386a
> --- /dev/null
> +++ b/libavfilter/vf_ow.c
> @@ -0,0 +1,344 @@
> +/*
> + * Copyright (C) 2007 Michael Niedermayer <michaelni at gmx.at>
> + * Copyright (c) 2013 Clément Bœsch
> + *
> + * This file is part of FFmpeg.
> + *
> + * FFmpeg is free software; you can redistribute it and/or
> + * modify it under the terms of the GNU Lesser General Public
> + * License as published by the Free Software Foundation; either
> + * version 2.1 of the License, or (at your option) any later version.
> + *
> + * FFmpeg is distributed in the hope that it will be useful,
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
> + * Lesser General Public License for more details.
> + *
> + * You should have received a copy of the GNU Lesser General Public
> + * License along with FFmpeg; if not, write to the Free Software
> + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
> + */
> +
> +/**
> + * @todo try to change to int
> + * @todo try lifting based implementation
> + * @todo optimize optimize optimize
> + * @todo hard tresholding
> + * @todo use QP to decide filter strength
> + * @todo wavelet normalization / least squares optimal signal vs. noise thresholds
> + */
> +
> +#include "libavutil/imgutils.h"
> +#include "libavutil/opt.h"
> +#include "libavutil/pixdesc.h"
> +#include "avfilter.h"
> +#include "internal.h"
> +
> +typedef struct {
> + const AVClass *class;
> + double luma_strength;
> + double chroma_strength;
> + int depth;
> + float *plane[16+1][4];
> + int linesize;
> + int hsub, vsub;
> +} OWContext;
> +
> +#define OFFSET(x) offsetof(OWContext, x)
> +#define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM
> +static const AVOption ow_options[] = {
> + { "depth", "set depth", OFFSET(depth), AV_OPT_TYPE_INT, {.i64 = 8}, 8, 16, FLAGS },
> + { "luma_strength", "set luma strength", OFFSET(luma_strength), AV_OPT_TYPE_DOUBLE, {.dbl = 1.0 }, 0, 1000, FLAGS },
> + { "ls", "set luma strength", OFFSET(luma_strength), AV_OPT_TYPE_DOUBLE, {.dbl = 1.0 }, 0, 1000, FLAGS },
> + { "chroma_strength", "set chroma strength", OFFSET(chroma_strength), AV_OPT_TYPE_DOUBLE, {.dbl = 1.0 }, 0, 1000, FLAGS },
> + { "cs", "set chroma strength", OFFSET(chroma_strength), AV_OPT_TYPE_DOUBLE, {.dbl = 1.0 }, 0, 1000, FLAGS },
> + { NULL }
> +};
> +
> +AVFILTER_DEFINE_CLASS(ow);
> +
> +DECLARE_ALIGNED(8, static const uint8_t, dither)[8][8] = {
> + { 0, 48, 12, 60, 3, 51, 15, 63 },
> + { 32, 16, 44, 28, 35, 19, 47, 31 },
> + { 8, 56, 4, 52, 11, 59, 7, 55 },
> + { 40, 24, 36, 20, 43, 27, 39, 23 },
> + { 2, 50, 14, 62, 1, 49, 13, 61 },
> + { 34, 18, 46, 30, 33, 17, 45, 29 },
> + { 10, 58, 6, 54, 9, 57, 5, 53 },
> + { 42, 26, 38, 22, 41, 25, 37, 21 },
> +};
> +
> +#define SQRT2 1.41421356237
> +
> +static const double coeff[2][5] = {
> + {
> + 0.6029490182363579 * SQRT2,
> + 0.2668641184428723 * SQRT2,
> + -0.07822326652898785 * SQRT2,
> + -0.01686411844287495 * SQRT2,
> + 0.02674875741080976 * SQRT2,
> + },{
> + 1.115087052456994 / SQRT2,
> + -0.5912717631142470 / SQRT2,
> + -0.05754352622849957 / SQRT2,
> + 0.09127176311424948 / SQRT2,
> + }
> +};
> +
> +static const double icoeff[2][5]={
> + {
> + 1.115087052456994 / SQRT2,
> + 0.5912717631142470 / SQRT2,
> + -0.05754352622849957 / SQRT2,
> + -0.09127176311424948 / SQRT2,
> + },{
> + 0.6029490182363579 * SQRT2,
> + -0.2668641184428723 * SQRT2,
> + -0.07822326652898785 * SQRT2,
> + 0.01686411844287495 * SQRT2,
> + 0.02674875741080976 * SQRT2,
> + }
> +};
> +
> +static inline int mirror(int x, int w)
> +{
> + while((unsigned)x > (unsigned)w) {
> + x = -x;
> + if (x < 0)
> + x += 2 * w;
> + }
> + return x;
> +}
> +
> +static inline void decompose(float *dst_l, float *dst_h, const float *src,
> + int linesize, int w)
> +{
> + int x, i;
> + for (x = 0; x < w; x++) {
> + double sum_l = src[x * linesize] * coeff[0][0];
> + double sum_h = src[x * linesize] * coeff[1][0];
> + for (i = 1; i <= 4; i++) {
> + const double s = src[mirror(x - i, w - 1) * linesize]
> + + src[mirror(x + i, w - 1) * linesize];
> +
> + sum_l += coeff[0][i] * s;
> + sum_h += coeff[1][i] * s;
> + }
> + dst_l[x * linesize] = sum_l;
> + dst_h[x * linesize] = sum_h;
> + }
> +}
> +
> +static inline void compose(float *dst, const float *src_l, const float *src_h,
> + int linesize, int w)
> +{
> + int x, i;
> + for (x = 0; x < w; x++) {
> + double sum_l = src_l[x * linesize] * icoeff[0][0];
> + double sum_h = src_h[x * linesize] * icoeff[1][0];
> + for (i = 1; i <= 4; i++) {
> + const int x0 = mirror(x - i, w - 1) * linesize;
> + const int x1 = mirror(x + i, w - 1) * linesize;
> +
> + sum_l += icoeff[0][i] * (src_l[x0] + src_l[x1]);
> + sum_h += icoeff[1][i] * (src_h[x0] + src_h[x1]);
> + }
> + dst[x * linesize] = (sum_l + sum_h) * 0.5;
> + }
> +}
> +
> +static inline void decompose2D(float *dst_l, float *dst_h, const float *src,
> + int xlinesize, int ylinesize,
> + int step, int w, int h)
> +{
> + int y, x;
> + for (y = 0; y < h; y++)
> + for (x = 0; x < step; x++)
> + decompose(dst_l + ylinesize*y + xlinesize*x,
> + dst_h + ylinesize*y + xlinesize*x,
> + src + ylinesize*y + xlinesize*x,
> + step * xlinesize, (w - x + step - 1) / step);
> +}
> +
> +static inline void compose2D(float *dst, const float *src_l, const float *src_h,
> + int xlinesize, int ylinesize,
> + int step, int w, int h)
> +{
> + int y, x;
> + for (y = 0; y < h; y++)
> + for (x = 0; x < step; x++)
> + compose(dst + ylinesize*y + xlinesize*x,
> + src_l + ylinesize*y + xlinesize*x,
> + src_h + ylinesize*y + xlinesize*x,
> + step * xlinesize, (w - x + step - 1) / step);
> +}
> +
> +static void decompose2D2(float *dst[4], float *src, float *temp[2],
> + int linesize, int step, int w, int h)
> +{
> + decompose2D(temp[0], temp[1], src, 1, linesize, step, w, h);
> + decompose2D( dst[0], dst[1], temp[0], linesize, 1, step, h, w);
> + decompose2D( dst[2], dst[3], temp[1], linesize, 1, step, h, w);
> +}
> +
> +static void compose2D2(float *dst, float *src[4], float *temp[2],
> + int linesize, int step, int w, int h)
> +{
> + compose2D(temp[0], src[0], src[1], linesize, 1, step, h, w);
> + compose2D(temp[1], src[2], src[3], linesize, 1, step, h, w);
> + compose2D(dst, temp[0], temp[1], 1, linesize, step, w, h);
> +}
this possibly could be factorized with the wavelet code we have in
libavcodec. such factorization could also be a seperate patch ...
[...]
--
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB
I am the wisest man alive, for I know one thing, and that is that I know
nothing. -- Socrates
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 198 bytes
Desc: Digital signature
URL: <http://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20130510/20e6ad44/attachment.asc>
More information about the ffmpeg-devel
mailing list