Resize

From Avisynth wiki
(Difference between revisions)
Jump to: navigation, search
m (added category)
m (Reverted edits by 77.205.22.58 (talk) to last revision by Reel.Deal)
 
(16 intermediate revisions by 4 users not shown)
Line 1: Line 1:
'''Basic usage:'''
+
<div style="max-width:62em" >
  
{{Template:Func11Def|BicubicResize(clip ''clip'', int ''target_width'', int ''target_height'', float ''b'', float ''c'')|BilinearResize(clip ''clip'', int ''target_width'', int ''target_height'')|BlackmanResize(clip ''clip'', int ''target_width'', int ''target_height'')|GaussResize(clip ''clip'', int ''target_width'', int ''target_height'')|LanczosResize(clip ''clip'', int ''target_width'', int ''target_height'')|Lanczos4Resize(clip ''clip'', int ''target_width'', int ''target_height'')|PointResize(clip ''clip'', int ''target_width'', int ''target_height'')|SincResize(clip ''clip'', int ''target_width'', int ''target_height'')|Spline16Resize(clip ''clip'', int ''target_width'', int ''target_height'')|Spline36Resize(clip ''clip'', int ''target_width'', int ''target_height'')|Spline64Resize(clip ''clip'', int ''target_width'', int ''target_height'')}}
+
<div {{BlueBox2|40|0|3px solid purple}} >
 +
{{AvsPlusFullname}}<br>
 +
Up-to-date documentation: [https://avisynthplus.readthedocs.io/en/latest/avisynthdoc/corefilters/resize.html https://avisynthplus.readthedocs.io]
 +
</div>
  
'''Advanced usage:'''
+
Scales the input video frames to an arbitrary new resolution, and optionally crops the frame before resizing with sub-pixel precision.
  
{{Template:Func11Def|BicubicResize(clip ''clip'', int ''target_width'', int ''target_height'', float ''b'', float ''c'', float ''src_left'', float ''src_top'', float ''src_width'', float ''src_height'')|BilinearResize(clip ''clip'', int ''target_width'', int ''target_height'', float ''src_left'', float ''src_top'', float ''src_width'', float ''src_height'')|BlackmanResize(clip ''clip'', int ''target_width'', int ''target_height'', float ''src_left'', float ''src_top'', float ''src_width'', float ''src_height'', int ''taps'')|GaussResize(clip ''clip'', int ''target_width'', int ''target_height'', float ''src_left'', float ''src_top'', float ''src_width'', float ''src_height'', float ''p'')|LanczosResize(clip ''clip'', int ''target_width'', int ''target_height'', float ''src_left'', float ''src_top'', float ''src_width'', float ''src_height'', int ''taps'')|Lanczos4Resize(clip ''clip'', int ''target_width'', int ''target_height'', float ''src_left'', float ''src_top'', float ''src_width'', float ''src_height'')|PointResize(clip ''clip'', int ''target_width'', int ''target_height'', float ''src_left'', float ''src_top'', float ''src_width'', float ''src_height'')|SincResize(clip ''clip'', int ''target_width'', int ''target_height'', float ''src_left'', float ''src_top'', float ''src_width'', float ''src_height'', int ''taps'')|Spline16Resize(clip ''clip'', int ''target_width'', int ''target_height'', float ''src_left'', float ''src_top'', float ''src_width'', float ''src_height'')|Spline36Resize(clip ''clip'', int ''target_width'', int ''target_height'', float ''src_left'', float ''src_top'', float ''src_width'', float ''src_height'')|Spline64Resize(clip ''clip'', int ''target_width'', int ''target_height'', float ''src_left'', float ''src_top'', float ''src_width'', float ''src_height'')}}
+
There are trade-offs to be considered between preservation (or augmentation) of image detail and possible artifacts (i.e., oversharpening).
 +
</div>
 +
__TOC__
  
=== General information ===
+
== Common Parameters ==
  
From v2.56 you can use offsets (as in [[Crop]]) for all resizers:
+
{{Par2|target_width, target_height|int|}}
 +
:Width and height of the returned clip.
  
i.e.<br>
+
{{Par2|src_left, src_top|float|0, 0}}
GaussResize(clip ''clip'', int ''target_width'', int ''target_height'', float ''src_left'', float ''src_top'', float -''src_right'', float -''src_bottom'')
+
:See [[#Cropping |cropping]] discussion below.
 +
<div {{ListItemContinue|2}} >
 +
Cropping of the {{FuncArg|left}} and {{FuncArg|top}} edges respectively, in pixels, before resizing.
 +
</div>
  
For all resizers you can use an expanded syntax which crops before resizing. The same operations are performed as if you put a [[Crop]] before the Resize, there can be a slight speed difference.
+
{{Par2|src_width, src_height|float|(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}} + '''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}} + '''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>
  
Note the edge semantics are slightly different, [[Crop]] gives a hard absolute boundary, the Resizer filter lobes can extend into the cropped region but not beyond the physical edge of the image.
 
  
Use Crop to remove any hard borders or 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.
+
== 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|54|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|54|3}} >
 +
Crop(10, 10, 200, 300).BilinearResize(100, 150)
 +
</div>
  
Note the source cropping parameters are all floats. This allows any resizer to be used as a sub pixel shifter. [http://forum.doom9.org/showpost.php?p=938102&postcount=2]
+
*Note the cropping parameters are all [[Script_variables|floating point]]. This allows any '''Resize''' filter to be used as a sub-pixel shifter. <sup>[http://forum.doom9.org/showpost.php?p=938102&postcount=2]</sup>
  
 +
*Note that [[Crop]] gives a hard boundary, whereas the '''Resize''' filters interpolate pixels outside the cropped region &ndash; depending on the resizer kernel &ndash; bilinear, bicubic etc, and not beyond the edge of the image.
  
Example:
+
*As a general rule,
Crop(10, 10, 200, 300).BilinearResize(100, 150)
+
** [[Crop]] any hard borders or noise; '''Resize''' cropping may propagate the noise into the output.
 +
** Use '''Resize''' cropping to maintain accurate edge rendering when excising a part of a complete image.
  
which is nearly the same as
+
*Negative cropping is allowed; this results in repeated edge pixels as shown below:
 +
<div {{BoxWidthIndent|54|3}} >
 +
BilinearResize(Width, Height, -64, -64, Width, Height)
 +
</div>
 +
:[[File:Sintel_frm6291_Resize_shift.jpg|680px]]
 +
</div>
  
BilinearResize(100, 150, 10, 10, 200, 300)
 
  
Important: AviSynth has completely separate vertical and horizontal resizers. If input is the same as output on one axis, that resizer will be skipped. Which one is called first, is determined by which one has the smallest downscale ratio. This is done to preserve maximum quality, so the second resizer has the best possible picture to work with. Data storing will have an impact on what modulos that ''should'' be used for sizes when resizing and cropping, see the [[Crop]] page.
+
== 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 ===
+
'''BilinearResize''' uses standard [[Wikipedia:Bilinear_filtering|bilinear filtering]] and is a good choice for smoothing overly sharp sources.
 +
</div>
  
The '''BilinearResize''' filter rescales the input video frames to an arbitrary new resolution. If you supply the optional source arguments, the result is the same as if you had applied [[Crop]] with those arguments to the clip before BilinearResize.
 
  
BilinearResize uses standard bilinear filtering and is almost identical to VirtualDub's "precise bilinear" resizing option. It's only "almost" because VirtualDub's filter seems to get the scaling factor slightly wrong, with the result that pixels at the top and right of the image get either clipped or duplicated. (This error is noticeable when expanding the frame size by a factor or two or more, but insignificant otherwise, so I wouldn't worry too much about it.)  
+
== 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'' ] )
 +
}}
  
(''Does anyone know the origin of this statement? The premise is not correct, as with standard mappings you must have duplicated or mirrored pixels around the border when enlarging. Looking at the sources and comparing outputs, VirtualDub 1.6 and Avisynth 2.5 appear to generate the same mappings. I wonder if this discrepancy has already been resolved. ? Avery'')
+
'''BicubicResize''' is similar to [[#BilinearResize|BilinearResize]], except that instead of a linear filtering function it uses the [[Wikipedia:Mitchell–Netravali_filters|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.
  
'''Examples:'''
+
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]].
  
# Load a video file and resize it to 240x180 (from whatever it was before)
+
==== parameters ''b'' and ''c'' ====
AviSource("video.avi").BilinearResize(240,180)
+
{{Par2|b, c|float|1/3}}
 +
:The default for both {{FuncArg|b}} and {{FuncArg|c}} is 1/3, which were recommended by Mitchell and Netravali for having the most visually pleasing results.
  
# Load a 720x480 (CCIR601) video and resize it to 352x240 (VCD),
+
<div {{ListItemContinue|2}} >
# preserving the correct aspect ratio
+
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.
AviSource("dv.avi").BilinearResize(352, 240, 8, 0, 704, 480)
+
+
# or what is the same
+
AviSource("dv.avi").BilinearResize(352, 240, 8, 0, -8, -0)
+
  
# Extract the upper-right quadrant of a 320x240 video and zoom it
+
Larger values of {{FuncArg|b}} and {{FuncArg|c}} can produce interesting op-art effects &ndash; for example, try ({{FuncArg|b}}=0, {{FuncArg|c}}= -5.0).
# to fill the whole frame
+
BilinearResize(320, 240, 160, 0, 160, 120)
+
  
=== BicubicResize ===
+
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.
  
'''BicubicResize''' is similar to BilinearResize, except that instead of a linear filtering function it uses the Mitchell-Netravali two-part cubic. The parameters b and c can be used to adjust the properties of the cubic, they are sometimes referred to as "blurring" and "ringing" respectively.
+
With ({{FuncArg|b}}=0, {{FuncArg|c}}=0.75) the filter is the same as [http://www.virtualdub.org/blog/pivot/entry.php?id=95 VirtualDub's "Precise Bicubic"].  
  
With b = 0 and c = 0.75 the filter is exactly the same as VirtualDub's "precise bicubic" and the results are identical except for the VirtualDub scaling problem mentioned above. The default is b = 1./3. and c = 1./3., which were the values recommended by Mitchell and Netravali as yielding the most visually pleasing results in subjective tests of human beings. Larger values of b and c can produce interesting op-art effects--for example, try b = 0 and c = -5.  
+
'''BicubicResize''' may be the most visually pleasing of the '''Resize''' filters for ''downsizing'' to half-size or less.<sup>[http://forum.doom9.org/showthread.php?t=172871&page=2 doom9]</sup><br>Try the default setting, ({{FuncArg|b}}=0, {{FuncArg|c}}=0.75) as above, or ({{FuncArg|b}}= -0.5, {{FuncArg|c}}=0.25).
 +
</div>
 +
</div>
  
If you are magnifying your video, you will get much better-looking results with BicubicResize than with BilinearResize. However, if you are shrinking it, you are probably just as well off, or even better off, with BilinearResize. Although VirtualDub's bicubic filter does produce better-looking images than its bilinear filter, this is mainly because the bicubic filter sharpens the image, not because it samples it better. Sharp images are nice to look at--until you try to compress them, at which point they turn nasty on you very quickly. The BicubicResize default doesn't sharpen nearly as much as VirtualDub's bicubic, but it still sharpens more than the bilinear. If you plan to encode your video at a low bitrate, I wouldn't be at all surprised if BilinearResize yields better quality.
+
== 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'' ] )
 +
}}
  
You have to set "b + 2 * c = 1" for the numerically most accurate filter. This gives for b = 0 the maximum value for c = 0.5, which is the Catmull-Rom spline and a good suggestion for sharpness.  
+
'''BlackmanResize''' is a modification of LanczosResize that has better control of [[Wikipedia:Ringing_artifacts|ringing]] artifacts for high numbers of {{FuncArg|taps}}.  
  
From c>0.6 the filter starts to "ring". You won't get real sharpness, what you'll get is crispening like on a TV set.
+
==== parameter ''taps'' ====
Negative values for b (although allowed) give undesirable results, so use b = 0 for values of c > 0.5.
+
{{Par2|taps|int|4}}
 +
:See [[#lanczos_taps|LanczosResize]] for an explanation of the {{FuncArg|taps}} argument (default 4, range 1-100).
 +
</div>
  
=== BlackmanResize ===
 
  
'''BlackmanResize''' is a modification of LanczosResize that has better control of ringing artifacts for high numbers of taps. See LanczosResize for an explanation of the taps argument (default: taps=4, 1<=taps<=100).
+
== 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 ===
+
'''GaussResize''' uses a [[Wikipedia:Gaussian_filter|gaussian]] resizer, which unlike the bicubics, does not overshoot &ndash; but perhaps does not appear as sharp to the eye.
  
'''GaussResize''' uses a gaussian resizer with adjustable sharpness parameter ''p'' (default 30). ''p'' has a range from about 1 to 100, with 1 being very blurry and 100 being very sharp. GaussResize has similar speed as Lanczos4Resize. (added in v2.56)
+
==== 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 ===
 
  
'''LanczosResize''' is an alternative to BicubicResize with high values of c about 0.6 ... 0.75 which produces quite strong sharpening. It usually offers better quality (fewer artifacts) and a sharp image.
+
== 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'' ] )
 +
}}
  
Lanczos was created for AviSynth because it retained so much detail, more so even than BicubicResize(x,y,0,0.75). As you might know, the more detail a frame has, the more difficult it is to compress it. This means that Lanczos is NOT suited for low bitrate video, the various Bicubic flavours are much better for this. If however you have enough bitrate then using Lanczos will give you a better picture, but in general I do not recommend using it for 1 CD rips because the bitrate is usually too low (there are exceptions of course).
+
{{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'' ] )
 +
}}
  
The input parameter taps (default 3, 1<=taps<=100) is equal to the number of lobes (ignoring mirroring around the origin).
+
'''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 LanczosResize(taps=4). It produces sharper images than LanczosResize with the default taps=3, especially useful when upsizing a clip.
+
'''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.
  
''Warning: the input argument named taps should really be lobes. When discussing resizers, taps has a different meaning, as described below (the first paragraph concerns LanczosResize(taps=2)):''
+
<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).
  
"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.
+
<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:
  
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." 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 {{ListItemContinue|1}} >
 +
{{BoldColor|black|120|“}}So when people talk about Lanczos2, they mean a 2-lobe Lanczos-windowed sinc function. There are actually 4 lobes -- 2 on each side...
  
LanczosResize(clip clip, int target_width, int target_height, int taps)
+
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 8 input samples, and thus 8 taps. For 3X downsampling, you need 12 taps, and so forth.
  
=== PointResize ===
+
The total number of taps you need for downsampling is the downsampling ratio times the number of lobes, times 2. And practically, one needs to round that up to the next even integer. For upsampling, it's always 4 taps.{{BoldColor|black|120|”}}
  
'''PointResize''' is the simplest resizer possible. It uses a Point Sampler or 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.
+
[http://www.avsforum.com/forum/26-home-theater-computers/460922-lanczos-vs-bicubic-comparison-2.html#post4760581 Don Munsil (avsforum post)] | [[lanczos lobs/taps|mirror]].
 +
</div>
 +
</div>
 +
</div>
  
=== Spline based resizers ===
 
  
'''Spline16Resize''', '''Spline36Resize''' and '''Spline64Resize''' are three Spline based resizers. They are the (cubic) spline based resizers from [http://www.all-in-one.ee/~dersch/ 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.
+
== 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 technical details.
 +
 
 +
The rationale for '''Spline''' is to be as sharp as possible with less ringing artifacts than [[#LanczosResize|LanczosResize]] produces. '''Spline16Resize''' uses &radic;16 or 4 sample points, '''Spline36Resize''' uses &radic;36 or 6 sample points, etc ... The more sample points used, the more accurate the resampling. Several resizer comparison pages are given in the [[#External Links|External Links]] section.
 +
 
 +
*'''Spline64Resize''' may be the most accurate of the '''Resize''' filters.<sup>[http://web.archive.org/web/20060827184031/http://www.path.unimelb.edu.au/~dersch/interpolator/interpolator.html Dersch]</sup>
 +
*'''Spline16Resize''' is sharper and [[Wikipedia:Ringing_artifacts|rings]] just a bit (which may be desirable with soft sources),<br>and looks pleasing to the eye when enlarging or reducing in moderate amounts.<sup>[http://forum.doom9.org/showthread.php?p=1689519#post1689519 doom9]</sup>
 +
*'''Spline36Resize''' is somewhere in between the other two.
 +
</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>
  
The rationale for Spline is to be as sharp as possible with less ringing artifacts as LanczosResize produces. Spline16Resize uses sqrt(16)=4 sample points, Spline36Resize uses 6 sample points, etc ... The more sample points is used, the sharper your clip will get. A comparison between several resizers is given [http://web.archive.org/web/20060827184031/http://www.path.unimelb.edu.au/~dersch/interpolator/interpolator.html here].
 
  
=== SincResize ===
+
== 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>
  
'''SincResize''' is added in v2.6 and it uses the truncated sinc function as resizer. See LanczosResize for an explanation of the taps argument (default: taps=4; 1<=taps<=20).
 
  
=== External Links ===
+
== External Links ==
* [http://hermidownloads.craqstar.de/videoresizefiltercomparasion/ AviSynth resize filter comparison] | [http://web.archive.org/web/20130815024055/http://hermidownloads.craqstar.de/videoresizefiltercomparasion archived link]
+
* [http://hermidownloads.craqstar.de/videoresizefiltercomparasion/ ''AviSynth resize filter comparison''] (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://jeanbruenn.info/2011/10/30/upscaling-in-avisynth-comparison-of-resizers/ ''Upscaling in Avisynth – Comparison of resizers''] (jeanbruenn.info) | [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 ''Discussion of resizers for downsizing''] (doom9.org)
  
=== Changelog ===
 
  
 +
== Changelog ==
 
{| border="1"
 
{| border="1"
 
|-  
 
|-  

Latest revision as of 21:53, 22 February 2024

AviSynth+
Up-to-date documentation: https://avisynthplus.readthedocs.io

Scales 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 preservation (or augmentation) of image detail and possible artifacts (i.e., oversharpening).

Contents


[edit] Common Parameters

int  target_width, target_height =

Width and height of the returned clip.

float  src_left, src_top = 0, 0

See cropping discussion below.

Cropping of the left and top edges respectively, in pixels, before resizing.

float  src_width, src_height = (source width, height)

See cropping discussion below.

As with Crop, these arguments have different functionality, depending on their value:

  • If  > zero, these set the width and height of the clip before resizing.
  • If <= zero, they set the cropping of the right and bottom edges respectively, before resizing.

Note, there are certain limits:

  • clip.Width must be >= (src_left + width)
  • clip.Width must be >  (src_left + right)
  • clip.Height must be >= (src_top + height)
  • clip.Height must be >  (src_top + bottom)

...otherwise it would enlarge ("un-crop") the clip, or reduce width or height to 0, which is not allowed.


[edit] Cropping

  • All resizers have an expanded syntax which crops the frame before resizing:
BilinearResize(100, 150, src_left=10, src_top=10, src_width=200, src_height=300)

...or more succinctly:

BilinearResize(100, 150, 10, 10, 200, 300)

The operations are the same as if you put Crop before the Resize:

Crop(10, 10, 200, 300).BilinearResize(100, 150)
  • Note the cropping parameters are all floating point. This allows any Resize filter to be used as a sub-pixel shifter. [1]
  • Note that Crop gives a hard boundary, whereas the Resize filters interpolate pixels outside the cropped region – depending on the resizer kernel – bilinear, bicubic etc, and not beyond the edge of the image.
  • As a general rule,
    • Crop any hard borders or noise; Resize cropping may propagate the noise into the output.
    • Use Resize cropping to maintain accurate edge rendering when excising a part of a complete image.
  • Negative cropping is allowed; this results in repeated edge pixels as shown below:
BilinearResize(Width, Height, -64, -64, Width, Height)
Sintel frm6291 Resize shift.jpg


[edit] BilinearResize

BilinearResize(clip clip, int target_width, int target_height [,
     float src_left, float src_top, float src_width, float src_height ] )

BilinearResize uses standard bilinear filtering and is a good choice for smoothing overly sharp sources.


[edit] BicubicResize

BicubicResize(clip clip, int target_width, int target_height [, float b, float c,
     float src_left, float src_top, float src_width, float src_height ] )

BicubicResize is similar to BilinearResize, except that instead of a linear filtering function it uses the Mitchell–Netravali two-part cubic. The parameters b and 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 as it performs some antialiasing.

[edit] parameters b and c

float  b, c = 1/3

The default for both b and c is 1/3, which were recommended by Mitchell and Netravali for having the most visually pleasing results.

Set [b + 2c = 1] for the most numerically accurate filter. This gives, for b=0, the maximum value of 0.5 for c, which is the Catmull-Rom spline and a good suggestion for sharpness.

Larger values of b and c can produce interesting op-art effects – for example, try (b=0, c= -5.0).

As c exceeds 0.6, the filter starts to "ring" or overshoot. You won't get true sharpness – what you'll get is exaggerated edges. Negative values for b (although allowed) give undesirable results, so use b=0 for values of c > 0.5.

With (b=0, c=0.75) the filter is the same as VirtualDub's "Precise Bicubic".

BicubicResize may be the most visually pleasing of the Resize filters for downsizing to half-size or less.doom9
Try the default setting, (b=0, c=0.75) as above, or (b= -0.5, c=0.25).

[edit] BlackmanResize

BlackmanResize(clip clip, int target_width, int target_height [,
     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 ringing artifacts for high numbers of taps.

[edit] parameter taps

int  taps = 4

See LanczosResize for an explanation of the taps argument (default 4, range 1-100).


[edit] GaussResize

GaussResize(clip clip, int target_width, int target_height [,
     float src_left, float src_top, float src_width, float src_height, float p ] )

GaussResize uses a gaussian resizer, which unlike the bicubics, does not overshoot – but perhaps does not appear as sharp to the eye.

[edit] parameter p

float  p = 30.0

Sharpness. Range from about 1 to 100, with 1 being very blurry and 100 being very sharp.


[edit] LanczosResize

LanczosResize(clip clip, int target_width, int target_height [,
     float src_left, float src_top, float src_width, float src_height, int taps ] )

Lanczos4Resize(clip clip, int target_width, int target_height [,
     float src_left, float src_top, float src_width, float src_height ] )

LanczosResize is a sharper alternative to BicubicResize. It is NOT suited for low bitrate video; the various Bicubic flavours are much better for this.

Lanczos4Resize is a short hand for LanczosResize(taps=4). It produces sharper images than LanczosResize with the default taps=3, especially useful when upsizing a clip.

[edit] parameter taps

int  taps = 3

Basically, taps affects sharpness. Default 3, range 1-100. Equal to the number of filter lobes (ignoring mirroring around the origin).

Note: the input argument named taps should really be called "lobes". When discussing resizers, "taps" has a different meaning, as described below:

So when people talk about Lanczos2, they mean a 2-lobe Lanczos-windowed sinc function. There are actually 4 lobes -- 2 on each side...

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 8 input samples, and thus 8 taps. For 3X downsampling, you need 12 taps, and so forth.

The total number of taps you need for downsampling is the downsampling ratio times the number of lobes, times 2. And practically, one needs to round that up to the next even integer. For upsampling, it's always 4 taps.

Don Munsil (avsforum post) | mirror.


[edit] PointResize

PointResize(clip clip, int target_width, int target_height [,
     float src_left, float src_top, float src_width, float src_height ] )

PointResize is the simplest resizer possible. It uses a Point Sampler or 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.


[edit] Spline based resizers

Spline16Resize(clip clip, int target_width, int target_height [,
     float src_left, float src_top, float src_width, float src_height ] )

Spline36Resize(clip clip, int target_width, int target_height [,
     float src_left, float src_top, float src_width, float src_height ] )

Spline64Resize(clip clip, int target_width, int target_height [,
     float src_left, float src_top, float src_width, float src_height ] )

Spline16Resize, Spline36Resize and Spline64Resize are three Spline based resizers. They are the (cubic) spline based resizers from Panorama tools that fit a spline through the sample points and then derives the filter kernel from the resulting blending polynomials. See this thread for the technical details.

The rationale for Spline is to be as sharp as possible with less ringing artifacts than LanczosResize produces. Spline16Resize uses √16 or 4 sample points, Spline36Resize uses √36 or 6 sample points, etc ... The more sample points used, the more accurate the resampling. Several resizer comparison pages are given in the External Links section.

  • Spline64Resize may be the most accurate of the Resize filters.Dersch
  • Spline16Resize is sharper and rings just a bit (which may be desirable with soft sources),
    and looks pleasing to the eye when enlarging or reducing in moderate amounts.doom9
  • Spline36Resize is somewhere in between the other two.


[edit] SincResize

SincResize(clip clip, int target_width, int target_height [,
     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 ringing artifacts.

[edit] parameter taps

int  taps = 4

See LanczosResize for an explanation of the taps argument (default 4, range 1-20).


[edit] Examples

  • Cropping:
Crop(10, 10, 200, 300).BilinearResize(100, 150)

which is nearly the same as:

BilinearResize(100, 150, 10, 10, 200, 300)
  • Load a video file and resize it to 240x180 (from whatever it was before)
AviSource("video.avi").BilinearResize(240,180)
  • Load a 720x480 (Rec. 601) video and resize it to 352x240 (VCD), preserving the correct aspect ratio
AviSource("dv.avi").BilinearResize(352, 240, 8, 0, 704, 480)

which is the same as:

AviSource("dv.avi").BilinearResize(352, 240, 8, 0, -8, -0)
  • Extract the upper-right quadrant of a 320x240 video and zoom it to fill the whole frame
BilinearResize(320, 240, 160, 0, 160, 120)


[edit] Notes

  • 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. Data storing will have an impact on what mods should be used for sizes when resizing and cropping; see Crop restrictions.


[edit] External Links


[edit] Changelog

v2.60 Added SincResize.
v2.58 Added BlackmanResize, Spline64Resize.
v2.56 Added Spline16Resize, Spline36Resize, GaussResize and taps parameter in LanczosResize; added offsets in Crop part of xxxResize.
v2.55 Added Lanczos4Resize.
Personal tools