I needed to convert a raw YUV image to something viewable on my computer. There are a few tools to do so, including the wonderful ImageMagick toolset. However, running my image through this did not work as is.

The source image is a frame from an HD-SDI stream, which has a color-depth of 10 bits instead of the usual 8. The sample packing seems to be UYVY, but using 16bit per component (with the lower 6 bits always 0).

Since I only wanted to have a quick view of the frame, I just discarded the lower 2bits (i.e. byte) and converted that instead. This perl-script discards the least significant byte:

while( read STDIN, my $block, 2 ) {
 my @value = split //, $block;
 print $value[0];

The output can be fed into ImageMagick’s convert tool:

convert -size 1280×720 -interlace none -sampling-factor 4:2:2 8bit.uyvy out.bmp