TCannyMod: Difference between revisions
From Avisynth wiki
Jump to navigationJump to search
| (24 intermediate revisions by 3 users not shown) | |||
| Line 1: | Line 1: | ||
{{FilterCat5|External_filters|Plugins|Plugins_x64|Other_filters|Edge_detection}} | |||
{{ | |||
{{Filter3 | {{Filter3 | ||
| {{Author/Chikuzen}} | | {{Author/Chikuzen}} | ||
| | | v1.3.2 | ||
|[ | |[https://github.com/Asd-g/TCannyMod/releases TCannyMod-1.3.2.7z] | ||
| Edge Detection | | Edge Detection | ||
| [ | | [https://www.gnu.org/licenses/gpl-2.0.txt GPLv2] | ||
|6=[ | |6=[https://forum.doom9.org/showthread.php?t=168449 Doom9 Thread]}} | ||
== Description == | == Description == | ||
<tt>TCannyMod</tt> is a [https://en.wikipedia.org/wiki/Canny_edge_detector Canny edge detection] filter. It's based on <tt>[[tcanny]]</tt> written by Kevin Stone (a.k.a. tritical) but rewritten from scratch exclusively for AviSynth 2.6 / Avisynth+. | |||
*'''NOTE''': TCannyMod requires appropriate memory alignments. Thus, if you want to crop the left side of your source clip before this filter, you have to set <code>[[Crop|Crop(align=true)]]</code>. | |||
<br> | <br> | ||
== Requirements == | == Requirements == | ||
: | * [x86]: [[AviSynth+]] or [https://sourceforge.net/projects/avisynth2/ AviSynth 2.6] | ||
: | * [x64]: [[AviSynth+]] | ||
* Supported color formats: [[Y8]], [[YV12]], [[YV16]], [[YV24]], [[YV411]] | |||
<br> | <br> | ||
* [[SSE2]] capable CPU | |||
* [https://support.microsoft.com/en-us/help/2977003/the-latest-supported-visual-c-downloads Microsoft Visual C++ 2019 Redistributable Package (x86 / x64)] | |||
:<span style="color:red">***</span> <tt>vcredist_x86.exe</tt> required for <tt>TCannyMod-x86</tt> | |||
:<span style="color:red">***</span> <tt>vcredist_x64.exe</tt> required for <tt>TCannyMod-x64</tt> | |||
<br> | <br> | ||
== [[Script variables|Syntax and Parameters]] == | == [[Script variables|Syntax and Parameters]] == | ||
<br> | <br> | ||
| Line 26: | Line 31: | ||
<br> | <br> | ||
<br> | <br> | ||
:{{Template:FuncDef|TCannyMod (clip, int "mode", float "sigma", float "t_h", float "t_l", bool "sobel", int "chroma")}} | :{{Template:FuncDef|TCannyMod (clip, int "mode", float "sigma", float "t_h", float "t_l", bool "sobel", int "chroma", float "gmmax", int "opt")}} | ||
<br> | <br> | ||
::{{Par2| |clip| }} | ::{{Par2| |clip| }} | ||
| Line 34: | Line 39: | ||
:::Sets the output format: | :::Sets the output format: | ||
:::*0 : thresholded edge map (255 for edge, 0 for non-edge) | |||
:::*1 : gradient magnitude map. | |||
:::*2 : edge pixel only gradient direction map (non-edge pixels set to 0) | |||
:::*3 : gradient direction map | |||
::::Gradient direction are normalized to 31, 63, 127 and 255. | |||
::::: | :::::31 = horizontal | ||
::::: | :::::63 = 45' up | ||
::::: | :::::127 = vertical | ||
::::: | :::::255 = 45' down | ||
:::*4 : Gaussian blurred frame. | |||
<br> | <br> | ||
::{{Par2|sigma|float|1.5}} | ::{{Par2|sigma|float|1.5}} | ||
| Line 50: | Line 55: | ||
<br> | <br> | ||
::{{Par2|t_h|float|8.0}} | ::{{Par2|t_h|float|8.0}} | ||
::{{Par2|t_l|float|1.0}} | ::{{Par2|t_l|float|1.0}} | ||
::: | :::High and low gradient magnitude threshold for hysteresis; {{Template:FuncDef3|t_h}} must be greater than {{Template:FuncDef3|t_l}}. | ||
<br> | <br> | ||
::{{Par2|sobel|bool|false}} | ::{{Par2|sobel|bool|false}} | ||
| Line 61: | Line 64: | ||
:::Chroma processing: | :::Chroma processing: | ||
:::*0 : do not process | |||
:::*1 : process | |||
:::*2 : copy from input clip. | |||
:::*3 : fill with 0x80(128), output is grayscale. | |||
:::*4 : fill with 0. | |||
<br> | |||
::{{Par2|gmmax|float|255.0}} | |||
:::Used for scaling gradient magnitude into [0,255] for {{Template:FuncDef3|mode}}=1. | |||
:::{{Template:FuncDef3|gmmax}} is internally set to 1.0 if you set it to < 1.0. | |||
<br> | |||
::{{Par2|int|opt|-1}} | |||
:::Specify which CPU optimization are used: | |||
:::*0 - Use SSE2 + SSE routine. | |||
:::*1 - Use SSE4.1 + SSE2 + SSE routine if possible. If SSE4.1 can't be used, fallback to 0. | |||
:::Others - use AVX2 + FMA3 + AVX routine if possible. If AVX2 can't be used, fallback to 1. | |||
<br> | <br> | ||
------------- | ------------- | ||
<br> | <br> | ||
=== | |||
=== GBlur2 === | |||
Gaussian blur filter. Just an alias for {{Template:FuncDef3|TCannyMod}}<tt>(mode=4)</tt>. | Gaussian blur filter. Just an alias for {{Template:FuncDef3|TCannyMod}}<tt>(mode=4)</tt>. | ||
<br> | <br> | ||
<br> | <br> | ||
:{{Template:FuncDef| | :{{Template:FuncDef|GBlur2 (clip, float "sigma", int "chroma", int "opt")}} | ||
<br> | <br> | ||
::{{Par2| |clip| }} | ::{{Par2| |clip| }} | ||
| Line 84: | Line 99: | ||
:::Chroma processing: | :::Chroma processing: | ||
:::*0 : do not process | |||
::::*1 : process | :::*1 : process | ||
::::*2 : copy from input clip. | :::*2 : copy from input clip. | ||
:::*3 : fill with 0x80(128), output is grayscale. | |||
:::*4 : fill with 0. | |||
<br> | |||
::{{Par2|int|opt|-1}} | |||
:::Specify which CPU optimization are used: | |||
:::*0 - Use SSE2 + SSE routine. | |||
:::*1 - Use SSE4.1 + SSE2 + SSE routine if possible. If SSE4.1 can't be used, fallback to 0. | |||
:::Others - use AVX2 + FMA3 + AVX routine if possible. If AVX2 can't be used, fallback to 1. | |||
<br> | |||
=== EMask === | |||
Generate gradient magnitude edge map. Just an alias for {{Template:FuncDef3|TCannyMod}}<tt>(mode=1)</tt>. | |||
<br> | |||
<br> | |||
:{{Template:FuncDef|EMask (clip, float "sigma", float "gmmax", int "chroma", bool "sobel", int "opt")}} | |||
<br> | |||
::{{Par2| |clip| }} | |||
:::Input clip; only planar formats are supported. | |||
<br> | |||
::{{Par2|sigma|float|1.5}} | |||
:::Standard deviation of Gaussian blur. 0 means no blurring before edge detection. | |||
:::(0 <= sigma <= 2.83, default = 0.5) | |||
<br> | |||
::{{Par2|gmmax|float|50.0}} | |||
:::Used for scaling gradient magnitude into [0,255] for {{Template:FuncDef3|mode}}=1. | |||
:::{{Template:FuncDef3|gmmax}} is internally set to 1.0 if you set it to < 1.0. | |||
<br> | |||
::{{Par2|chroma|int|1}} | |||
:::Chroma processing: | |||
:::*0 : do not process | |||
:::*1 : process | |||
:::*2 : copy from input clip. | |||
:::*3 : fill with 0x80(128), output is grayscale. | |||
:::*4 : fill with 0. | |||
<br> | |||
::{{Par2|sobel|bool|false}} | |||
:::If set to <tt>true</tt>, edge detection will use a Sobel operator instead of [1, 0, -1]. | |||
<br> | |||
::{{Par2|int|opt|-1}} | |||
:::Specify which CPU optimization are used: | |||
:::*0 - Use SSE2 + SSE routine. | |||
:::*1 - Use SSE4.1 + SSE2 + SSE routine if possible. If SSE4.1 can't be used, fallback to 0. | |||
:::Others - use AVX2 + FMA3 + AVX routine if possible. If AVX2 can't be used, fallback to 1. | |||
<br> | <br> | ||
| Line 93: | Line 151: | ||
{{Template:FuncDef3|TCannyMod}} with default settings: | {{Template:FuncDef3|TCannyMod}} with default settings: | ||
[[AviSource]]("blah.avi") | [[AviSource]]("blah.avi") | ||
TCannyMod (mode=0, sigma=1.5, t_h=8.0, t_l=1.0, sobel=false, chroma=0) | TCannyMod (mode=0, sigma=1.5, t_h=8.0, t_l=1.0, sobel=false, chroma=0, gmmax=255.0, opt=-1) | ||
<br> | |||
{{Template:FuncDef3|GBlur2}} with default settings: | |||
[[AviSource]]("blah.avi") | |||
GBlur2 (sigma=0.5, chroma=1, opt=-1) | |||
<br> | <br> | ||
{{Template:FuncDef3| | {{Template:FuncDef3|EMask}} with default settings: | ||
[[AviSource]]("blah.avi") | [[AviSource]]("blah.avi") | ||
EMask (sigma=1.5, gmmax=50.0, chroma=0, sobel=false, opt=-1) | |||
<br> | <br> | ||
== Changelog == | == Changelog == | ||
Version Date Changes<br> | Version Date Changes<br> | ||
v1.3.2 2020/05/15 - Changes by asd-g | |||
- Change GBlur function name to GBlur2<br> | |||
v1.3.1 2020/05/13 - Changes by asd-g | |||
- Update to AviSynth+'s v8 interface<br> | |||
v1.3.0 07/04/2016 - Require AviSynth 2.6.0 / AviSynth+MT r2005 or later.<br> | |||
v1.2.0 05/25/2016 - Disable AVX2/FMA3/AVX code when /arch:AVX2 is not set. | |||
- Disable AVX2/FMA3/AVX code on Avisynth2.6. | |||
- Set filter mode as [[MT_NICE_FILTER]] on Avisynth+ MT. | |||
- Use buffer pool on Avisynth+ MT.<br> | |||
v1.1.1 04/03/2016 - Add AVX2 support for 32bit.<br> | |||
v1.1.0 03/28/2016 - Add EMask(). | |||
- Implement simd non-maximum-suppression. | |||
- a bit optimized gaussian-blur/ hysteresis.<br> | |||
v1.0.0 03/26/2016 - Almost rewrite. | |||
- VS2013 to VS2015. | |||
- Add AVX2(64bit only) / SSE4.1(both 32bit and 64bit) support. | |||
- Change direction values from 1,3,7,15 to 31,63,127,255. | |||
- Reduce waste processes.<br> | |||
v0.2.0 09/13/2015 - add option "gmmax" | |||
- update avisynth.h | |||
- VS2010 to VS2013 and code cosmetics<br> | |||
v0.1.1 08/21/2013 - fix crash when sigma is too large | v0.1.1 08/21/2013 - fix crash when sigma is too large | ||
- add new argument 'sobel' | - add new argument 'sobel' | ||
- add new function 'GBlur'<br> | - add new function 'GBlur'<br> | ||
v0.1.0 08/017/2013 - Initial release | v0.1.0 08/017/2013 - Initial release | ||
<br> | <br> | ||
== External Links == | == External Links == | ||
*[ | *[https://github.com/chikuzen/TCannyMod/tree/master/avisynth GitHub] - Source code repository. | ||
*[ | *[https://github.com/Asd-g/TCannyMod/tree/v8_interface/avisynth GitHub] - Source code repository (update). | ||
*[https://forum.doom9.org/showthread.php?t=168449 Doom9 Forum] - TCannyMod discussion. | |||
<br> | <br> | ||
<br> | <br> | ||
----------------------------------------------- | ----------------------------------------------- | ||
'''Back to [[External_filters#Edge_Detection|External Filters]] ←''' | '''Back to [[External_filters#Edge_Detection|External Filters]] ←''' | ||
Latest revision as of 01:46, 22 May 2020
| Abstract | |
|---|---|
| Author | Chikuzen |
| Version | v1.3.2 |
| Download | TCannyMod-1.3.2.7z |
| Category | Edge Detection |
| License | GPLv2 |
| Discussion | Doom9 Thread |
Description
TCannyMod is a Canny edge detection filter. It's based on tcanny written by Kevin Stone (a.k.a. tritical) but rewritten from scratch exclusively for AviSynth 2.6 / Avisynth+.
- NOTE: TCannyMod requires appropriate memory alignments. Thus, if you want to crop the left side of your source clip before this filter, you have to set
Crop(align=true).
Requirements
- [x86]: AviSynth+ or AviSynth 2.6
- [x64]: AviSynth+
- Supported color formats: Y8, YV12, YV16, YV24, YV411
- *** vcredist_x86.exe required for TCannyMod-x86
- *** vcredist_x64.exe required for TCannyMod-x64
TCannyMod
Builds an edge map using Canny edge detection.
- TCannyMod (clip, int "mode", float "sigma", float "t_h", float "t_l", bool "sobel", int "chroma", float "gmmax", int "opt")
- clip =
- Input clip; only planar formats are supported.
- clip =
- int mode = 0
- Sets the output format:
- int mode = 0
- 0 : thresholded edge map (255 for edge, 0 for non-edge)
- 1 : gradient magnitude map.
- 2 : edge pixel only gradient direction map (non-edge pixels set to 0)
- 3 : gradient direction map
- Gradient direction are normalized to 31, 63, 127 and 255.
- 31 = horizontal
- 63 = 45' up
- 127 = vertical
- 255 = 45' down
- 4 : Gaussian blurred frame.
- float sigma = 1.5
- Standard deviation of Gaussian blur. 0 means no blurring before edge detection.
- (0 <= sigma <= 2.83, default = 1.5)
- float sigma = 1.5
- float t_h = 8.0
- float t_l = 1.0
- High and low gradient magnitude threshold for hysteresis; t_h must be greater than t_l.
- float t_h = 8.0
- bool sobel = false
- If set to true, edge detection will use a Sobel operator instead of [1, 0, -1].
- bool sobel = false
- int chroma = 0
- Chroma processing:
- int chroma = 0
- 0 : do not process
- 1 : process
- 2 : copy from input clip.
- 3 : fill with 0x80(128), output is grayscale.
- 4 : fill with 0.
- float gmmax = 255.0
- Used for scaling gradient magnitude into [0,255] for mode=1.
- gmmax is internally set to 1.0 if you set it to < 1.0.
- float gmmax = 255.0
- opt int = -1
- Specify which CPU optimization are used:
- 0 - Use SSE2 + SSE routine.
- 1 - Use SSE4.1 + SSE2 + SSE routine if possible. If SSE4.1 can't be used, fallback to 0.
- Others - use AVX2 + FMA3 + AVX routine if possible. If AVX2 can't be used, fallback to 1.
- Specify which CPU optimization are used:
- opt int = -1
GBlur2
Gaussian blur filter. Just an alias for TCannyMod(mode=4).
- GBlur2 (clip, float "sigma", int "chroma", int "opt")
- clip =
- Input clip; only planar formats are supported.
- clip =
- float sigma = 0.5
- Standard deviation of Gaussian blur. 0 means no blurring before edge detection.
- (0 <= sigma <= 2.83, default = 0.5)
- float sigma = 0.5
- int chroma = 1
- Chroma processing:
- int chroma = 1
- 0 : do not process
- 1 : process
- 2 : copy from input clip.
- 3 : fill with 0x80(128), output is grayscale.
- 4 : fill with 0.
- opt int = -1
- Specify which CPU optimization are used:
- 0 - Use SSE2 + SSE routine.
- 1 - Use SSE4.1 + SSE2 + SSE routine if possible. If SSE4.1 can't be used, fallback to 0.
- Others - use AVX2 + FMA3 + AVX routine if possible. If AVX2 can't be used, fallback to 1.
- Specify which CPU optimization are used:
- opt int = -1
EMask
Generate gradient magnitude edge map. Just an alias for TCannyMod(mode=1).
- EMask (clip, float "sigma", float "gmmax", int "chroma", bool "sobel", int "opt")
- clip =
- Input clip; only planar formats are supported.
- clip =
- float sigma = 1.5
- Standard deviation of Gaussian blur. 0 means no blurring before edge detection.
- (0 <= sigma <= 2.83, default = 0.5)
- float sigma = 1.5
- float gmmax = 50.0
- Used for scaling gradient magnitude into [0,255] for mode=1.
- gmmax is internally set to 1.0 if you set it to < 1.0.
- float gmmax = 50.0
- int chroma = 1
- Chroma processing:
- int chroma = 1
- 0 : do not process
- 1 : process
- 2 : copy from input clip.
- 3 : fill with 0x80(128), output is grayscale.
- 4 : fill with 0.
- bool sobel = false
- If set to true, edge detection will use a Sobel operator instead of [1, 0, -1].
- bool sobel = false
- opt int = -1
- Specify which CPU optimization are used:
- 0 - Use SSE2 + SSE routine.
- 1 - Use SSE4.1 + SSE2 + SSE routine if possible. If SSE4.1 can't be used, fallback to 0.
- Others - use AVX2 + FMA3 + AVX routine if possible. If AVX2 can't be used, fallback to 1.
- Specify which CPU optimization are used:
- opt int = -1
Examples
TCannyMod with default settings:
AviSource("blah.avi") TCannyMod (mode=0, sigma=1.5, t_h=8.0, t_l=1.0, sobel=false, chroma=0, gmmax=255.0, opt=-1)
GBlur2 with default settings:
AviSource("blah.avi") GBlur2 (sigma=0.5, chroma=1, opt=-1)
EMask with default settings:
AviSource("blah.avi") EMask (sigma=1.5, gmmax=50.0, chroma=0, sobel=false, opt=-1)
Changelog
Version Date Changes
v1.3.2 2020/05/15 - Changes by asd-g - Change GBlur function name to GBlur2
v1.3.1 2020/05/13 - Changes by asd-g - Update to AviSynth+'s v8 interface
v1.3.0 07/04/2016 - Require AviSynth 2.6.0 / AviSynth+MT r2005 or later.
v1.2.0 05/25/2016 - Disable AVX2/FMA3/AVX code when /arch:AVX2 is not set. - Disable AVX2/FMA3/AVX code on Avisynth2.6. - Set filter mode as MT_NICE_FILTER on Avisynth+ MT. - Use buffer pool on Avisynth+ MT.
v1.1.1 04/03/2016 - Add AVX2 support for 32bit.
v1.1.0 03/28/2016 - Add EMask(). - Implement simd non-maximum-suppression. - a bit optimized gaussian-blur/ hysteresis.
v1.0.0 03/26/2016 - Almost rewrite. - VS2013 to VS2015. - Add AVX2(64bit only) / SSE4.1(both 32bit and 64bit) support. - Change direction values from 1,3,7,15 to 31,63,127,255. - Reduce waste processes.
v0.2.0 09/13/2015 - add option "gmmax" - update avisynth.h - VS2010 to VS2013 and code cosmetics
v0.1.1 08/21/2013 - fix crash when sigma is too large - add new argument 'sobel' - add new function 'GBlur'
v0.1.0 08/017/2013 - Initial release
External Links
- GitHub - Source code repository.
- GitHub - Source code repository (update).
- Doom9 Forum - TCannyMod discussion.
Back to External Filters ←