Skip to content

Commit f091c6a

Browse files
LypheoFichteFoll
authored andcommitted
Mention chroma shift when resizing subsampled video
1 parent 76f9d41 commit f091c6a

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

encoding/resampling.md

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -593,8 +593,18 @@ before calculating the output samples.
593593
This way,
594594
the left-alignment is restored.
595595

596-
This quarter-pixel shifting is performed
596+
Similiarly,
597+
when resizing left-aligned 4:2:0 material
598+
while keeping the subsampling,
599+
a slight shift needs to be applied
600+
to preserve the alignment.
601+
Specifically,
602+
the chroma needs to be shifted by
603+
`0.25 - 0.25 * src_width/dst_width`.[^4]
604+
605+
Chroma shifting is performed
597606
automatically under the hood by most format conversion software
607+
(including zimg, VapourSynth’s resizing library)
598608
and media players.
599609
Thus, we only need to take care of it
600610
if we handle the chroma upscaling seperately by hand.
@@ -614,5 +624,6 @@ shifted_scaled_u = core.resize.Spline16(u, 1920, 1080, src_left=0.25) # shifts t
614624
[^1]: The Fourier transform is an ubiqitous concept in image processing, so we strongly advise becoming familiar with at least the basics. A very good resource for this topic is [ImageMagick’s guide][].
615625
[^2]: Robidoux, N. (2012, October 21). Resampling — ImageMagick v6 Examples. Retrieved August 22, 2019, from https://www.imagemagick.org/Usage/filter/nicolas/#upsampling
616626
[^3]: If you don’t understand what this means, read the resources linked above in the [resizing section](#resizing).
627+
[^4]: This is derived as follows: The shift is the distance between the position of the first luma sample and the position of the first chroma sample (both mapped onto the input grid and given in terms of input chroma pixel widths). The former is located at `0.25 + (src_width/dst_width)/4`, the latter at `(src_width/dst_width)/2`. This yields `0.25 + (src_width/dst_width)/4 - (src_width/dst_width)/2 = 0.25 + (src_width/dst_width) * (1/4 - 1/2) = 0.25 + (src_width/dst_width) * -0.25` for the shift.
617628

618629
[ImageMagick’s guide]: http://www.fmwconcepts.com/imagemagick/fourier_transforms/fourier.html

0 commit comments

Comments
 (0)