From patchwork Sat Nov 5 15:26:13 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?b?Q2zDqW1lbnQgQsWTc2No?= X-Patchwork-Id: 39174 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a21:999a:b0:a4:2148:650a with SMTP id ve26csp1085795pzb; Sat, 5 Nov 2022 08:28:14 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4tkwKni68LGTDizXUq+xYFhRBBGtBdZ2DYdfyDlq5z4bcHbvmUV3wupoNbGq2GTsc1QOjt X-Received: by 2002:a05:6402:5187:b0:461:ac01:7512 with SMTP id q7-20020a056402518700b00461ac017512mr40644760edd.327.1667662094189; Sat, 05 Nov 2022 08:28:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667662094; cv=none; d=google.com; s=arc-20160816; b=b1uLw5+tA3V2CeAtXdoR7yrPPirhoPiEvC10gvxlNEPTzeREsCkEkc9sqEzmSbWSIX uubnxqkvdc80jui8Cfw5cFwyPYaoElgp1qFOJNFqzzZ3bX3ae2UllB4bc5fiKPcFkFTb rP+nfoTq3RY3uwop1JftMpWU8eKQ8lGUjcbtZbTUmFwlCZT/gmqHCfqns4Ds5F167afe 3f3TjStnZpPZkKQrxp8ID+sPOUujg6osmo/K8doNnwphaaV6fBy+OjBfCaW546+dbLLl mkwmmNcfuEIUXzwBXT1igpIoc6rPmqgoSTrP0vnhRQ7Q+vB87eaEcb7kmcM6VUgkWkxF XTqw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:mime-version:references:in-reply-to :message-id:date:to:from:dkim-signature:delivered-to; bh=plOhObQPp3XbCXdA4wXh1rbNxeGCvnN7LSsVrd+HisU=; b=zLIHjU3SilJQfwnSjzTkAv+HZMHxsZ8TEoxphUSPKgWpcmas0VN8/I+hEmD97ORMQZ JUbMgBXmb/REb8xjT3FeUWaZ2Ea+qbsYvOC+NCR1NaCCgRfTshrWRlF8V8yxAo+8ga+8 DqX8kspgCnyFLYuyHdMN6Ci6N07FOXW3v+orQMqqxuwx82XtoaCHAbsW5TA1miEfNhJA +BNP6ftGB+BqroZfKGli21SRzc6iqznsjw55R6s/Wy6l5XVa6/FiqejWbPjlGPsl71JT t4XcFer3DVJnoXxeimliT3DrWSqLejxNeJEOHVx9aobN8Ov85rf2LTbZRy+MVLbRoEPS EIKw== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@pkh.me header.s=selector1 header.b=X6x1gqUj; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=pkh.me Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id b8-20020a056402278800b0045928479b71si3731361ede.405.2022.11.05.08.28.13; Sat, 05 Nov 2022 08:28:14 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@pkh.me header.s=selector1 header.b=X6x1gqUj; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=pkh.me Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 873E468B663; Sat, 5 Nov 2022 17:26:46 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from ssq0.pkh.me (laubervilliers-656-1-228-164.w92-154.abo.wanadoo.fr [92.154.28.164]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 4DD5A68B3E7 for ; Sat, 5 Nov 2022 17:26:41 +0200 (EET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pkh.me; s=selector1; t=1667661982; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=n1OyaAQq87iiEE2XLvuqG94Vopy9hh+rhmOfKdxlAxA=; b=X6x1gqUjSpI3mCUa1Qp42jvBG7NMSNswP7OxudmHsE3wqdv4iiDeK56W15Q9ou/kQLohl1 YSXDHry4WCOjcWVgtnvhNd3wduR0Cl+mK6j/06ZyPl/REIfLjdaK1q/GFb8bNSTNUPEcLr oC9zk5yPTyBcGiQ22NfVVMoXzKFTY7M= Received: from localhost (ssq0.pkh.me [local]) by ssq0.pkh.me (OpenSMTPD) with ESMTPA id 66408e5d; Sat, 5 Nov 2022 15:26:22 +0000 (UTC) From: =?utf-8?b?Q2zDqW1lbnQgQsWTc2No?= To: ffmpeg-devel@ffmpeg.org Date: Sat, 5 Nov 2022 16:26:13 +0100 Message-Id: <20221105152617.1809282-12-u@pkh.me> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20221105152617.1809282-1-u@pkh.me> References: <20221105152617.1809282-1-u@pkh.me> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 11/15] avfilter/palettegen: comment on the unnormalized variance X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Cc: =?utf-8?b?Q2zDqW1lbnQgQsWTc2No?= Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: P10qLMo01PzD --- libavfilter/vf_palettegen.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/libavfilter/vf_palettegen.c b/libavfilter/vf_palettegen.c index 2b412cdb55..b8e4463539 100644 --- a/libavfilter/vf_palettegen.c +++ b/libavfilter/vf_palettegen.c @@ -152,6 +152,24 @@ static void compute_box_variance(PaletteGenContext *s, struct range_box *box) const struct color_ref *ref = s->refs[box->start + i]; variance += diff(ref->color, box->color) * ref->count; } + /* + * The variance is computed as a Mean Squared Error of the distance of the + * current color to the box color average, with an important difference: + * the final sum is not normalized using the total weight of the box (the + * sum of the ref->count). + * + * One may expect that in order to compare the variance of the boxes + * between each others a normalization makes sense. Unfortunately, the + * normalization has the side effect of taking the "size" of the box out of + * the equation. In practice, this has a tendency to cause dramatic banding + * effects (in particular without dithering). Typically a scene where the + * sky is omnipresent may get much less colors assigned than its + * surroundings. + * + * Not normalizing causes a bias towards boxes with many colors, but that's + * exactly what we want. The downside is that vivid/accent colors found in + * small quantities tend to disappear. + */ box->variance = variance; }