[FFmpeg-devel] Add alternative delogo algorithm for my donation
uwe.freese at gmx.de
uwe.freese at gmx.de
Thu Dec 13 08:55:35 EET 2018
Hello Kyle,
> You should also try vf_removelogo. It is supposedly better than the
> more simple vf_delogo.
I tried (with a box in a PNG mask as logo cover).
That is no alternative both quality wise and from usability point of view:
1. It gave me blurry borders with several pixels widths from outside to
the inner. They were very symmetrical and showed a 45 degree "lines"
from the edges to the middle. Hardly the nice blurred box I wanted.
2. If you want to cover the logo by simple coordinates (a box), it's
unnecessary effort to create a PNG mask with that box in it instead of
giving the coordinates as parameter.
Because removelogo can handle arbitrary masks and the calculation I
posted is using a simple rectangular box (and this is my typical use
case), I suggested to add it to the "delogo" filter.
So my offer stands, would be nice if someone can add this additional mode.
>> Here's the relevant code to add (+ some config variable to set the mode
>> I guess):
>>
>> // Precalculate weights once.
>> void TimgFilterLogoaway::Tplane::calcUweWeightTable(int w, int h, int power)
>> {
>> double e = 1.0 + (0.3 * power);
>> int x;
>> for (x = 0; x < w; x++)
>> for (int y = 0; y < h; y++)
>> if (x + y != 0) {
>> double d = pow(sqrt(double(x * x + y * y)), e);
>> uwetable[x + y * w] = 1.0 / d;
>> } else {
>> uwetable[x + y * w] = 1.0;
>> }
>>
>> for (x = 1; x < w - 1; x++)
>> for (int y = 1; y < h - 1; y++) {
>> double weightsum = 0;
>> for (int bx = 0; bx < w; bx++) {
>> weightsum += uwetable[abs(bx - x) + y * w];
>> weightsum += uwetable[abs(bx - x) + abs(h - 1 - y) * w];
>> }
>> for (int by = 1; by < h - 1; by++) {
>> weightsum += uwetable[x + abs(by - y) * w];
>> weightsum += uwetable[abs(w - 1 - x) + abs(by - y) * w];
>> }
>> uweweightsum[y * w + x] = weightsum;
>> }
>> }
>>
>> // apply filter
>> void TimgFilterLogoaway::Tplane::uwe(const TlogoawaySettings *cfg)
>> {
>> if (!uwetable) {
>> uwetable = (double*)aligned_malloc(w * h * sizeof(double));
>> uweweightsum = (double*)aligned_malloc(w * h * sizeof(double));
>> calcUweWeightTable(w, h, cfg->blur);
>> }
>>
>> for (int x = 1; x < w - 1; x++)
>> for (int y = 1; y < h - 1; y++) {
>> double r = 0;
>> const unsigned char *lineN = bordn, *lineS = bords;
>> for (int bx = 0; bx < w; bx++) {
>> r += lineN[bx] * uwetable[abs(bx - x) + y * w];
>> r += lineS[bx] * uwetable[abs(bx - x) + abs(h - 1 - y)
>> * w];
>> }
>> const unsigned char *lineW = bordw, *lineE = borde;
>> for (int by = 1; by < h - 1; by++) {
>> r += lineW[by] * uwetable[x + abs(by - y) * w];
>> r += lineE[by] * uwetable[abs(w - 1 - x) + abs(by - y)
>> * w];
>> }
>> logotempdata[y * logotempstride + x] = uint8_t(r /
>> uweweightsum[y * w + x]);
>> }
>>
>> }
>>
>>
>> Regards,
>> Uwe
>>
>> _______________________________________________
>> ffmpeg-devel mailing list
>> ffmpeg-devel at ffmpeg.org
>> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>>
> Thanks,
> Kyle
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel at ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
More information about the ffmpeg-devel
mailing list