Page 1 of 1
Image convertion
Posted: 2010-07-21T05:54:02-07:00
by GnnG
Hi all,
I'm having some troubles in my program and would like to know if ImageMagick could help me:
- If I obtained an image from YUV420 pixel format, ImageMagick can convert it to RGB?
- and if I have a RGB blob converted form a YUV420, ImageMagick can save it in JPEG and/or JPEG2000 format?
Thanks so much,
Best regards.
GnnG.
Re: Image convertion
Posted: 2010-07-22T07:53:07-07:00
by GnnG
I didn't find a way to convert my YUV pointer to RGB, but I got a conversion manually and than write the image to JPEG:
Code: Select all
try {
string file = "/home/guilherme/Desktop/img/";
file.append(name);
file.append(".jpeg"); // THIS LINE
Image img(320, 240, "RGB", CharPixel, rgb24);
img.write(file);
} catch (Magick::Exception &e) {
cout << "Error: " << e.what() << endl;
}
// this works
but when I trade the marked line above to
jp2, it writes a corrupted image.
Please, how can i save in jp2.
PS. When I ran the configure to install IM, in the summary of configure is:
Code: Select all
Option Value
-------------------------------------------------------------------------------
Shared libraries --enable-shared=yes yes
Static libraries --enable-static=yes yes
Module support --with-modules=no no
GNU ld --with-gnu-ld=yes yes
Quantum depth --with-quantum-depth=16 16
High Dynamic Range Imagery
--enable-hdri=no no
Delegate Configuration:
BZLIB --with-bzlib=yes no
Autotrace --with-autotrace=no no
Dejavu fonts --with-dejavu-font-dir=default none
DJVU --with-djvu=yes no
DPS --with-dps=yes no
FFTW --with-fftw=yes no
FlashPIX --with-fpx=yes no
FontConfig --with-fontconfig=no no
FreeType --with-freetype=yes no
GhostPCL None pcl6 (unknown)
GhostXPS None gxps (unknown)
Ghostscript None gs (8.71)
Ghostscript fonts --with-gs-font-dir=default /usr/share/fonts/type1/gsfonts/
Ghostscript lib --with-gslib=no no
Graphviz --with-gvc=yes no
JBIG --with-jbig=yes no
JPEG v1 --with-jpeg=yes yes
JPEG-2000 --with-jp2=yes no // NO?
LCMS v1 --with-lcms=yes no
LCMS v2 --with-lcms2=yes no
LQR --with-lqr=yes no
Magick++ --with-magick-plus-plus=yes yes
OpenEXR --with-openexr=yes no
PERL --with-perl=no no
PNG --with-png=yes no
RSVG --with-rsvg=no no
TIFF --with-tiff=yes no
Windows fonts --with-windows-font-dir= none
WMF --with-wmf=yes no
X11 --with-x= no
XML --with-xml=no no
ZLIB --with-zlib=yes no
could be here the problem?
Re: Image convertion
Posted: 2010-07-22T09:23:41-07:00
by fmw42
For JP2 files, you need the Jasper delegate libary installed (and then reinstall IM). To see what delegates you have installed type
convert -list configure
look at the line starting with DELEGATES. See if jp2 is included (or any other file format that you need).
For example on my system:
DELEGATES bzlib fftw fontconfig freetype gs jpeg jng jp2 lcms lqr mpeg openexr png rsvg tiff x11 xml zlib
Re: Image convertion
Posted: 2010-07-26T06:13:35-07:00
by GnnG
fmw42 wrote:For JP2 files, you need the Jasper delegate libary installed (and then reinstall IM). To see what delegates you have installed type
convert -list configure
look at the line starting with DELEGATES. See if jp2 is included (or any other file format that you need).
For example on my system:
DELEGATES bzlib fftw fontconfig freetype gs jpeg jng jp2 lcms lqr mpeg openexr png rsvg tiff x11 xml zlib
fmw42, thanks for your help,
I've installed the Jasper Delegate and now it's working but, my camera don't support direct RGB capture so am capturing in BGR and then save to JPEG or JP2 with IM, when I save it in JPEG, this is very fast (~115 milliseconds / img = 24Kb) and when I save in JP2 (~300 millis / 300Kb), JP2 wouldn't have to be faster and lighter?
Thanks you.
Re: Image convertion
Posted: 2010-07-29T11:30:22-07:00
by GnnG
Nobody can explain me that?! is it normal?!
Re: Image convertion
Posted: 2010-07-29T13:47:43-07:00
by Drarakel
Why should JP2 be faster?
For JPG and JP2, you should choose reasonable settings for your pictures. Options like "
-quality", "
-sampling-factor" or "
-interlace" (and some "-define" settings) influence the quality and the file size.
The current default for JPG for example (when IM detects no settings in the input image) is quality 92 and sampling-factor 2x2 (and interlace none). Not sure about JP2.
See also here:
http://www.imagemagick.org/Usage/formats/#jpg
Re: Image convertion
Posted: 2010-07-29T15:00:22-07:00
by fmw42
Drarakel wrote:
The current default for JPG for example (when IM detects no settings in the input image) is quality 92 and sampling-factor 2x2 (and interlace none).
From
http://www.imagemagick.org/script/comma ... hp#quality, it says
"The default is to use the estimate quality of your input image otherwise 85"
Re: Image convertion
Posted: 2010-07-29T21:08:48-07:00
by Drarakel
fmw42 wrote:it says
"The default is to use the estimate quality of your input image otherwise 85"
Yeah, but that's outdated. For JPG, it's currently as follows:
The interlace setting is always 'none' - unless a different setting is specified manually.
For "quality" and "sampling-factor", a manual setting overrides the setting from the input image (if existing) - which overrides the default setting. The default in IM for RGB is quality
92 and sampling-factor
2x2. (To be precise, IM shows it as 2x2,1x1,1x1. For CMYK, the default sampling-factor is 1x1,1x1,1x1,1x1. With Grayscale, it's always 1x1.)
The default for the sampling-factor in RGB JPGs can be different, if one specifies only the quality setting manually. A quality setting of 89 or lower then results in sampling-factor 2x2, while a quality setting of 90 or higher results in 1x1.
And the quality values for JPG can go from 1 to 100. (It seems that a quality value 0 is passed to the encoder, but it results in a output with the default of quality 92.)
I tried JP2 now: The default quality setting for that format is
100 (lossless), I believe.
When compared to JPG, one usually has to specify a lower quality setting for JP2 to achieve the same file size.
Oh, and the current default 'quality' for PNG (of course, it has a completely different meaning there) seems to be
75 (not 85).
Re: Image convertion
Posted: 2010-07-29T21:29:28-07:00
by fmw42
Very interesting! I have been assuming that the default would most frequently end up at 85.
The docs say:
"For the JPEG and MPEG image formats, quality is 0 (lowest image quality and highest compression) to 100 (best quality but least effective compression). The default is to use the estimate quality of your input image otherwise 85."
I tried
convert logo: logo.jpg
In this case, identify -verbose does say 92. So I wonder what is going on?
I guess that in this case, IM is estimating the quality (at 92) from logo: rather than using 85. But I wonder how it gets 92 from that image.
I wonder if 92 is the norm or just in this case or a few cases?
Have you tried a number of images and always get 92? I get 92 for rose: and also netscape: and also when I convert zelda3.png to jpg.
So either it is frequently "estimating" at 92 or the default value is 92 and not 85?
A document change may be in order or at least an explanation of what is going on to make so many images convert to jpg quality of 92 rather than 85 by default.
Re: Image convertion
Posted: 2010-07-29T22:26:14-07:00
by Drarakel
fmw42 wrote:I guess that in this case, IM is estimating the quality (at 92) from logo: rather than using 85.
No. (Well, I guess, the word 'estimating' can be confusing here.) If your input file is a JPG (only then!), then ImageMagick can take the JPG output settings for quality and sampling-factor from this input file. The quality setting is sometimes 'estimated', as there's no simple 'quality' field in a JPG, but quantization matrices ('standard' quantization matrices fit to a 'exact' quality setting, and custom quantization matrices result in an 'approximate' quality value that doesn't have to be 100% correct).
When the input file is not JPG, then there is no 'quality', thus the default values must be used.
And as I said, the default quality setting for JPG is 92.
Re: Image convertion
Posted: 2010-07-30T09:25:47-07:00
by fmw42
Then it looks like the documentation is in error and needs updating. I will try to inquire about this in the bugs forum