[FFmpeg-devel] [PATCH] lavfi: edgedetect filter

Michael Niedermayer michaelni at gmx.at
Thu Aug 9 01:33:01 CEST 2012


On Wed, Aug 08, 2012 at 10:16:38PM +0200, Clément Bœsch wrote:
> On Wed, Aug 08, 2012 at 03:42:20PM +0200, Michael Niedermayer wrote:
> > Hi
> > 
> > On Wed, Aug 08, 2012 at 02:12:02PM +0200, Clément Bœsch wrote:
> > > On Wed, Aug 08, 2012 at 12:55:15PM +0200, Stefano Sabatini wrote:
> > > [...]
> > > > > +static void gaussian_blur(AVFilterContext *ctx, int w, int h,
> > > > > +                                uint8_t *dst, int dst_linesize,
> > > > > +                          const uint8_t *src, int src_linesize)
> > > > > +{
> > > > > +    int i, j;
> > > > > +
> > > > > +    memcpy(dst, src, w); dst += dst_linesize; src += src_linesize;
> > > > > +    memcpy(dst, src, w); dst += dst_linesize; src += src_linesize;
> > > > > +    for (j = 2; j < h - 2; j++) {
> > > > > +        dst[0] = src[0];
> > > > > +        dst[1] = src[1];
> > > > > +        for (i = 2; i < w - 2; i++) {
> > > > > +            dst[i] = ((src[-2*src_linesize + i-2] + src[2*src_linesize + i-2]) * 2
> > > > > +                    + (src[-2*src_linesize + i-1] + src[2*src_linesize + i-1]) * 4
> > > > > +                    + (src[-2*src_linesize + i  ] + src[2*src_linesize + i  ]) * 5
> > > > > +                    + (src[-2*src_linesize + i+1] + src[2*src_linesize + i+1]) * 4
> > > > > +                    + (src[-2*src_linesize + i+2] + src[2*src_linesize + i+2]) * 2
> > > > > +
> > > > > +                    + (src[  -src_linesize + i-2] + src[  src_linesize + i-2]) *  4
> > > > > +                    + (src[  -src_linesize + i-1] + src[  src_linesize + i-1]) *  9
> > > > > +                    + (src[  -src_linesize + i  ] + src[  src_linesize + i  ]) * 12
> > > > > +                    + (src[  -src_linesize + i+1] + src[  src_linesize + i+1]) *  9
> > > > > +                    + (src[  -src_linesize + i+2] + src[  src_linesize + i+2]) *  4
> > > > > +
> > > > > +                    + src[i-2] *  5
> > > > > +                    + src[i-1] * 12
> > > > > +                    + src[i  ] * 15
> > > > > +                    + src[i+1] * 12
> > > > > +                    + src[i+2] *  5) / 159;
> > > > > +        }
> > > > 
> > > > My feeling is that we should avoid to hardcode convolution operations,
> > > > and write generic code for it. Also we may want to make the size of
> > > > the gaussian mask parametric, as well as the sigma parameter used to
> > > > compute the mask.
> > > > 
> > > > Convolution operations are useful per-se, and could be used to
> > > > implement ad-hoc filters.
> > > > 
> > > 
> > > I've just used the standard matrix for that algorithm; from a performance
> > > point of view it also has some benefits. Note that it is relatively
> > > trivial to write so I'm not sure such generic code would be required.
> > > Maybe we could macro-generate various version of that but I'm not sure
> > > that's really important in that case.
> > > 
> > > This step really is just to quickly get rid of some noise.
> > > 
> > > Do we have already use these in some other filters?
> > 
> > swscale can apply generic seperably (in 1D H/V) convolutions.
> > 
> 
> Interesting; is that part of the public API?

yes
see libavfilter/libmpcodecs/vf_smartblur.c on a filter using it


[...]

-- 
Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

It is dangerous to be right in matters on which the established authorities
are wrong. -- Voltaire
-------------- 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/20120809/9ca0dea2/attachment.asc>


More information about the ffmpeg-devel mailing list