Hi everyone
I need to convert an image to single precision grayscale and then to save that image as a PGM file. I'm using the Magick++ API.
I can convert the image to PGM no problem but am unsure about the single precision element - is this as simple as dropping image.depth to 32?
How would I go about setting an image to single precision with Magick++?
Many thanks in advance.
Convert to single precision grayscale PGM
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Convert to single precision grayscale PGM
What do you mean by single precision? All images are digital integer values in Q18 (0-255) or Q16 (0-65535). There is no fraction unless you are using HDRI and a compatible format such as MIFF, TIFF, PFM that support fractions and negative values.
Re: Convert to single precision grayscale PGM
That's what I don't know. I think it means 32-bit floating point format - does that make sense?
In the ImageMagick documentation itself, it says:
"Use -size and -depth to specify the image width, height, and depth. To specify a single precision floating-point format, use -define quantum:format=floating-point. Set the depth to 32 for single precision floats, 64 for double precision, and 16 for half-precision."
How do I set the quantum:format through Magick++?
Many thanks for your help.
In the ImageMagick documentation itself, it says:
"Use -size and -depth to specify the image width, height, and depth. To specify a single precision floating-point format, use -define quantum:format=floating-point. Set the depth to 32 for single precision floats, 64 for double precision, and 16 for half-precision."
How do I set the quantum:format through Magick++?
Many thanks for your help.
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Convert to single precision grayscale PGM
What is your objective? How are you going to use this precision? Will it be for internal processing or for output image formats? For the former, IM already does floating point format internally. To get floating point format for output images, I compile IM in Q16 HDRI.
You will need to explain in more detail what you really want, so Magick or someone on the IM team can help you more.
But you likely need to recompile IM to get output formats as floats and use certain image formats such as TIFF, MIFF, PFM.
see http://www.imagemagick.org/script/advan ... lation.php
and
http://www.imagemagick.org/Usage/basics/#hdri
and
http://www.imagemagick.org/Usage/formats/#tiff (which is where it talks about -define quantum:format=floating-point but you need to be in Q32 at least or HDRI)
If I understand PGM format (http://netpbm.sourceforge.net/doc/pgm.html), it does not support floats only integers. You will need either TIFF or PFM (http://netpbm.sourceforge.net/doc/pfm.html).
You will need to explain in more detail what you really want, so Magick or someone on the IM team can help you more.
But you likely need to recompile IM to get output formats as floats and use certain image formats such as TIFF, MIFF, PFM.
see http://www.imagemagick.org/script/advan ... lation.php
and
http://www.imagemagick.org/Usage/basics/#hdri
and
http://www.imagemagick.org/Usage/formats/#tiff (which is where it talks about -define quantum:format=floating-point but you need to be in Q32 at least or HDRI)
If I understand PGM format (http://netpbm.sourceforge.net/doc/pgm.html), it does not support floats only integers. You will need either TIFF or PFM (http://netpbm.sourceforge.net/doc/pfm.html).