User:Raffriff42/sandbox

From Avisynth wiki
< User:Raffriff42(Difference between revisions)
Jump to: navigation, search
m (b+2c=1)
m (clear the page)
 
(4 intermediate revisions by one user not shown)
Line 1: Line 1:
{{BoldColor|black|200|Resize}}
+
(this page reserved for future experiments)
----
+
<div style="max-width:62em" >
+
Rescales the input video frames to an arbitrary new resolution, and optionally crops the frame before resizing with sub-pixel precision. There are trade-offs to be considered between retention of detail and introduction of new artifacts; this is why there are so many resizers in AviSynth.
+
</div>
+
__TOC__
+
 
+
== Common Parameters ==
+
 
+
{{Par2|target_width, target_height|int|}}
+
:Width and height of the returned clip.
+
 
+
{{Par2|src_left, src_top|int|0, 0}}
+
:See [[#Cropping |cropping]] discussion below.
+
<div {{ListItemContinue|2}} >
+
Cropping of the {{FuncArg|left}} and {{FuncArg|top}} edges respectively, in pixels, before resizing.
+
</div>
+
 
+
{{Par2|src_width, src_height|int|(source width, height)}}
+
:See [[#Cropping |cropping]] discussion below.
+
<div {{ListItemContinue|2}} >
+
As with [[Crop]], these arguments have different functionality, depending on their value:
+
* If &nbsp;&gt; zero, these set the '''width''' and '''height''' of the clip before resizing. 
+
* If &lt;= zero, they set the cropping of the '''right''' and '''bottom''' edges respectively,  before resizing.
+
Note, there are certain limits:
+
* {{FuncArg|clip}}.[[Clip_properties|Width]] must be &gt;= ({{FuncArg|src_left}} + {{FuncArg|src_width}})
+
* {{FuncArg|clip}}.[[Clip_properties|Width]] must be &gt;&nbsp; ({{FuncArg|src_left}} + '''right''')
+
* {{FuncArg|clip}}.[[Clip_properties|Height]] must be &gt;= ({{FuncArg|src_top}} + {{FuncArg|src_height}})
+
* {{FuncArg|clip}}.[[Clip_properties|Height]] must be &gt;&nbsp; ({{FuncArg|src_top}} + '''bottom''')
+
...otherwise it would enlarge ("un-crop") the clip, or reduce width or height to 0, which is not allowed.
+
</div>
+
 
+
 
+
== Cropping ==
+
<div style="max-width:62em" >
+
* All resizers have an expanded syntax which '''crops''' the frame before resizing:
+
<div {{BoxWidthIndent|54|3}} >
+
BilinearResize(100, 150, ''src_left''=10, ''src_top''=10, ''src_width''=200, ''src_height''=300)
+
</div>
+
<div {{ListItemContinue}} >
+
...or more succinctly:
+
</div>
+
<div {{BoxWidthIndent|36|3}} >
+
BilinearResize(100, 150, 10, 10, 200, 300)
+
</div><div {{ListItemContinue}} >
+
The operations are the same as if you put [[Crop]] before the Resize:
+
</div>
+
<div {{BoxWidthIndent|36|3}} >
+
Crop(10, 10, 200, 300).BilinearResize(100, 150)
+
</div>
+
 
+
<div {{ListItemContinue}} >
+
Note the edge semantics are slightly different. Also note that [[Crop]] gives a hard absolute boundary, and the Resizer filter lobes extend into the cropped region &ndash; but not beyond the physical edge of the image.
+
 
+
As a general rule, use Crop to remove any hard borders or [[Wikipedia:VHS|VHS]] head switching noise; using the Resizer cropping may propagate the noise into the adjacent output pixels. Use the Resizer cropping to maintain accurate edge rendering when excising a part of a complete image.
+
 
+
Note the source cropping parameters are all [[Script_variables|floating point]]. This allows any resizer to be used as a sub-pixel shifter. <sup>[http://forum.doom9.org/showpost.php?p=938102&postcount=2]</sup>
+
</div>
+
</div>
+
 
+
 
+
== BilinearResize ==
+
<div style="max-width:62em" >
+
{{FuncDef
+
|BilinearResize(clip ''clip'', int ''target_width'', int ''target_height'' [, <br>
+
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;float ''src_left'', float ''src_top'', float ''src_width'', float ''src_height'' ] )
+
}}
+
 
+
'''BilinearResize''' uses standard [[Wikipedia:Bilinear_filtering|bilinear filtering]] and is a good choice for smoothing overly sharp sources.
+
</div>
+
 
+
 
+
== BicubicResize ==
+
<div style="max-width:62em" >
+
{{FuncDef
+
|BicubicResize(clip ''clip'', int ''target_width'', int ''target_height'' [, float ''b'', float ''c'', <br>
+
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;float ''src_left'', float ''src_top'', float ''src_width'', float ''src_height'' ] )
+
}}
+
 
+
'''BicubicResize''' is similar to [[#BilinearResize|BilinearResize]], except that instead of a linear filtering function it uses the [http://de.wikipedia.org/wiki/Mitchell-Netravali-Filter Mitchell-Netravali] two-part cubic. The parameters {{FuncArg|b}} and {{FuncArg|c}} can be used to adjust the properties of the cubic; they are sometimes referred to as "blurring" and "ringing" respectively.
+
 
+
If you are enlarging your video, you will get sharper results with '''BicubicResize''' than with BilinearResize. However, if you are shrinking it, you may prefer [[#BilinearResize|BilinearResize]] as it performs some [[Wikipedia:Spatial_anti-aliasing#Examples|antialiasing]].
+
 
+
==== parameters ''b'' and ''c'' ====
+
{{Par2|b, c|float|1/3}}
+
:With {{FuncArg|b}}=0 and {{FuncArg|c}}=0.75 the filter is exactly the same as [[VirtualDub]]'s ''precise bicubic''. The default for both {{FuncArg|b}} and {{FuncArg|c}} is 1.0/3.0, which were the values recommended by Mitchell and Netravali as yielding the most visually pleasing results. Larger values of {{FuncArg|b}} and {{FuncArg|c}} can produce interesting op-art effects &ndash; for example, try {{FuncArg|b}}=0 and {{FuncArg|c}}=-5.0.
+
 
+
<div {{ListItemContinue|2}} >
+
You have to set [{{FuncArg|b}} + 2{{FuncArg|c}} = 1] for the most numerically accurate filter. This gives for {{FuncArg|b}}=0 the maximum value of 0.5 for {{FuncArg|c}}, which is the [[Wikipedia:Cubic_Hermite_spline#Catmull.E2.80.93Rom_spline|Catmull-Rom spline]] and a good suggestion for sharpness.
+
 
+
As {{FuncArg|c}} exceeds 0.6, the filter starts to [[Wikipedia:Ringing_artifacts|"ring"]] or overshoot. You won't get true sharpness &ndash; what you'll get is exaggerated edges.
+
Negative values for {{FuncArg|b}} (although allowed) give undesirable results, so use {{FuncArg|b}}=0 for values of {{FuncArg|c}} > 0.5.
+
</div>
+
</div>
+
 
+
 
+
== BlackmanResize ==
+
<div style="max-width:62em" >
+
{{FuncDef
+
|BlackmanResize(clip ''clip'', int ''target_width'', int ''target_height'' [, <br>
+
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;float ''src_left'', float ''src_top'', float ''src_width'', float ''src_height'', int ''taps'' ] )
+
}}
+
 
+
'''BlackmanResize''' is a modification of LanczosResize that has better control of [[Wikipedia:Ringing_artifacts|ringing]] artifacts for high numbers of {{FuncArg|taps}}.
+
 
+
==== parameter ''taps'' ====
+
{{Par2|taps|int|4}}
+
:See [[#lanczos_taps|LanczosResize]] for an explanation of the {{FuncArg|taps}} argument (default 4, range 1-100).
+
</div>
+
 
+
 
+
== GaussResize ==
+
<div style="max-width:62em" >
+
{{FuncDef
+
|GaussResize(clip ''clip'', int ''target_width'', int ''target_height'' [, <br>
+
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;float ''src_left'', float ''src_top'', float ''src_width'', float ''src_height'', float ''p'' ] )
+
}}
+
 
+
'''GaussResize''' uses a [[Wikipedia:Gaussian_filter|gaussian]] resizer, which does not overshoot &ndash; making it more accurate, but perhaps not as sharp to the eye.
+
 
+
==== parameter ''p'' ====
+
{{Par2|p|float|30.0}}
+
:Sharpness. Range from about 1 to 100, with 1 being very blurry and 100 being very sharp.
+
</div>
+
 
+
 
+
== LanczosResize ==
+
<div style="max-width:62em" >
+
{{FuncDef
+
|LanczosResize(clip ''clip'', int ''target_width'', int ''target_height'' [, <br>
+
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;float ''src_left'', float ''src_top'', float ''src_width'', float ''src_height'', int ''taps'' ] )
+
}}
+
 
+
{{FuncDef
+
|Lanczos4Resize(clip ''clip'', int ''target_width'', int ''target_height'' [, <br>
+
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;float ''src_left'', float ''src_top'', float ''src_width'', float ''src_height'' ] )
+
}}
+
 
+
'''LanczosResize''' is a sharper alternative to [[#BicubicResize|BicubicResize]]. It is NOT suited for low bitrate video; the various Bicubic flavours are much better for this.
+
 
+
'''Lanczos4Resize''' is a short hand for <code>LanczosResize(taps=4)</code>. It produces sharper images than LanczosResize with the default {{FuncArg|taps}}=3, especially useful when upsizing a clip.
+
 
+
<div id="lanczos_taps" style="display:inline;font-size:50%;height:0;line-height:0;overflow:hidden;"></div>
+
==== parameter ''taps'' ====
+
{{Par2|taps|int|3}}
+
:Basically, {{FuncArg|taps}} affects sharpness. Default 3, range 1-100. Equal to the number of filter [[Wikipedia:Lanczos_resampling#Lanczos_kernel|''lobes'']] (ignoring mirroring around the origin).
+
 
+
<div {{ListItemContinue|2}} >
+
''Note:'' the input argument named {{FuncArg|taps}} should really be called "lobes". When discussing resizers, "taps" has a different meaning, as described below (the first paragraph concerns <code>[[#LanczosResize|LanczosResize]](taps=2)</code>):
+
 
+
<div {{ListItemContinue|2}} >
+
"For upsampling (making the image larger), the filter is sized such that the entire equation falls across 4 input samples, making it a 4-tap filter. It doesn't matter how big the output image is going to be - it's still just 4 taps. For downsampling (making the image smaller), the equation is sized so it will fall across 4 *destination* samples, which obviously are spaced at wider intervals than the source samples. So for downsampling by a factor of 2 (making the image half as big), the filter covers 2*4=8 input samples, and thus 8 taps. For 3x downsampling, you need 3*4=12 taps, and so forth.
+
 
+
Thus the total number of taps you need for downsampling is the downsampling ratio times the number of lobes (thus '''T'''x downsampling and Lanczos'''k'''Resize results in T*2*k taps). And practically, one needs to round that up to the next even integer. For upsampling, it's always 2*k taps." </div>
+
Source: [http://www.avsforum.com/forum/26-home-theater-computers/460922-lanczos-vs-bicubic-comparison-2.html#post4760581 avsforum post] ([[lanczos lobs/taps|mirror]]).
+
</div>
+
</div>
+
 
+
 
+
== PointResize ==
+
<div style="max-width:62em" >
+
{{FuncDef
+
|PointResize(clip ''clip'', int ''target_width'', int ''target_height'' [, <br>
+
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;float ''src_left'', float ''src_top'', float ''src_width'', float ''src_height'' ] )
+
}}
+
 
+
'''PointResize''' is the simplest resizer possible. It uses a Point Sampler or [[Wikipedia:Nearest-neighbor_interpolation|Nearest Neighbour]] algorithm, which usually results in a very "blocky" image. So in general this filter should only be used, if you ''intend'' to have inferior quality, or you need the clear pixel drawings. Useful for magnifying small areas for examination.
+
</div>
+
 
+
 
+
== Spline based resizers ==
+
<div style="max-width:62em" >
+
{{FuncDef
+
|Spline16Resize(clip ''clip'', int ''target_width'', int ''target_height'' [, <br>
+
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;float ''src_left'', float ''src_top'', float ''src_width'', float ''src_height'' ] )
+
}}
+
 
+
{{FuncDef
+
|Spline36Resize(clip ''clip'', int ''target_width'', int ''target_height'' [, <br>
+
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;float ''src_left'', float ''src_top'', float ''src_width'', float ''src_height'' ] )
+
}}
+
 
+
{{FuncDef
+
|Spline64Resize(clip ''clip'', int ''target_width'', int ''target_height'' [, <br>
+
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;float ''src_left'', float ''src_top'', float ''src_width'', float ''src_height'' ] )
+
}}
+
 
+
'''Spline16Resize''', '''Spline36Resize''' and '''Spline64Resize''' are three [[Wikipedia:Spline_interpolation|Spline based]] resizers. They are the (cubic) spline based resizers from [http://sourceforge.net/projects/panotools/ Panorama tools] that fit a spline through the sample points and then derives the filter kernel from the resulting blending polynomials. See [http://forum.doom9.org/showthread.php?t=147117 this thread] for the details.
+
 
+
The rationale for '''Spline''' is to be as sharp as possible with less ringing artifacts than [[#LanczosResize|LanczosResize]] produces. '''Spline16Resize''' uses <tt>sqrt(16)=4</tt> sample points, '''Spline36Resize''' uses 6 sample points, etc ... The more sample points used, the sharper your clip will get. Several resizer comparison pages are given in the [[#External Links|External Links]] section.
+
</div>
+
 
+
 
+
== SincResize ==
+
<div style="max-width:62em" >
+
{{FuncDef
+
|SincResize(clip ''clip'', int ''target_width'', int ''target_height'' [, <br>
+
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;float ''src_left'', float ''src_top'', float ''src_width'', float ''src_height'', int ''taps'' ] )
+
}}
+
 
+
'''SincResize''' uses the truncated sinc function. It is very sharp, but prone to [[Wikipedia:Ringing_artifacts|ringing]] artifacts.
+
 
+
==== parameter ''taps'' ====
+
{{Par2|taps|int|4}}
+
:See [[#lanczos_taps|LanczosResize]] for an explanation of the {{FuncArg|taps}} argument (default 4, range 1-20).
+
</div>
+
 
+
 
+
== Examples ==
+
* Cropping:
+
<div {{BoxWidthIndent|42|3}} >
+
Crop(10, 10, 200, 300).BilinearResize(100, 150)
+
</div>
+
<div {{ListItemContinue}} >
+
which is nearly the same as:
+
</div>
+
<div {{BoxWidthIndent|42|3}} >
+
BilinearResize(100, 150, 10, 10, 200, 300)
+
</div>
+
 
+
* Load a video file and resize it to 240x180 (from whatever it was before)
+
<div {{BoxWidthIndent|42|3}} >
+
AviSource("video.avi").BilinearResize(240,180)
+
</div>
+
 
+
* Load a 720x480 ([[Wikipedia:Rec._601|Rec. 601]]) video and resize it to 352x240 ([[Wikipedia:Video_CD|VCD]]), preserving the correct aspect ratio
+
<div {{BoxWidthIndent|42|3}} >
+
AviSource("dv.avi").BilinearResize(352, 240, 8, 0, 704, 480)
+
</div>
+
<div {{ListItemContinue}} >
+
which is the same as:
+
</div>
+
<div {{BoxWidthIndent|42|3}} >
+
AviSource("dv.avi").BilinearResize(352, 240, 8, 0, -8, -0)
+
</div>
+
 
+
* Extract the upper-right quadrant of a 320x240 video and zoom it to fill the whole frame
+
<div {{BoxWidthIndent|42|3}} >
+
BilinearResize(320, 240, 160, 0, 160, 120)
+
</div>
+
 
+
 
+
== Notes ==
+
<div style="max-width:62em" >
+
* AviSynth has completely separate vertical and horizontal resizers. If input is the same as output on one axis, that resizer will be skipped. The resizer with the smallest downscale ratio is called first; this is done to preserve maximum quality, so the second resizer has the best possible picture to work with. [[Filter_SDK/Data_storage|Data storing]] will have an impact on what [[Modulo|mods]] should be used for sizes when resizing and cropping; see [[Crop#Crop restrictions|Crop restrictions]].
+
</div>
+
 
+
 
+
== External Links ==
+
* [http://hermidownloads.craqstar.de/videoresizefiltercomparasion/ ''AviSynth resize filter comparison''] (http://hermidownloads.craqstar.de) | [http://web.archive.org/web/20130815024055/http://hermidownloads.craqstar.de/videoresizefiltercomparasion archived link]
+
* [http://jeanbruenn.info/2011/10/30/upscaling-in-avisynth-comparison-of-resizers/ ''Upscaling in Avisynth – Comparison of resizers''] | [http://web.archive.org/web/20140207171106/http://jeanbruenn.info/2011/10/30/upscaling-in-avisynth-comparison-of-resizers/ archived link]
+
* [http://web.archive.org/web/20060827184031/http://www.path.unimelb.edu.au/~dersch/interpolator/interpolator.html ''Testing Interpolator Quality''] (Helmut Dersch, Technical University Furtwangen)
+
* [http://forum.doom9.org/showthread.php?t=172871 Doom9 discussion of resizers for downsizing]
+
 
+
 
+
== Changelog ==
+
. . .
+

Latest revision as of 11:42, 17 February 2016

(this page reserved for future experiments)

Personal tools