[FFmpeg-devel] [PATCH V2] lavfi/vf_nlmeans: Improve the performance for nlmeans

Clément Bœsch u at pkh.me
Fri Feb 1 11:43:32 EET 2019


On Fri, Feb 01, 2019 at 05:19:53PM +0800, mypopy at gmail.com wrote:
> On Fri, Feb 1, 2019 at 5:11 PM Clément Bœsch <u at pkh.me> wrote:
> >
> > On Fri, Feb 01, 2019 at 04:57:37PM +0800, mypopy at gmail.com wrote:
> > [...]
> > > > > -#define WEIGHT_LUT_NBITS 9
> > > > > -#define WEIGHT_LUT_SIZE  (1<<WEIGHT_LUT_NBITS)
> > > > > +#define WEIGHT_LUT_SIZE  (800000) // need to >  300 * 300 *
> log(255)
> > > >
> > > > So the LUT is now 3.2MB?
> > > >
> > > > Why 300? 300*300*log(255) is closer to 500 000 than 800 000
> > > I just seleted a value > 300*300*log(255) (500 000 more precise) for
> > > this case at liberty in fact , the other option is use a dynamic
> > > allocation memory for weight_lut table size base on the
> > > max_meaningful_diff :), but maybe seems pretty obvious, I think 3M is
> > > not a big burden for nlmeans
> >
> > It's probably fine yes, I'm just confused at the comment: why does it
> > *needs* to be > 300 * 300 * log(255)?
> >
> > --
> ohhh, 300 = max(s) * 10 :), max(s) = 30, this is the reason.
> 
> In fact, max size of WEIGHT_LUT_SIZE ==  max (max_meaningful_diff), then we
> can avoid use pdiff_lut_scale in nlmeans, becasue now pdiff_lut_scale == 1.
> :)
> 
> and max( max_meaningful_diff ) = -log(-1/255.0) * h * h = log(255) * max
> (h) * max(h) = log(255) * max (10*s) * max(10*s)

Ok, makes sense. Would you mind updating the comment to something like:

    /* Note: WEIGHT_LUT_SIZE must be larger than max_meaningful_diff
     * (log(255)*max(h)^2, which is approximately 500000 with the current
     * maximum sigma of 30). The current value is arbitrary and could be
     * tweaked or defined dynamically. */
    #define WEIGHT_LUT_SIZE 800000

I will test your patch tonight (let's say in about 10 hours given my
current timezone) and apply if everything works fine.

Thanks

-- 
Clément B.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 488 bytes
Desc: not available
URL: <http://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20190201/bb2bbb03/attachment.sig>


More information about the ffmpeg-devel mailing list