From patchwork Mon Jun 22 15:29:21 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Valery Kot X-Patchwork-Id: 20555 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id 7952644B456 for ; Mon, 22 Jun 2020 18:29:41 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 62CA568B903; Mon, 22 Jun 2020 18:29:41 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-ot1-f48.google.com (mail-ot1-f48.google.com [209.85.210.48]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 9161B68B8C7 for ; Mon, 22 Jun 2020 18:29:34 +0300 (EEST) Received: by mail-ot1-f48.google.com with SMTP id s13so13376589otd.7 for ; Mon, 22 Jun 2020 08:29:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:from:date:message-id:subject:to; bh=gcW7HWERxgyW9zwKDiviUs0dy96LUTPRuhUQ/aLm87A=; b=KsylXqUiYxuffZgO2vR1KCFD+ltKspNKwbKrkgREEpx4QESIdv8icj9v6uiPpy+d7P BRLpg3Afs+VDBxKscmLY9NstYoRIVC9dsSb2s7oriT33MM6AKN68mEXnI0EjJzIixM5F hTUpxG0EOGfmj6x/Qbid60+cCTazct3k9dARea+tmvXB8mbH0dCmBXcjoHGEWLMVrUGz gDYhA5e/8F5X8k4FR7904bi2SIF/dkEt/ytoFJdXf+7IPaGCQn+WgmEvxGylnFLL8bm0 mJjHPV5gwbRHffbbP8FTuh14i/GnIbpDVcqQ/uVRypo6hxJaetRDsjKi5qWzxCGp//gk YcOQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:from:date:message-id:subject:to; bh=gcW7HWERxgyW9zwKDiviUs0dy96LUTPRuhUQ/aLm87A=; b=qG/kfXRkQ/v8Lc2b2CoNRe9SbnhMOoGKyrNs0hTUDaLMgqBb9d9RsXTq/IIEt47Jpc 3+cAzMlmj6FihOWunmVbExnKujiAYQLThnbfNd+bM0d9LcrSkIntMYkdOBfJgZGi+Dka gKTfj+ukqNtroBQAQF1CYYhnjhyNnmKhCHF9aZo16rUkisgU7S02eVXof9U7OecFT06I 6XIpr+cYFibAPUxqyW2I0uG5pVYasZ/mWfZ/sbqzNWB98ZLYtln6lrxBK3eOsc6Ljh5I KR8vWTu8TjU8i5m1jLhcq+kBfmHV4DwdLuPRjvGV8SMs3tjZ2SxIXA4sj5NlIc0dT6/h Wqsw== X-Gm-Message-State: AOAM533DmUj5wedS883PRIWXIWz9+n8Y7oTtrrWYnzsiIeFS6HqIIZp+ rq1g04xw4JtHTiWjeSAu2yEL91vHZl2OnyZCw/JZSkoQ X-Google-Smtp-Source: ABdhPJw3429L1YfDWy6KsC13E1U3Xi7QkCOa/APVU1+SZf1WuMN83ZdCT8j2b4Mq+EStWzpyLCzgmZfsWTsBpIrP0Lk= X-Received: by 2002:a05:6830:1613:: with SMTP id g19mr14700677otr.199.1592839772692; Mon, 22 Jun 2020 08:29:32 -0700 (PDT) MIME-Version: 1.0 From: Valery Kot Date: Mon, 22 Jun 2020 17:29:21 +0200 Message-ID: To: FFmpeg development discussions and patches Subject: [FFmpeg-devel] [PATCH v2] avfilter/vf_edgedetect: properly implement double_threshold() X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 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 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" === Version 1 === vf_edgedetect video filter implements Canny algorithm (https://en.wikipedia.org/wiki/Canny_edge_detector) Important part of this algo is the double threshold step: pixels above "high" threshold being kept, pixels below "low" threshold dropped, pixels in between kept if they are attached to "high" pixels. This is implemented in the double_threshold() function. However, condition to start checking attached pixels, as it is now and as it was in FFmpeg since 2012, only allows checking on the boundary, not inside the video. It is a very lucky coincidence that those boundary pixels are always 0, otherwise following lines would be reading outside of the buffer. As it is now, double_threshold() only implements "high" thresholding. As a result, edges are either noisy or fragmented, depending on "high" threshold selection; "low" threshold is simply ignored. Attached one char patch fixes this. === Version 2 === - include avfilter/ in commit message - update FATE tests From 69bbe24bfe23efa3874448f28451b1abaa209d5d Mon Sep 17 00:00:00 2001 From: vkot Date: Fri, 19 Jun 2020 16:57:13 +0200 Subject: [PATCH] avfilter/vf_edgedetect: properly implement double_threshold() --- libavfilter/vf_edgedetect.c | 2 +- tests/ref/fate/filter-edgedetect | 2 +- tests/ref/fate/filter-edgedetect-colormix | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/libavfilter/vf_edgedetect.c b/libavfilter/vf_edgedetect.c index a5614ea63b..df8afbd532 100644 --- a/libavfilter/vf_edgedetect.c +++ b/libavfilter/vf_edgedetect.c @@ -294,7 +294,7 @@ static void double_threshold(int low, int high, int w, int h, continue; } - if ((!i || i == w - 1 || !j || j == h - 1) && + if (!(!i || i == w - 1 || !j || j == h - 1) && src[i] > low && (src[-src_linesize + i-1] > high || src[-src_linesize + i ] > high || diff --git a/tests/ref/fate/filter-edgedetect b/tests/ref/fate/filter-edgedetect index 23c9953e61..e49639afac 100644 --- a/tests/ref/fate/filter-edgedetect +++ b/tests/ref/fate/filter-edgedetect @@ -1 +1 @@ -edgedetect 93ceace33f6636bcdbeb037317c65745 +edgedetect 04ff46bb35edff3dbad4102391516d25 diff --git a/tests/ref/fate/filter-edgedetect-colormix b/tests/ref/fate/filter-edgedetect-colormix index e828c6bd19..0df17344bc 100644 --- a/tests/ref/fate/filter-edgedetect-colormix +++ b/tests/ref/fate/filter-edgedetect-colormix @@ -1 +1 @@ -edgedetect-colormix 1b8658252e2f03fbae30e6d63dd24c7c +edgedetect-colormix 9f50c5586f899a8f5a10059154d64bde