snibgo's ImageMagick pages

HDRI

ImageMagick can handle High Dynamic Range Images. It does this by storing and processing pixels as floating-point numbers instead of integers.

Distribution

If you compile IM yourself, you can configure it for HDRI. The precompiled alpha release of v7 includes HDRI, and we use that on this page. Note that v7 also has magick.exe, with the same options as convert.exe.

Outside quantum and small values

Black is zero. HDRI still has the concept of quantum, which defines the white level. For Q16 HDRI, white is 65535. But pixels can take values outside the range from zero to quantum.

%IMGF%magick xc:white -evaluate Multiply 2 -evaluate Divide 2 txt: 
# ImageMagick pixel enumeration: 1,1,65535,srgb
0,0: (100%,100%,100%)  #FFFFFFFFFFFF  white

If the IM is an integer build, the multiply will have no effect, so the result will be quantum/2, mid-grey. For an HDRI build, the multiply is effective but then cancelled by the divide so the result is white.

When data is written to txt:, it is clamped between 0 and quantum.

Create a gradient image and manipulate it.

%IMGF%magick -size 100x200 gradient: ^
  -rotate 90 ^
  hdri_grad.png

%IM%convert -size 100x200 gradient:#fffffe-#010000 ^
  -rotate 90 ^
  hdri_grad.png
hdri_grad.png

Read it and write it.

%IMGF%magick ^
  hdri_grad.png ^
  hdri_gradSv.png

BUG it shouldn't be red. Reported.

hdri_gradSv.png

Expand it out of range at both ends. Also write numerical values.

%IMGF%magick ^
  hdri_grad.png ^
  -evaluate Multiply 2 -evaluate subtract 50%% ^
  -format "%%[min] %%[max]" -write info:hdri_grad2.lis ^
  hdri_grad2.png
-32768 98302
hdri_grad2.png

The same again, but followed by "-auto-level".

%IMGF%magick ^
  hdri_grad.png ^
  -evaluate Multiply 2 -evaluate Subtract 50%% ^
  -auto-level ^
  hdri_grad3.png
hdri_grad3.png

The same again, but followed by "-level".

%IMGF%magick ^
  hdri_grad.png ^
  -evaluate Multiply 2 -evaluate Subtract 50%% ^
  -level -50%%,150%% ^
  hdri_grad4.png
hdri_grad4.png

Reduce contrast heavily with "+level". Also write numerical values.

%IMGF%magick ^
  hdri_grad.png ^
  +level 50%%,50.00002%% ^
  -precision 10 -format "%%[min] %%[max]" -write info:hdri_grad5.lis ^
  hdri_grad5.png
32767.5 32767.51367
hdri_grad5.png

The same again, but followed by "-auto-level".

%IMGF%magick ^
  hdri_grad.png ^
  +level 50%%,50.00002%% ^
  -auto-level ^
  hdri_grad6.png

The banding is caused by hitting the floating point quantum, the smallest difference that can be represented.

hdri_grad6.png

Repeat the last with 16-bit integer, reducing the difference between levels to get roughly the same banding.

%IM%convert ^
  hdri_grad.png ^
  +level 50%%,50.01%% ^
  -auto-level ^
  hdri_grad7.png

So floating point quantum is roughly 1/500 the integer quantum, about 9 bits.

hdri_grad7.png

We can demonstrate the most negative and most positive values that can be represented.

%IMGF%magick xc:Black -evaluate Add 1e38 -format "%%[max]\n" info:
%IMGF%magick xc:Black -evaluate Add 1e39 -format "%%[max]\n" info:
%IMGF%magick xc:Black -evaluate Subtract 1e38 -format "%%[max]\n" info:
%IMGF%magick xc:Black -evaluate Subtract 1e39 -format "%%[max]\n" info:
1e+038
1.#INF
-1e+038
-1.#INF

auto-level brings the values within zero to quantum; contrast-stretch doesn't. clamp.

TODO: can we do histograms? Yes.
%IMGF%magick ^
  rose: -depth 16 ^
  -evaluate multiply 2 -evaluate subtract 50% ^
  -define histogram:unique-colors=true -format "%c" ^
  histogram:info:a.txt

This works in the usual way but in each row the integer pixel values are clamped. The floating-point percentage values seem correct.

Files

Use "-depth 32 -define quantum:format=floating-point".

GRAY: RAW:
%IMGF%magick ^
  hdri_grad.png ^
  -evaluate Multiply 2 -evaluate subtract 50%% ^
  -depth 32 ^
  -define quantum:format=floating-point ^
  -compress Zip ^
  -write hdri_save.tiff ^
  -write hdri_save.miff ^
  hdri_save.png

%IMGF%identify hdri_save.tiff 
%IMGF%identify hdri_save.miff 
%IMGF%identify hdri_save.png 
hdri_save.tiff TIFF 200x100 200x100+0+0 32-bit sRGB 4.17KB 0.000u 0:00.000
hdri_save.miff MIFF 200x100 200x100+0+0 32-bit TrueColor sRGB 6.91KB 0.000u 0:00.000
hdri_save.png PNG 200x100 200x100+0+0 16-bit sRGB 788B 0.000u 0:00.000

So TIFF and MIFF can store 32 bit/channel (and these are floating point), but PNG is limited to 16 bits/channel (integer).

hdri_grad2.tiff

All images on this page were created by the commands shown, using:

%IMGF%identify -version
%IM%identify -version
Version: ImageMagick 7.0.0-0 Q16 x64 2014-06-07 http://www.imagemagick.org
Copyright: Copyright (C) 1999-2014 ImageMagick Studio LLC
Features: DPC Modules HDRI OpenMP
Delegates: bzlib cairo freetype jbig jng jp2 jpeg lcms lqr pangocairo png ps rsvg tiff webp xml zlib

Version: ImageMagick 6.9.0-0 Q16 x64 2014-11-14 http://www.imagemagick.org
Copyright: Copyright (C) 1999-2014 ImageMagick Studio LLC
Features: DPC OpenMP
Delegates (built-in): bzlib cairo freetype jbig jng jp2 jpeg lcms lqr pangocairo png ps rsvg tiff webp xml zlib

Installed from ImageMagick-7.0.0-0~beta20140110-Q16-x64-dll.exe at http://imagemagick.org/download/beta/.

Source file for this web page is hdri.h1. To re-create this web page, execute "procH1 hdri".


This page, including the images, is my copyright. Anyone is permitted to use or adapt any of the code, scripts or images for any purpose, including commercial use.

Anyone is permitted to re-publish this page, but only for non-commercial use.

Anyone is permitted to link to this page, including for commercial use.


Page version v1.0 11-Jan-2014.

Page created 13-Oct-2015 21:59:51.

Copyright © 2015 Alan Gibson.