User:Raffriff42/sandbox
Raffriff42 (Talk | contribs) m (typo) |
Raffriff42 (Talk | contribs) m (typo) |
||
Line 19: | Line 19: | ||
{{Par2|src_width, src_height|int|(source width, height)}} | {{Par2|src_width, src_height|int|(source width, height)}} | ||
<div {{ListItemContinue|2}} > | <div {{ListItemContinue|2}} > | ||
− | {| border="0" style="width: | + | {| border="0" style="width:52em" |
|colspan="4"| See [[#Cropping |cropping]] discussion below. | |colspan="4"| See [[#Cropping |cropping]] discussion below. | ||
|- | |- |
Revision as of 21:35, 31 January 2016
Resize
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.
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 "un-crop" the clip, which is not allowed. |
• src_height | cannot be >= | (clip.Height - src_top); | this would "un-crop" the clip, which is not allowed. |
• -src_right | cannot be >= | (clip.Width - src_left); | this would reduce clip width to 0, which is not allowed. |
• -src_bottom | cannot be >= | (clip.Height - src_top); | this would reduce clip height to 0, which is not allowed. |
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 [,
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,
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.
parameters b and c
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 [,
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.
parameter taps
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 [,
float src_left, float src_top, float src_width, float src_height, float p ] )
GaussResize uses a gaussian resizer, which does not overshoot – making it more accurate, but perhaps not as sharp to the eye.
parameter p
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 [,
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.
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 (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).
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.
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 details.
The rationale for Spline is to be as sharp as possible with less ringing artifacts than LanczosResize produces. Spline16Resize uses sqrt(16)=4 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 section.
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.
parameter taps
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 (http://hermidownloads.craqstar.de) | archived link
- Upscaling in Avisynth – Comparison of resizers | archived link
- Testing Interpolator Quality (Helmut Dersch, Technical University Furtwangen)
- Doom9 discussion of resizers for downsizing
Changelog
. . .