Subtract

From Avisynth wiki
(Difference between revisions)
Jump to: navigation, search
(synced with offline docs)
 
m (add link)
 
(5 intermediate revisions by 2 users not shown)
Line 1: Line 1:
{{Template:FuncDef|Subtract(clip1 ''clip'', clip2 ''clip'')}}
+
Show the difference between two clips. Where the clips are equal, the output is 50% grey.<br>
 +
See [[filters with multiple input clips]] for the resulting [[Clip_properties|clip properties]].
  
Subtract produces an output clip in which every pixel is set according to the difference between the corresponding pixels in clip1 and clip2. More specifically, it sets each pixel to (50% grey) + (clip1 pixel) - (clip2 pixel). You can use [[Levels]] afterwards if you want to increase the contrast.
+
==== Syntax ====
 +
{{Template:FuncDef|Subtract(clip ''clip1'', clip ''clip2'')}}
  
'''Examples:'''
+
==== Examples ====
 +
<div style="max-width:62em" >
 +
Show the difference between two clips, and make the difference blatantly obvious:
 +
<div {{BoxWidthIndent|46|2}} >
 +
Subtract(A, B).[[Levels]](65, 1, 255-64, 0, 255, coring=false)
 +
</div>
  
# make the differences between clip1 and clip2 blatantly obvious:
+
Show the difference between adjacent frames:
  Subtract(clip1, clip2).Levels(127, 1, 129, 0, 255)
+
<div {{BoxWidthIndent|46|2}} >
 +
  Subtract(A, A.[[Trim]](1, 0))
 +
</div>
  
If you want to see the deltas between adjacent frames in a single clip, you can do it like this:
+
==== About offset of luma range ====
  
  Subtract(clip.Trim(1, 0), clip)
+
For YUV formats the valid ''Y'' range is 16-235, and '''Subtract''' takes this into account. This means that the following script
 +
<div {{BoxWidthIndent|46|2}} >
 +
  Subtract(A, B)
 +
</div>
 +
...will result in a "50% grey" clip with luma=126.
  
'''About offset of luma range:'''
+
If you require a mathematically correct ''subtract'' function for 0-255 RGB or YUV data, use [[Overlay]]:
 
+
<div {{BoxWidthIndent|46|2}} >
For YUV formats the valid Y range is from 16 to 235 inclusive and subtract takes this into account. This means that the following script
+
  Overlay(A, B, mode="difference", pc_range=false)
 
+
</div>
Subtract(any_clip, any_clip)
+
...which results in a "50% grey" clip with luma=128.
 
+
will result in a grey clip with luma = 126. For those that require a subtract function for pc_range YUV data use [[Overlay]]:
+
 
+
  # Overlay(any_clip, any_clip, mode="difference", pc_range=true) # grey clip with luma = 128
+
Overlay(clip1, clip2, mode="difference", pc_range=true)
+
  
  
 
[[Category:Internal filters]]
 
[[Category:Internal filters]]
 +
[[Category:Debugging/Diagnostic_filters]]
 +
[[Category:Layering]]

Latest revision as of 16:33, 27 February 2016

Show the difference between two clips. Where the clips are equal, the output is 50% grey.
See filters with multiple input clips for the resulting clip properties.

[edit] Syntax

Subtract(clip clip1, clip clip2)

[edit] Examples

Show the difference between two clips, and make the difference blatantly obvious:

Subtract(A, B).Levels(65, 1, 255-64, 0, 255, coring=false)

Show the difference between adjacent frames:

Subtract(A, A.Trim(1, 0))

[edit] About offset of luma range

For YUV formats the valid Y range is 16-235, and Subtract takes this into account. This means that the following script

Subtract(A, B)

...will result in a "50% grey" clip with luma=126.

If you require a mathematically correct subtract function for 0-255 RGB or YUV data, use Overlay:

Overlay(A, B, mode="difference", pc_range=false)
...which results in a "50% grey" clip with luma=128.
Personal tools