[FFmpeg-devel] [PATCH] lavfi: edgedetect filter
Clément Bœsch
ubitux at gmail.com
Wed Aug 8 22:16:38 CEST 2012
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?
It might be interesting to move that stuff in a common place if possible
(since I'm not sure it's a good idea to put a swscale dependency for such
a trivial filter, and might be usable somewhere else in lavc or
something).
[...]
--
Clément B.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 490 bytes
Desc: not available
URL: <http://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20120808/7a5d4bbe/attachment.asc>
More information about the ffmpeg-devel
mailing list