Using ImageMagick to convert a 4:2:2 YCrCb raw image to something viewable

This post was written by eli on February 28, 2009
Posted Under: Linux,Signal Processing,Software

Some electronic imaging system dumped a 4:2:2 YCbCr raw image into a file. It’s a debug output. Now I wanted to see this image. GIMP doesn’t import that format. ImageMagick had the solution. It was as simple as

convert -size 800x600 pal:ImageOut.raw ImageOut.bmp

I don’t know why they picked the codename “pal” to represent 4:2:2 format (maybe because of ITU-R BT.601?) , but it did the job. Ah, they call it “YUV” and not “YCbCr”, but it was really close enough for me.

Reader Comments

Since this entry rates so high on Google, I thought I’d put in a better answer.

The generic format is “yuv”. So:
convert -size 800x600 -depth 8 yuv:image.raw image.png

You will need to provide:
Bits per pixel (-depth 8)
The Y:U:V ratio (-sample 4:2:2)
The relative location of the various bits of information (read about the -interlace option).

So, if we have a 4:2:0 image with the Y plane followed by the Cb followed by the Cr planes:
convert -size 800x600 -depth -sample 4:2:0 -interlace plane 8 yuv:image.raw image.png


Written By Shachar Shemesh on October 31st, 2011 @ 09:59

One correction to the other comment: It’s not “-sample 4:2:0″, but “-sampling-factor 4:2:0″.

Written By Constantin on September 23rd, 2013 @ 17:28

You have slipped the “sample” and “interlace” fields in the middle of the “-depth 8″ part, thereby separating the “-depth” from the “8″

Written By Freddy on February 9th, 2016 @ 16:47

Add a Comment

required, use real name
required, will not be published
optional, your blog address