Re: [FFmpeg-devel] [PATCH v3] GSoC: Add guided filter
Xuewei Meng: > V3: Add examples on how to use this filter, and improve the code style. > V2: Implement the slice-level parallelism for guided filter. > V1: Add the basic version of guided filter. > > Signed-off-by: Xuewei Meng > --- > doc/filters.texi | 38 + > libavfilter/Makefile | 1 + > libavfilter/allfilters.c | 1 + > libavfilter/vf_guided.c | 429 > +++ > 4 files changed, 469 insertions(+) > create mode 100644 libavfilter/vf_guided.c > > diff --git a/doc/filters.texi b/doc/filters.texi > index 36e35a1..515c655 100644 > --- a/doc/filters.texi > +++ b/doc/filters.texi > @@ -12918,6 +12918,44 @@ greyedge=difford=1:minknorm=0:sigma=2 > > @end itemize > > +@section guided filter > +Apply guided filter for edge-preserving smoothing, dehazing and so on. > + > +The filter accepts the following options: > +@table @option > +@item radius > +Set the radius in pixels. > +Allowed range is 1 to 20. Default is 3. > + > +@item eps > +Set regularization parameter. > +Allowed range is 0 to 1. Default is 0.1. > + > +@item planes > +Set planes to filter. Default is first only. > +@end table > + > +@subsection Commands > +This filter supports the all above options as @ref{commands}. > + > +@subsection Examples > +@itemize > +@item > +Edge-preserving smoothing with guided filter: > +@example > +ffmpeg -i in.png -i in.png -filter_complex guided out.png > +@end example > + > +@item > +Dehazing, structure-transferring filtering, detail enhancement with guided > filter. > +For the generation of guidance image, > +see @url{http://kaiminghe.com/publications/pami12guidedfilter.pdf}. > +@example > +ffmpeg -i in.png -i guidance.png -filter_complex guided out.png > +@end example > + > +@end itemize > + > @anchor{haldclut} > @section haldclut > > diff --git a/libavfilter/Makefile b/libavfilter/Makefile > index 5a28736..60a97e1 100644 > --- a/libavfilter/Makefile > +++ b/libavfilter/Makefile > @@ -285,6 +285,7 @@ OBJS-$(CONFIG_GEQ_FILTER)+= vf_geq.o > OBJS-$(CONFIG_GRADFUN_FILTER)+= vf_gradfun.o > OBJS-$(CONFIG_GRAPHMONITOR_FILTER) += f_graphmonitor.o > OBJS-$(CONFIG_GREYEDGE_FILTER) += vf_colorconstancy.o > +OBJS-$(CONFIG_GUIDED_FILTER) += vf_guided.o > OBJS-$(CONFIG_HALDCLUT_FILTER) += vf_lut3d.o framesync.o > OBJS-$(CONFIG_HFLIP_FILTER) += vf_hflip.o > OBJS-$(CONFIG_HISTEQ_FILTER) += vf_histeq.o > diff --git a/libavfilter/allfilters.c b/libavfilter/allfilters.c > index 931d7db..962f656 100644 > --- a/libavfilter/allfilters.c > +++ b/libavfilter/allfilters.c > @@ -270,6 +270,7 @@ extern const AVFilter ff_vf_geq; > extern const AVFilter ff_vf_gradfun; > extern const AVFilter ff_vf_graphmonitor; > extern const AVFilter ff_vf_greyedge; > +extern const AVFilter ff_vf_guided; > extern const AVFilter ff_vf_haldclut; > extern const AVFilter ff_vf_hflip; > extern const AVFilter ff_vf_histeq; > diff --git a/libavfilter/vf_guided.c b/libavfilter/vf_guided.c > new file mode 100644 > index 000..bd706fb > --- /dev/null > +++ b/libavfilter/vf_guided.c > @@ -0,0 +1,429 @@ > +/* > + * Copyright (c) 2021 Xuewei Meng > + * > + * 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 > + */ > + > +#include "libavutil/imgutils.h" > +#include "libavutil/opt.h" > +#include "libavutil/pixdesc.h" > +#include "avfilter.h" > +#include "formats.h" > +#include "framesync.h" > +#include "internal.h" > +#include "video.h" > + > +typedef struct GuidedContext { > +const AVClass *class; > +FFFrameSync fs; > + > +int radius; > +float eps; > + > +int planes; > + > +int width; > +int height; > + > +int nb_planes; > +int depth; > +int planewidth[4]; > +int planeheight[4]; > + > +int (*box_slice)(AVFilterContext *ctx, void *arg, int jobnr, int > nb_jobs); > +} GuidedContext; > + > +#define OFFSET(x) offsetof(GuidedContext, x) > +#define FLAGS > AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_RUNTIME_PARAM > + > +static const AVOption guided_options[] = { > +{ "radius", "set the box radius", OFFSET(radius), > AV_OPT_TYPE_INT, {.i64=3},
Re: [FFmpeg-devel] [PATCH v3] GSoC: Add guided filter
> 2021年5月8日 下午6:20,Steven Liu 写道: > > > >> 2021年5月8日 下午6:06,Xuewei Meng <928826...@qq.com> 写道: >> >> V3: Add examples on how to use this filter, and improve the code style. >> V2: Implement the slice-level parallelism for guided filter. >> V1: Add the basic version of guided filter. >> >> Signed-off-by: Xuewei Meng >> --- >> doc/filters.texi | 38 + >> libavfilter/Makefile | 1 + >> libavfilter/allfilters.c | 1 + >> libavfilter/vf_guided.c | 429 >> +++ >> 4 files changed, 469 insertions(+) >> create mode 100644 libavfilter/vf_guided.c >> >> diff --git a/doc/filters.texi b/doc/filters.texi >> index 36e35a1..515c655 100644 >> --- a/doc/filters.texi >> +++ b/doc/filters.texi >> @@ -12918,6 +12918,44 @@ greyedge=difford=1:minknorm=0:sigma=2 >> >> @end itemize >> >> +@section guided filter >> +Apply guided filter for edge-preserving smoothing, dehazing and so on. >> + >> +The filter accepts the following options: >> +@table @option >> +@item radius >> +Set the radius in pixels. >> +Allowed range is 1 to 20. Default is 3. >> + >> +@item eps >> +Set regularization parameter. >> +Allowed range is 0 to 1. Default is 0.1. >> + >> +@item planes >> +Set planes to filter. Default is first only. >> +@end table >> + >> +@subsection Commands >> +This filter supports the all above options as @ref{commands}. >> + >> +@subsection Examples >> +@itemize >> +@item >> +Edge-preserving smoothing with guided filter: >> +@example >> +ffmpeg -i in.png -i in.png -filter_complex guided out.png >> +@end example >> + >> +@item >> +Dehazing, structure-transferring filtering, detail enhancement with guided >> filter. >> +For the generation of guidance image, >> +see @url{http://kaiminghe.com/publications/pami12guidedfilter.pdf}. >> +@example >> +ffmpeg -i in.png -i guidance.png -filter_complex guided out.png >> +@end example >> + >> +@end itemize >> + >> @anchor{haldclut} >> @section haldclut >> >> diff --git a/libavfilter/Makefile b/libavfilter/Makefile >> index 5a28736..60a97e1 100644 >> --- a/libavfilter/Makefile >> +++ b/libavfilter/Makefile >> @@ -285,6 +285,7 @@ OBJS-$(CONFIG_GEQ_FILTER)+= vf_geq.o >> OBJS-$(CONFIG_GRADFUN_FILTER)+= vf_gradfun.o >> OBJS-$(CONFIG_GRAPHMONITOR_FILTER) += f_graphmonitor.o >> OBJS-$(CONFIG_GREYEDGE_FILTER) += vf_colorconstancy.o >> +OBJS-$(CONFIG_GUIDED_FILTER) += vf_guided.o >> OBJS-$(CONFIG_HALDCLUT_FILTER) += vf_lut3d.o framesync.o >> OBJS-$(CONFIG_HFLIP_FILTER) += vf_hflip.o >> OBJS-$(CONFIG_HISTEQ_FILTER) += vf_histeq.o >> diff --git a/libavfilter/allfilters.c b/libavfilter/allfilters.c >> index 931d7db..962f656 100644 >> --- a/libavfilter/allfilters.c >> +++ b/libavfilter/allfilters.c >> @@ -270,6 +270,7 @@ extern const AVFilter ff_vf_geq; >> extern const AVFilter ff_vf_gradfun; >> extern const AVFilter ff_vf_graphmonitor; >> extern const AVFilter ff_vf_greyedge; >> +extern const AVFilter ff_vf_guided; >> extern const AVFilter ff_vf_haldclut; >> extern const AVFilter ff_vf_hflip; >> extern const AVFilter ff_vf_histeq; >> diff --git a/libavfilter/vf_guided.c b/libavfilter/vf_guided.c >> new file mode 100644 >> index 000..bd706fb >> --- /dev/null >> +++ b/libavfilter/vf_guided.c >> @@ -0,0 +1,429 @@ >> +/* >> + * Copyright (c) 2021 Xuewei Meng >> + * >> + * 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 >> + */ >> + >> +#include "libavutil/imgutils.h" >> +#include "libavutil/opt.h" >> +#include "libavutil/pixdesc.h" >> +#include "avfilter.h" >> +#include "formats.h" >> +#include "framesync.h" >> +#include "internal.h" >> +#include "video.h" >> + >> +typedef struct GuidedContext { >> +const AVClass *class; >> +FFFrameSync fs; >> + >> +int radius; >> +float eps; >> + >> +int planes; >> + >> +int width; >> +int height; >> + >> +int nb_planes; >> +int depth; >> +int planewidth[4]; >> +int planeheight[4]; >> + >> +int (*box_slice)(AVFilterContext *ctx, void *arg, int jobnr, int >> nb_jobs); >> +} GuidedContext; >> + >> +#define OFFSET(x) offsetof(GuidedContext, x) >> +#define FLAGS >>
Re: [FFmpeg-devel] [PATCH v3] GSoC: Add guided filter
> 2021年5月8日 下午6:06,Xuewei Meng <928826...@qq.com> 写道: > > V3: Add examples on how to use this filter, and improve the code style. > V2: Implement the slice-level parallelism for guided filter. > V1: Add the basic version of guided filter. > > Signed-off-by: Xuewei Meng > --- > doc/filters.texi | 38 + > libavfilter/Makefile | 1 + > libavfilter/allfilters.c | 1 + > libavfilter/vf_guided.c | 429 +++ > 4 files changed, 469 insertions(+) > create mode 100644 libavfilter/vf_guided.c > > diff --git a/doc/filters.texi b/doc/filters.texi > index 36e35a1..515c655 100644 > --- a/doc/filters.texi > +++ b/doc/filters.texi > @@ -12918,6 +12918,44 @@ greyedge=difford=1:minknorm=0:sigma=2 > > @end itemize > > +@section guided filter > +Apply guided filter for edge-preserving smoothing, dehazing and so on. > + > +The filter accepts the following options: > +@table @option > +@item radius > +Set the radius in pixels. > +Allowed range is 1 to 20. Default is 3. > + > +@item eps > +Set regularization parameter. > +Allowed range is 0 to 1. Default is 0.1. > + > +@item planes > +Set planes to filter. Default is first only. > +@end table > + > +@subsection Commands > +This filter supports the all above options as @ref{commands}. > + > +@subsection Examples > +@itemize > +@item > +Edge-preserving smoothing with guided filter: > +@example > +ffmpeg -i in.png -i in.png -filter_complex guided out.png > +@end example > + > +@item > +Dehazing, structure-transferring filtering, detail enhancement with guided > filter. > +For the generation of guidance image, > +see @url{http://kaiminghe.com/publications/pami12guidedfilter.pdf}. > +@example > +ffmpeg -i in.png -i guidance.png -filter_complex guided out.png > +@end example > + > +@end itemize > + > @anchor{haldclut} > @section haldclut > > diff --git a/libavfilter/Makefile b/libavfilter/Makefile > index 5a28736..60a97e1 100644 > --- a/libavfilter/Makefile > +++ b/libavfilter/Makefile > @@ -285,6 +285,7 @@ OBJS-$(CONFIG_GEQ_FILTER)+= vf_geq.o > OBJS-$(CONFIG_GRADFUN_FILTER)+= vf_gradfun.o > OBJS-$(CONFIG_GRAPHMONITOR_FILTER) += f_graphmonitor.o > OBJS-$(CONFIG_GREYEDGE_FILTER) += vf_colorconstancy.o > +OBJS-$(CONFIG_GUIDED_FILTER) += vf_guided.o > OBJS-$(CONFIG_HALDCLUT_FILTER) += vf_lut3d.o framesync.o > OBJS-$(CONFIG_HFLIP_FILTER) += vf_hflip.o > OBJS-$(CONFIG_HISTEQ_FILTER) += vf_histeq.o > diff --git a/libavfilter/allfilters.c b/libavfilter/allfilters.c > index 931d7db..962f656 100644 > --- a/libavfilter/allfilters.c > +++ b/libavfilter/allfilters.c > @@ -270,6 +270,7 @@ extern const AVFilter ff_vf_geq; > extern const AVFilter ff_vf_gradfun; > extern const AVFilter ff_vf_graphmonitor; > extern const AVFilter ff_vf_greyedge; > +extern const AVFilter ff_vf_guided; > extern const AVFilter ff_vf_haldclut; > extern const AVFilter ff_vf_hflip; > extern const AVFilter ff_vf_histeq; > diff --git a/libavfilter/vf_guided.c b/libavfilter/vf_guided.c > new file mode 100644 > index 000..bd706fb > --- /dev/null > +++ b/libavfilter/vf_guided.c > @@ -0,0 +1,429 @@ > +/* > + * Copyright (c) 2021 Xuewei Meng > + * > + * 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 > + */ > + > +#include "libavutil/imgutils.h" > +#include "libavutil/opt.h" > +#include "libavutil/pixdesc.h" > +#include "avfilter.h" > +#include "formats.h" > +#include "framesync.h" > +#include "internal.h" > +#include "video.h" > + > +typedef struct GuidedContext { > +const AVClass *class; > +FFFrameSync fs; > + > +int radius; > +float eps; > + > +int planes; > + > +int width; > +int height; > + > +int nb_planes; > +int depth; > +int planewidth[4]; > +int planeheight[4]; > + > +int (*box_slice)(AVFilterContext *ctx, void *arg, int jobnr, int > nb_jobs); > +} GuidedContext; > + > +#define OFFSET(x) offsetof(GuidedContext, x) > +#define FLAGS > AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_RUNTIME_PARAM > + > +static const AVOption guided_options[] = { > +{ "radius", "set the box radius", OFFSET(radius), >
[FFmpeg-devel] [PATCH v3] GSoC: Add guided filter
V3: Add examples on how to use this filter, and improve the code style. V2: Implement the slice-level parallelism for guided filter. V1: Add the basic version of guided filter. Signed-off-by: Xuewei Meng --- doc/filters.texi | 38 + libavfilter/Makefile | 1 + libavfilter/allfilters.c | 1 + libavfilter/vf_guided.c | 429 +++ 4 files changed, 469 insertions(+) create mode 100644 libavfilter/vf_guided.c diff --git a/doc/filters.texi b/doc/filters.texi index 36e35a1..515c655 100644 --- a/doc/filters.texi +++ b/doc/filters.texi @@ -12918,6 +12918,44 @@ greyedge=difford=1:minknorm=0:sigma=2 @end itemize +@section guided filter +Apply guided filter for edge-preserving smoothing, dehazing and so on. + +The filter accepts the following options: +@table @option +@item radius +Set the radius in pixels. +Allowed range is 1 to 20. Default is 3. + +@item eps +Set regularization parameter. +Allowed range is 0 to 1. Default is 0.1. + +@item planes +Set planes to filter. Default is first only. +@end table + +@subsection Commands +This filter supports the all above options as @ref{commands}. + +@subsection Examples +@itemize +@item +Edge-preserving smoothing with guided filter: +@example +ffmpeg -i in.png -i in.png -filter_complex guided out.png +@end example + +@item +Dehazing, structure-transferring filtering, detail enhancement with guided filter. +For the generation of guidance image, +see @url{http://kaiminghe.com/publications/pami12guidedfilter.pdf}. +@example +ffmpeg -i in.png -i guidance.png -filter_complex guided out.png +@end example + +@end itemize + @anchor{haldclut} @section haldclut diff --git a/libavfilter/Makefile b/libavfilter/Makefile index 5a28736..60a97e1 100644 --- a/libavfilter/Makefile +++ b/libavfilter/Makefile @@ -285,6 +285,7 @@ OBJS-$(CONFIG_GEQ_FILTER)+= vf_geq.o OBJS-$(CONFIG_GRADFUN_FILTER)+= vf_gradfun.o OBJS-$(CONFIG_GRAPHMONITOR_FILTER) += f_graphmonitor.o OBJS-$(CONFIG_GREYEDGE_FILTER) += vf_colorconstancy.o +OBJS-$(CONFIG_GUIDED_FILTER) += vf_guided.o OBJS-$(CONFIG_HALDCLUT_FILTER) += vf_lut3d.o framesync.o OBJS-$(CONFIG_HFLIP_FILTER) += vf_hflip.o OBJS-$(CONFIG_HISTEQ_FILTER) += vf_histeq.o diff --git a/libavfilter/allfilters.c b/libavfilter/allfilters.c index 931d7db..962f656 100644 --- a/libavfilter/allfilters.c +++ b/libavfilter/allfilters.c @@ -270,6 +270,7 @@ extern const AVFilter ff_vf_geq; extern const AVFilter ff_vf_gradfun; extern const AVFilter ff_vf_graphmonitor; extern const AVFilter ff_vf_greyedge; +extern const AVFilter ff_vf_guided; extern const AVFilter ff_vf_haldclut; extern const AVFilter ff_vf_hflip; extern const AVFilter ff_vf_histeq; diff --git a/libavfilter/vf_guided.c b/libavfilter/vf_guided.c new file mode 100644 index 000..bd706fb --- /dev/null +++ b/libavfilter/vf_guided.c @@ -0,0 +1,429 @@ +/* + * Copyright (c) 2021 Xuewei Meng + * + * 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 + */ + +#include "libavutil/imgutils.h" +#include "libavutil/opt.h" +#include "libavutil/pixdesc.h" +#include "avfilter.h" +#include "formats.h" +#include "framesync.h" +#include "internal.h" +#include "video.h" + +typedef struct GuidedContext { +const AVClass *class; +FFFrameSync fs; + +int radius; +float eps; + +int planes; + +int width; +int height; + +int nb_planes; +int depth; +int planewidth[4]; +int planeheight[4]; + +int (*box_slice)(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs); +} GuidedContext; + +#define OFFSET(x) offsetof(GuidedContext, x) +#define FLAGS AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_RUNTIME_PARAM + +static const AVOption guided_options[] = { +{ "radius", "set the box radius", OFFSET(radius), AV_OPT_TYPE_INT, {.i64=3}, 1, 20, FLAGS }, +{ "eps","set the regularization parameter (with square)", OFFSET(eps),AV_OPT_TYPE_FLOAT, {.dbl=0.01 }, 0.0, 1, FLAGS }, +{ "planes", "set planes to filter", OFFSET(planes), AV_OPT_TYPE_INT, {.i64=1}, 0, 0xF, FLAGS }, +{ NULL } +}; +