From patchwork Fri Jun 19 15:15:06 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Valery Kot X-Patchwork-Id: 20505 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 D5BA244ABAE for ; Fri, 19 Jun 2020 18:15:25 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id C1B7368B75F; Fri, 19 Jun 2020 18:15:25 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-ot1-f53.google.com (mail-ot1-f53.google.com [209.85.210.53]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 2B66268B6F8 for ; Fri, 19 Jun 2020 18:15:19 +0300 (EEST) Received: by mail-ot1-f53.google.com with SMTP id v13so7544487otp.4 for ; Fri, 19 Jun 2020 08:15:19 -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=xZoAHxhZT0pbu/lDmhq3KRXUrvG3x+Bfj6UJ12JW6mM=; b=GAn2jMMJk7uZpeBwODMTIlnbBNoJCuaE3qe6mSyGYdaFpuqILeDJUD05xjE+we+5ew n/VQLObOhJ1fmdhIt4z032JbnBuN2djYuQefaEkvrubln8FHf6gJEpr2D8B+dCag5WUI 7koND/VRp6mbsEuWWdvytPrujcSf/AyP2EJICUQDxD7tKatqTdr5w+oRHAZizzEFyCBB TLbxqf0B1CeZQLOH0MFnV552jp4biebHT/sJABKvQj3CWQHbRPKwulDPEBl+Px1i2aL7 Li5vm/JTtTO33s1RKjbfQXgmw+T5Tx3lQTeQefH5R41YwvI2HWUVTVnvqOKo4BBhKjgl nxoA== 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=xZoAHxhZT0pbu/lDmhq3KRXUrvG3x+Bfj6UJ12JW6mM=; b=V74+WYuqXLT9f7BQ+F7sZexWigABfu9ri3n8H3Y8AXWrvG6tGrijmcdUNOlWNuTsTi nirietLV2lzi+z8YxFgLn2k1DSVpT6tvf2RF+0ioM7o5B6rYJJsUZXeQ/R/lDmVVOwjh yQiYBbBaGRJFNbVWfSwt/9uQOHB4/cHkypKZlpcI9Fq2cqVQEycwb4JWiiOH5N2XJ0fI sTkpvM/uVW4dLkKekMTuxGSnRFBRxkA1wp+7jtKxg+sqJ3tQRs2LwXK4GuZI7VDxEJWX qM5R55VOb0OY0PXiALxLsYGDrd3KMG9RlFYt+sTI1vrEP+hl+zvKfEnKwyfLmiXInnVu rvUg== X-Gm-Message-State: AOAM531KmgGk+zltEuoz2JvPg48jR6+L+JBu6edWc+i1Pc0MlkfTdW1x +275xVk1GVSfp/0mJgttcsDzSgucR4OyOw5verHbh6Dz X-Google-Smtp-Source: ABdhPJyMj8mtj20Z3hAfqO3uMLkAMBgbKVtyDWo4+Y9K9xLKCunZHFLekEE10V+NvxrZkmPNmYAc6HAF90yMnO6RF/k= X-Received: by 2002:a9d:a34:: with SMTP id 49mr3529144otg.204.1592579717153; Fri, 19 Jun 2020 08:15:17 -0700 (PDT) MIME-Version: 1.0 From: Valery Kot Date: Fri, 19 Jun 2020 17:15:06 +0200 Message-ID: To: FFmpeg development discussions and patches Subject: [FFmpeg-devel] [Patch] 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" 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. Please review. Valery From b78f5960736de52d1c8e41bd598a465092c1de60 Mon Sep 17 00:00:00 2001 From: vkot Date: Fri, 19 Jun 2020 16:57:13 +0200 Subject: [PATCH] vf_edgedetect: properly implement double_threshold() --- libavfilter/vf_edgedetect.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 ||