How to use imageMagick to convert a ppm image to YUV422
How to use imageMagick to convert a ppm image to YUV422
Hi,
I am trying to use imageMagick to convert a ppm image in RGB format to YUV422 format:
I am using Bretagne1 ppm from:
http://www.openjpeg.org/index.php?menu=samples
I tried:
convert ~/Downloads/Bretagne1.ppm -colorspace YCbCr ~/Downloads/Bretagne2.ppm
convert ~/Downloads/Bretagne1.ppm -colorspace YUV ~/Downloads/Bretagne2.ppm
But when I display Bretagne2.ppm using imageMagick and go to ImageInfo, it still said it is using RGB format.
How can I fix it?
Thank you.
I am trying to use imageMagick to convert a ppm image in RGB format to YUV422 format:
I am using Bretagne1 ppm from:
http://www.openjpeg.org/index.php?menu=samples
I tried:
convert ~/Downloads/Bretagne1.ppm -colorspace YCbCr ~/Downloads/Bretagne2.ppm
convert ~/Downloads/Bretagne1.ppm -colorspace YUV ~/Downloads/Bretagne2.ppm
But when I display Bretagne2.ppm using imageMagick and go to ImageInfo, it still said it is using RGB format.
How can I fix it?
Thank you.
-
- Posts: 12159
- Joined: 2010-01-23T23:01:33-07:00
- Authentication code: 1151
- Location: England, UK
Re: How to use imageMagick to convert a ppm image to YUV422
As far as I know, color pixels in PPM format always represent red, green and blue. It has no metadata to say they represent anything else. See http://en.wikipedia.org/wiki/Netpbm_format Hence IM will automatically convert from YUV to sRGB (or possibly RGB) before saving the result.
You need a file format that supports YUV. MIFF supports YUV, but is specific to IM.
You need a file format that supports YUV. MIFF supports YUV, but is specific to IM.
snibgo's IM pages: im.snibgo.com
Re: How to use imageMagick to convert a ppm image to YUV422
The PPM format doesn't support YUV. You'll need to use a format that does, such as .yuv
(note that .yuv has no header so when you read it you need to use -size WxH to supply the
image dimensions).
(note that .yuv has no header so when you read it you need to use -size WxH to supply the
image dimensions).
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: How to use imageMagick to convert a ppm image to YUV422
I believe that tiff supports yuv, but with JPG compression.
I suspect that when you do -colorspace YUV image.ppm, the data is yuv, but it is not known to be, since there is no header to tell it that.
In, IM, you can read it in and specify that the colorspace is YUV, for example
convert yuv.ppm -set colorspace YUV -colorspace sRGB show:
That will convert the YUV data in the ppm from YUV to sRGB and then display it.
There was also a recent topic about YUV at viewtopic.php?f=1&t=24819
I suspect that when you do -colorspace YUV image.ppm, the data is yuv, but it is not known to be, since there is no header to tell it that.
In, IM, you can read it in and specify that the colorspace is YUV, for example
convert yuv.ppm -set colorspace YUV -colorspace sRGB show:
That will convert the YUV data in the ppm from YUV to sRGB and then display it.
There was also a recent topic about YUV at viewtopic.php?f=1&t=24819
Re: How to use imageMagick to convert a ppm image to YUV422
Thanks for all the answers.
If I understanding correctly, PPM image can't be in YUV 422 format, it can only in RGB format.
My next question is , can I use IM to convert PPM's RBG format to YUV422 and save Y , U, V's data into different files?
i.e. the output image is not an image but 3 planes of Y , U , V.
Thank you.
If I understanding correctly, PPM image can't be in YUV 422 format, it can only in RGB format.
My next question is , can I use IM to convert PPM's RBG format to YUV422 and save Y , U, V's data into different files?
i.e. the output image is not an image but 3 planes of Y , U , V.
Thank you.
Re: How to use imageMagick to convert a ppm image to YUV422
Thanks for the pointers.
I googled how to use 'interlace'.
From this http://www.chemie.fu-berlin.de/chemnet/ ... nvert.html, it seems like
it will create a interlaced GIF or progressive JPEG.
How can I save Y to a file, U to a file , V to a file?
Sorry that my question are from newbies. I am new to image processing field.
I googled how to use 'interlace'.
From this http://www.chemie.fu-berlin.de/chemnet/ ... nvert.html, it seems like
it will create a interlaced GIF or progressive JPEG.
How can I save Y to a file, U to a file , V to a file?
Sorry that my question are from newbies. I am new to image processing field.
-
- Posts: 12159
- Joined: 2010-01-23T23:01:33-07:00
- Authentication code: 1151
- Location: England, UK
Re: How to use imageMagick to convert a ppm image to YUV422
Code: Select all
convert Bretagne1.ppm -colorspace yuv -separate b.png
Code: Select all
convert b-0.png b-1.png b-2.png -set colorspace yuv -combine -colorspace sRGB b2.png
snibgo's IM pages: im.snibgo.com
Re: How to use imageMagick to convert a ppm image to YUV422
The YUV format uses -interlace none to specify 4:2:2 (downsampled) and -interlace plane for 4:1:1 (notmichaels wrote: How can I save Y to a file, U to a file , V to a file?
downsampled). If you use -interlace partition, you'll get 3 files which are just what you want:
- convert rose: -interlace partition roseip.yuv
produces
-rw-rw-r-- 1 glennrp glennrp 805 Jan 17 16:23 roseip.U
-rw-rw-r-- 1 glennrp glennrp 805 Jan 17 16:23 roseip.V
-rw-rw-r-- 1 glennrp glennrp 3220 Jan 17 16:23 roseip.Y
Glenn
Re: How to use imageMagick to convert a ppm image to YUV422
Thanks a lot for all your answers!
Re: How to use imageMagick to convert a ppm image to YUV422
Thanks a lot for your answer.
I get "save Y to a file, U to a file , V to a file" works.
But how can I save Y to a file , Cb to a file, Cr to a file?
I tried:
convert ~/Downloads/Bretagne1.ppm -interlace partition -colorspace YCbCr Bretagne2.yuv
does not work.
And I tried:
convert ~/Downloads/Bretagne1.ppm -interlace partition Bretagne2.ycbcr
I see it created Bretagne2.Y , Bretagne2.Cb, Bretagne2.Cr
But Cb and Cr do not get download sample as the U, V do (when I use YUV format instead of YCbCr format).
Thank you for your help again.
I get "save Y to a file, U to a file , V to a file" works.
But how can I save Y to a file , Cb to a file, Cr to a file?
I tried:
convert ~/Downloads/Bretagne1.ppm -interlace partition -colorspace YCbCr Bretagne2.yuv
does not work.
And I tried:
convert ~/Downloads/Bretagne1.ppm -interlace partition Bretagne2.ycbcr
I see it created Bretagne2.Y , Bretagne2.Cb, Bretagne2.Cr
But Cb and Cr do not get download sample as the U, V do (when I use YUV format instead of YCbCr format).
Thank you for your help again.
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: How to use imageMagick to convert a ppm image to YUV422
I do not believe that is true. The PPM image will store any 3-channel data in it. It could be YUV channels. The issue is that there is no header to tell any other program that it is any thing but RGB channels. In IM you can read the PPM YUV image data and convert it to RGB by telling IM that the data is YUV colorspace. For examplemichaels wrote:Thanks for all the answers.
If I understanding correctly, PPM image can't be in YUV 422 format, it can only in RGB format.
Thank you.
convert yuv.ppm -set colorspace YUV -colorspace sRGB rgb.png
You should also be able to create YUV channels or YCbCr channels by something like.
convert rgb.png -colorspace YUV -separate yuv_%d.ppm (or any other format).
or
convert rgb.png -colorspace YCbCr -separate yuv_%d.ppm (or any other format).
However, you still need to tell IM or any other tool that it is YUV when reading these channels back in. You may need to specify the -interlace none to get 4:2:2 as glennrp pointed out or -sampling-factor (see http://www.imagemagick.org/script/comma ... ing-factor). I do not really know much about that.
Re: How to use imageMagick to convert a ppm image to YUV422
Thanks but it does not give me what I am looking for.
I am looking for what this does, but break it down in YCbCr instead of YUV:
Basically I want what
Thank you.
I am looking for what this does, but break it down in YCbCr instead of YUV:
This is the output from the above comment. Each Y, U, V is smaller than the original image (921638)convert ~/Downloads/Bretagne1.ppm -interlace partition Bretagne2.yuv
When I tried "convert Bretagne1.ppm -colorspace YUV -separate Bretagne_yuv_%d.ppm", it gives me307200 Jan 20 10:06 Bretagne2.Y
76800 Jan 20 10:06 Bretagne2.U
76800 Jan 20 10:06 Bretagne2.V
Each of them are the same side as big as the original image.921639 Jan 20 10:13 Bretagne_yuv_1.ppm
921639 Jan 20 10:13 Bretagne_yuv_0.ppm
921639 Jan 20 10:13 Bretagne_yuv_2.ppm
Basically I want what
gives me but instead of YUV , I want YCbCr.convert ~/Downloads/Bretagne1.ppm -interlace partition Bretagne2.yuv
Thank you.
Re: How to use imageMagick to convert a ppm image to YUV422
Do you need the downsampling of Cb and Cr channels? Writing to file.ycbcr with -interlace partition gives
you 3 files, all full size. Oh, never mind, I see you tried that already. Looking at coders/ycbcr.c it appears
that downsampling is not an option. So you'd need to resize those two files afterwards as a separate
proces (convert -resize 50% file.Cb file-downsampled.Cb; convert -resize 50% file.Cr file-downsampled.Cr).
I guess you'd need to make sure that your input file has an even number of rows and columns.
you 3 files, all full size. Oh, never mind, I see you tried that already. Looking at coders/ycbcr.c it appears
that downsampling is not an option. So you'd need to resize those two files afterwards as a separate
proces (convert -resize 50% file.Cb file-downsampled.Cb; convert -resize 50% file.Cr file-downsampled.Cr).
I guess you'd need to make sure that your input file has an even number of rows and columns.
Re: How to use imageMagick to convert a ppm image to YUV422
Thanks Glen for your reply.
I tried that with my sample image Bretagne1 from http://www.openjpeg.org/index.php?menu=samples.
It has even row and column.
But I get this error:
I tried that with my sample image Bretagne1 from http://www.openjpeg.org/index.php?menu=samples.
It has even row and column.
But I get this error:
$ convert ~/Downloads/Bretagne1.ppm -interlace partition -colorspace YCbCr Bretagne2.ycbcr
$ convert -resize 50% ~/Downloads/Bretagne2.Cb ~/Downloads/Bretagne2-ds.Cb
convert: no decode delegate for this image format `/home/mike/Downloads/Bretagne2.Cb' @ error/constitute.c/ReadImage/532.
convert: missing an image filename `/home/mike/Downloads/Bretagne2-ds.Cb' @ error/convert.c/ConvertImageCommand/3011.