User:Raffriff42/sandbox
Resize
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 resizing.
Contents |
Common Parameters
int target_width, target_height =
- Width and height of the returned clip.
int src_left, src_top = 0, 0
- See cropping discussion below.
Cropping of the left and top edges respectively, in pixels, before resizing.
int 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 restrictions: | |||
• src_width | cannot be >= | (clip.Width - src_left); | this would enlarge the clip. |
• src_height | cannot be >= | (clip.Height - src_top); | this would enlarge the clip. |
• -src_right | cannot be >= | (clip.Width - src_left); | this would reduce clip width to 0 or less. |
• -src_bottom | cannot be >= | (clip.Height - src_top); | this would reduce clip width to 0 or less. |
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 edge semantics are slightly different. Also note that Crop gives a hard absolute boundary, and the Resizer filter lobes extend into the cropped region – but not beyond the physical edge of the image.
As a general rule, 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.
Note the source cropping parameters are all floating point. This allows any resizer to be used as a sub-pixel shifter. [1]
BilinearResize
BilinearResize(clip clip, int target_width, int target_height )
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.
BicubicResize
BicubicResize(clip clip, int target_width, int target_height [, float b, float c ] )
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.
b and c parameters
float b, c = 1/3
- With b=0 and c=0.75 the filter is exactly the same as VirtualDub's precise bicubic. The default for both b and 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 b and c can produce interesting op-art effects – for example, try b=0 and c=-5.0.
You have to set "b + 2.0 * c = 1.0" for the numerically most 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.
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.
BlackmanResize
BlackmanResize(clip clip, int target_width, int target_height )
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.
taps parameter
int taps = 4
- See LanczosResize for an explanation of the taps argument (default 4, range 1-100).
GaussResize
GaussResize(clip clip, int target_width, int target_height )
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 is good for smoothing.
p parameter
float p = 30.0
- Sharpness. Range from about 1 to 100, with 1 being very blurry and 100 being very sharp.
LanczosResize
LanczosResize(clip clip, int target_width, int target_height )
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 )
Lanczos4Resize(clip clip, int target_width, int target_height [,
float src_left, float src_top, float src_width, float src_height ] )
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.
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).
The input parameter taps (default 3, 1<=taps<=100) is equal to the number of lobes (ignoring mirroring around the origin).
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.
taps parameter
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)):
"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 Tx downsampling and LanczoskResize 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: avsforum post (mirror).
LanczosResize(clip clip, int target_width, int target_height, int taps)
PointResize
PointResize(clip clip, int target_width, int target_height )
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.
Spline based resizers
Spline16Resize(clip clip, int target_width, int target_height )
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 )
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 )
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 details.
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 here.
SincResize
SincResize(clip clip, int target_width, int target_height )
SincResize(clip clip, int target_width, int target_height [,
float src_left, float src_top, float src_width, float src_height, int taps ] )
SincResize is added in v2.6 and it uses the truncated sinc function as resizer.
taps parameter
int taps = 4
- See LanczosResize for an explanation of the taps argument (default 4, range 1-20).
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)
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)
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.
External Links
- AviSynth resize filter comparison | archived link
- Upscaling in Avisynth – Comparison of resizers | archived link
- Doom9 discussion of downsizing resizers
Changelog
. . .