Change DPI while keeping resolution

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?".
Jimbo
Posts: 23
Joined: 2019-08-26T12:24:48-07:00
Authentication code: 1152

Re: Change DPI while keeping resolution

Post by Jimbo »

By the way, of the HDRI supported image formats: Tiff, Pfm, and EXR, only Tiff allows a dpi (-density, -units PixelsPerInch) setting in its header.
PSD/PSB allows dpi settings, but IM only creates 8 or 16bit version of this format currently, so it does not support HDRI.

See this thread: https://www.imagemagick.org/discourse-s ... 43#p168543

- Jimbo
Jimbo
Posts: 23
Joined: 2019-08-26T12:24:48-07:00
Authentication code: 1152

Re: Change DPI while keeping resolution

Post by Jimbo »

By the way, as far as setting dpi for images...
Many image formats simply do not have 'dpi' as part of their specification; EXR and PFM being two of them.

Using '-set':
So, even if you figure out how to declare dpi followed by an integer value and add it to the image's header using "-set," it is likely that the software then reading the resulting image will ignore the added dpi value of the image because an outside vendor's software will simply ignore the dpi setting because their image library does not look for variables that are not part of the specification.

So far, the only fully support HDR image formats are EXR and PFM; neither of which have a dpi in their spec.

PSDs/PSBs are written out as 16bit only, and as a result, they truncate any data outside of normalized color space (<0 and >1).

Here is a thread that discusses the error, where to find it, and how one person compiled their own version to create 32bit PSDs/PSBs.
[ULR]https://imagemagick.org/discourse-serve ... 12#p167912[/URL]

Warning: the solution is described, not presented and is incomplete.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Change DPI while keeping resolution

Post by fmw42 »

TIFF and MIFF and MPC also support HDRI. With TIFF and MIFF, you need to add -define quantum:format=floating-point
Jimbo
Posts: 23
Joined: 2019-08-26T12:24:48-07:00
Authentication code: 1152

Re: Change DPI while keeping resolution

Post by Jimbo »

Thanks for that clarification. Are the IM formats MIFF and MPC getting more widely adapted by other software?

- Jimbo
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Change DPI while keeping resolution

Post by fmw42 »

Not that I know about. I do not know of any other software that will read either.
Jimbo
Posts: 23
Joined: 2019-08-26T12:24:48-07:00
Authentication code: 1152

Re: Change DPI while keeping resolution

Post by Jimbo »

The tiff format has a file size limit of 4 Gbytes. For the work I am doing (very large files for print), tiff is not really an option.
My best hope, so far, is that the PSD format will be corrected to allow 32bit floating point mode in IM.

- Jimbo
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: Change DPI while keeping resolution

Post by magick »

Standard TIFF file is limited to 4GB. The bigtiff delegate library can write BigTIFF files, which contain 64-bit offsets to directories and image data. For a BigTIFF file there is no practical limit to the size of a file.
Jimbo
Posts: 23
Joined: 2019-08-26T12:24:48-07:00
Authentication code: 1152

Re: Change DPI while keeping resolution

Post by Jimbo »

magick wrote: 2019-09-07T17:49:28-07:00 Standard TIFF file is limited to 4GB. The bigtiff delegate library can write BigTIFF files, which contain 64-bit offsets to directories and image data. For a BigTIFF file there is no practical limit to the size of a file.

Thanks for that heads up.

Do you know the image library name to add bigTiff to my delegates?
I've been looking around for a corresponding listing in the community, but have yet to find one.

Cheers.
- Jimbo
Jimbo
Posts: 23
Joined: 2019-08-26T12:24:48-07:00
Authentication code: 1152

Re: Change DPI while keeping resolution

Post by Jimbo »

fmw42 wrote: 2019-09-06T11:29:09-07:00 TIFF and MIFF and MPC also support HDRI. With TIFF and MIFF, you need to add -define quantum:format=floating-point
Tiff
Thank you, Fred. This helped me get tiff output at 32bit with a simple convert like this:
convert IN.exr -define quantum:format=floating-point -colorspace RGB OUT.tif

Although, in converting from exr, the resulting gamma is off, and I've not found a combination
of "-set gamma (float)" to have an effect in the above command by placing it either before or after the define.

DPX
Also, I have been trying several convert combinations to get the same thing for the DPX format, but have failed at getting 32bit thus far.
Seems like there is something missing.

With this command:
convert IN.exr -set gamma 1.0 -set reference-black 95 -set reference-white 685 -colorspace RGB OUT.dpx

I get a dpx file that is 16bits per channel, so the highs and lows get clipped to 0 and 1, but other than that the image looks okay.

I will keep looking and trying things, but if anyone has a method for passing the gamma setting to the tiff output in one go,
or a method for converting 16bit half-float EXR files to 32bit DPX files, I would be grateful.

Cheers.
- Jimbo
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Change DPI while keeping resolution

Post by snibgo »

Jimbo wrote: convert IN.exr -define quantum:format=floating-point -colorspace RGB OUT.tif
... in converting from exr, the resulting gamma is off, ...
You use v7. I suggest you use "magick", not "convert".

Assuming IN.exr is encoded as sRGB, your "-colorspace RGB" will convert it to linear RGB. That is, the encoding will still have the sRGB primaries, but without the non-linear tone response curve.

But if IN.exr isn't sRGB, "-colorspace RGB" will do something bad.
snibgo's IM pages: im.snibgo.com
Jimbo
Posts: 23
Joined: 2019-08-26T12:24:48-07:00
Authentication code: 1152

Re: Change DPI while keeping resolution

Post by Jimbo »

snibgo wrote: 2019-09-08T16:29:35-07:00
Jimbo wrote: convert IN.exr -define quantum:format=floating-point -colorspace RGB OUT.tif
... in converting from exr, the resulting gamma is off, ...
You use v7. I suggest you use "magick", not "convert".

Assuming IN.exr is encoded as sRGB, your "-colorspace RGB" will convert it to linear RGB. That is, the encoding will still have the sRGB primaries, but without the non-linear tone response curve.

But if IN.exr isn't sRGB, "-colorspace RGB" will do something bad.
Thanks, snigbo. I will try "Magick" and see if I get a different result.

Yes, typically exrs are created in Linear colorspace, not sRGB.
- Jimbo
Jimbo
Posts: 23
Joined: 2019-08-26T12:24:48-07:00
Authentication code: 1152

Re: Change DPI while keeping resolution

Post by Jimbo »

Here is my IM info:
Version: ImageMagick 7.0.8-59 Q16 x86_64 2019-08-05 https://imagemagick.org
Copyright: © 1999-2019 ImageMagick Studio LLC
License: https://imagemagick.org/script/license.php
Features: Cipher DPC HDRI Modules OpenMP(3.1)
Delegates (built-in): bzlib freetype heic jng jp2 jpeg lcms ltdl lzma openexr png tiff webp xml zlib

-----

Okay, I had some more time this morning and continued exploring how to convert exr 16bit half-floats to DPX linear 32bit images, thereby keeping the complete range of values from one file to the other.

So far, I have not found a command that allows a dpx file to become 32 bit float.

Normally, to convert to dpx from exr, I do this:
magick in.exr -gamma 2.2 -set reference-black 95 -set reference-white 685 out.dpx
OR
magick in.exr -colorspace LOG -set gamma 1.0 -set reference-black 95 -set reference-white 685 -colorspace RGB -gamma 2.2 out.dpx
OR
magick in.exr -colorspace LOG -set gamma 1.0 -set reference-black 95 -set reference-white 685 -colorspace RGB -gamma 2.2 -define format:floating-point out.dpx
OR
magick in.exr -colorspace LOG -set gamma 1.0 -set reference-black 95 -set reference-white 685 -colorspace RGB -gamma 2.2 -define format:floating-point -depth 16 out.dpx
OR
magick in.exr -colorspace LOG -set gamma 1.0 -set reference-black 95 -set reference-white 685 -colorspace RGB -gamma 2.2 -depth 16 -define format:floating-point out.dpx

Any of these commands create an eye-pleasing 16bits per channel linear dpx, but because of the default quantum setting, the result loses any values below 0 or above 1 in the resulting dpx that were contained in the input exr.

But if I try to fix the quantum problem by changing -depth 16 to -depth 32, the resulting image's channels are offset, resulting in a "scrambled" image.

If you have an idea on how to create a 32bits per channel dpx from an exr input successfully, please let me know.

Thanks.
- Jimbo
Jimbo
Posts: 23
Joined: 2019-08-26T12:24:48-07:00
Authentication code: 1152

Re: Change DPI while keeping resolution

Post by Jimbo »

magick wrote: 2019-09-07T17:49:28-07:00 Standard TIFF file is limited to 4GB. The bigtiff delegate library can write BigTIFF files, which contain 64-bit offsets to directories and image data. For a BigTIFF file there is no practical limit to the size of a file.
Thanks, magick.
I have libtiff 4.0 installed for my tiff delegates.

I see in my delegates that I do have this:
TIFF* TIFF rw+ Tagged Image File Format (LIBTIFF, Version 4.0.10)
TIFF64* TIFF rw+ Tagged Image File Format (64-bit) (LIBTIFF, Version 4.0.10)

If the BigTIFF that you refer to the same as the TIFF64 listed?
And, if so, is there any flag that I need in order to create TIFF64 as opposed to TIFF?

Thanks.
- Jimbo
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Change DPI while keeping resolution

Post by fmw42 »

Jimbo
Posts: 23
Joined: 2019-08-26T12:24:48-07:00
Authentication code: 1152

Re: Change DPI while keeping resolution

Post by Jimbo »

fmw42 wrote: 2019-09-16T15:20:51-07:00 Not the same. Search Google or check http://bigtiff.org and https://www.awaresystems.be/imaging/tiff/bigtiff.html
Thank you for the second set of information (I'd already been made aware of bigtiff.org by magick,
but neither of the links instruct me on how to call BigTIFF output in IM.

I tried:
magick in.exr -define quantum:format=floating-point out.tiff
AND
magick in.exr -define quantum:format=floating-point BigTIFF:out.tif

But both of those calls used the older tiff definition, and failed at 4Gbyte output.

I see that I have libtiff 4.0.10_1 in my version of IM, so, according to bigtiff.org, BigTiff is supported (since libTIff v.3.8.2).
Also, the format is supposed to "automatically" convert to bigTiff once the threshold of 4 Gbytes is reached.

It seems as thought what I have should work, but does not.

Perhaps I am missing a vital bit of info for making this work?

UPDATE:
THIS WORKS: (the TIFF64 call on the output file causes the output format to be the newer BigTIFF format)
magick in.exr -define quantum:format=floating-point TIFF64:out.tif
(You must have at least libtiff v.3.8.2 for BigTIFF format to be present).

Cheers.
- Jimbo
Last edited by Jimbo on 2019-09-16T18:08:37-07:00, edited 3 times in total.
Post Reply