Page 1 of 1

RGB bitmap to YCbCr 422 ?

Posted: 2009-12-10T14:56:00-07:00
by eesutton
What are the steps needed to convert a 1280 x 1024 x 8-bit RGB bitmap file to three separate files; Y.pgm, Cb.pgm, and Cr.pgm files.

* The Y.pgm file will be 1280 x 1024
* The 422 sampled Cr.pgm and Cb.pgm files will be (1280 / 2) x 1024

I am an ImageMagick newbie trying to learn if this tool can do this. While I have seen some colorspace conversion usage examples, I do not know if it can output each YCbCr element to a separate file. Any example steps are much appreciated !

Thanks in advance,

-Ed

Re: RGB bitmap to YCbCr 422 ?

Posted: 2009-12-10T15:42:55-07:00
by fmw42
I think this will convert to YCbCr and then separate each channel (all will be the same size) into 3 images numbered _0, _1 and _2. If you need to reduce the size on any or all channels then you will need to add -resize to the processing using either separate commands or using parenthesis processing with clones. If you need help with the resizing, then explain a little better what you need in the way of size and I can try to help.

convert rgbimage -colorspace YCbCr -separate ycbcrimage_%d.pgm

I don't know much about YCbCr and 422 format.

See
http://www.imagemagick.org/script/comma ... colorspace
http://www.imagemagick.org/Usage/channels/#separate
http://www.imagemagick.org/Usage/basics/#image_seq

see also this post about 422 format viewtopic.php?f=1&t=14013&p=48391&hilit ... 422#p48391

convert -list format

shows all the supported formats for your version of IM.

Re: RGB bitmap to YCbCr 422 ?

Posted: 2009-12-11T08:08:45-07:00
by eesutton
Cool! I'm almost there.

convert videoFrame-1280x1024x24.bmp -colorspace YCbCr -separate videoFrame-ycbcr_%d.pgm

Outputs three files:

videoFrame-ycbcr_0.pgm ( Looks like a gray-scale 1280x1024x8 version of the color bmp image)
videoFrame-ycbcr_1.pgm ( Looks like a foggy gray-scale 1280x1024x8 version of the color bmp image)
videoFrame-ycbcr_2.pgm ( Looks like a foggy gray-scale 1280x1024x8 version of the color bmp image)

YCbCr

As I understand it, is a way of encoding RGB information.

* Y - Luminance or brightness intensity
* Cr - Luminance deducted from the color red (R-Y)
* Cb - Luminance deducted from the color blue (B-Y)

Sampled as 4:2:2

This seems to be a bandwidth compression technique. It appears to me, that adjacent pairs of Cr or Cb pixels are averaged. This effectively reduce number of total Y + CR + Cb pixels by 1/3. For example if the native image size was 1280 x 1024. The Y component will also be 1280 x 1024. However, the Cr and Cb image components will be reduced to (1280/2) x 1024, or 640 x 1024.

With what you have shown me, I think I can simply resize the Cr and Cb images from 1280 x 1024 to 640 x 1024 While this may not be ideal, I think it should be close enough and will serve my purposes. I will investigate how to use the resize command.

I had seen the posting you sent me, How to put 10 bit YUV 422 data into a DPX file?. This posting dated June 2009 said:
YCbCR444 should be supported in the next point release and YCbCr422 is being worked on now.
This must still be under development as I only saw mention of YCbCr in the documentaion.

Thank you very much for your help and references! I am impressed by both the power and simplicity of ImageMagick!

-Ed

Re: RGB bitmap to YCbCr 422 ?

Posted: 2009-12-11T10:16:22-07:00
by fmw42
to resize by averaging each 2 pixels try

-scale 50x100%
or
-filter box -resize 50x100%

to resize by taking every second pixel try

-filter point -resize 50x100%

see
http://www.imagemagick.org/Usage/resize/#scale
http://www.imagemagick.org/script/comma ... php#filter
http://www.imagemagick.org/script/comma ... p#geometry
http://www.imagemagick.org/Usage/resize/#filter

Re: RGB bitmap to YCbCr 422 ?

Posted: 2009-12-11T10:26:46-07:00
by eesutton
Wow! Impressive! ImageMagick just works!

convert image-1280x1024-cr.pgm -filter box -resize 50x100% image-640x1024-cr.pgm

Thanks a million for taking the time to assist me!

-Ed

Re: RGB bitmap to YCbCr 422 ?

Posted: 2009-12-11T10:53:11-07:00
by fmw42
just a quick note: -scale will be slightly faster than -filter box -resize

Re: RGB bitmap to YCbCr 422 ?

Posted: 2009-12-11T11:20:27-07:00
by eesutton
Thanks for the performance tip.

My goal is to create a JPEG 2000 JP2 file from the ImageMagick output in order to benchmark JPEG 2000 software decode times. I need a better estimate of the CPU performance required to decode JPEG 2000 encoded 1280x1024 video. Eventually the camera video encoding will be done in hardware. But for now, and with your kind assistance, I think I can estimate the decode processing power required.

Thanks again!

-Ed

Re: RGB bitmap to YCbCr 422 ?

Posted: 2009-12-11T11:41:15-07:00
by fmw42
Don't know if this is helpful, but IM can convert images to JP2000 files using the Jasper delegate library. see http://www.imagemagick.org/download/delegates/ or get a more current version, if you need it.

Re: RGB bitmap to YCbCr 422 ?

Posted: 2009-12-11T13:52:51-07:00
by fmw42
by the way you can do it all in one command:

convert rgbimage -colorspace YCbCr -separate \
\( -clone 0 -write yimage.pgm \) \
\( -clone 1 -scale 50x100% -write cbimage.pgm \) \
\( -clone 2 -scale 50x100% -write crimage.pgm \) \
null:

Re: RGB bitmap to YCbCr 422 ?

Posted: 2009-12-11T15:26:27-07:00
by eesutton
I am using Kakadu for my JPEG 2000 encoding. I should try Jasper; for non-real-time decoding and encoding it might be fine.

Thanks for the single-line decode tip!

I was having some issue downsizing the Cr Cb images. When I changed the input bitmap to a 256 color bitmap the resulting 50x100% downscaled image was tiny. Something like 50 x 80 pixels. The downsizing of a 24-bit color bitmap seemed to work as expected. Anyway, I ended up using IrfanView to down scale to 50% x 100%. This seemed to work fine.

Unfortunately my JPEG decode times are not was I was hoping. Using two cores, it is about 100 ms which is not quite 10 fps. Anyway, I have some performance tuning to work on.

Thanks again,

-Ed

Re: RGB bitmap to YCbCr 422 ?

Posted: 2009-12-11T17:01:25-07:00
by fmw42
what was your exact command and what version of IM are you using? Perhaps your version of IM is too old or you are not using the correct command for 256 colored (pseudocolor) bitmapped image.

try using quotes with the % or escape the percent

-resize "50x100%"

if on windows, see http://www.imagemagick.org/Usage/windows/