blubb444
27th March 2013, 02:03
I have some videos that were shot in a rather dark setting, 1920x1080p50. In order to make them brighter without introducing too much noise I'd like to downscale them to exactly half the resolution (960x540p50) but instead of most other resizing algorithms that average neighbouring pixels (that'd be bilinear, right?) or fitting some functions through them (bicubic, sinc, spline...?) I want the luma values of 4 pixels to simply add up to form 1 new pixel. I'm not familiar enough with the Avisynth code and neither with C(++), I only learned some Pascal/Delphi back in school so this is how the pseudo-code would look like:
//Vin/Vout = current input/output video frame
//Vin.Y and Vout.Y are 2D arrays which store the luma values at given pixel (x,y)
function ClampToByte(i: integer): byte; //this is just to make sure that there's no overshooting
begin
if i > 255 then result := 255 else if i < 0 then result := 0 else result := i;
end;
Vout.width := Vin.width div 2;
Vout.height := Vin.height div 2;
//if input levels are 16..235, call levels() to make them 0..255 beforehand
for x := 0 to (Vout.width - 1) do for y := 0 to (Vout.height - 1) do
Vout.Y[x,y] := ClampToByte(Vin.Y[2*x, 2*y] + Vin.Y[2*x+1, 2*y] + Vin.Y[2*x, 2*y+1] + Vin.Y[2*x+1, 2*y+1]);
//U and V values can be resized normally or left as-is if you wish to go from 4:2:0 to 4:4:4
Any way to "translate" that into Avisynth? Or is there already a function which does this? (And I'm not talking about regular BilinearResize() and then multiplying luma by 4 as this would introduce unnecessary banding because of rounding errors, or technically reduce the bit depth from 8 to 6 which I don't want)
//Vin/Vout = current input/output video frame
//Vin.Y and Vout.Y are 2D arrays which store the luma values at given pixel (x,y)
function ClampToByte(i: integer): byte; //this is just to make sure that there's no overshooting
begin
if i > 255 then result := 255 else if i < 0 then result := 0 else result := i;
end;
Vout.width := Vin.width div 2;
Vout.height := Vin.height div 2;
//if input levels are 16..235, call levels() to make them 0..255 beforehand
for x := 0 to (Vout.width - 1) do for y := 0 to (Vout.height - 1) do
Vout.Y[x,y] := ClampToByte(Vin.Y[2*x, 2*y] + Vin.Y[2*x+1, 2*y] + Vin.Y[2*x, 2*y+1] + Vin.Y[2*x+1, 2*y+1]);
//U and V values can be resized normally or left as-is if you wish to go from 4:2:0 to 4:4:4
Any way to "translate" that into Avisynth? Or is there already a function which does this? (And I'm not talking about regular BilinearResize() and then multiplying luma by 4 as this would introduce unnecessary banding because of rounding errors, or technically reduce the bit depth from 8 to 6 which I don't want)