Image convertion

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
GnnG

Image convertion

Post 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.
GnnG

Re: Image convertion

Post 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?
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Image convertion

Post 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
GnnG

Re: Image convertion

Post 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.
GnnG

Re: Image convertion

Post by GnnG »

Nobody can explain me that?! is it normal?!
Drarakel
Posts: 547
Joined: 2010-04-07T12:36:59-07:00
Authentication code: 8675308

Re: Image convertion

Post 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
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Image convertion

Post 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"
Drarakel
Posts: 547
Joined: 2010-04-07T12:36:59-07:00
Authentication code: 8675308

Re: Image convertion

Post 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).
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Image convertion

Post 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.
Drarakel
Posts: 547
Joined: 2010-04-07T12:36:59-07:00
Authentication code: 8675308

Re: Image convertion

Post 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.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Image convertion

Post 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
Post Reply