Page 3 of 5

Re: Does Image Magick have Tonemapping operators?

Posted: 2011-07-26T07:03:54-07:00
by ssilk
I'm working with Image Magick under Windows, and I've never been successful using PFStools in Windows. I've tried Cygwin approaches, as well as recompiling the library but there are way too many dependencies for the latter, and the former just didn't work for me. So, your suggestion would only work in Linux.

Re: Does Image Magick have Tonemapping operators?

Posted: 2011-07-26T15:28:00-07:00
by rnbc
ssilk, you're quite right: I also tried pfstools in windows a few months ago, and never managed to get everything working, so I ended up with a Linux setup.

May I suggest a virtual machine? Performance impact shouldn't be large since this programs are command line, and don't use any specific hardware function. They are mostly number crunchers.

Re: Does Image Magick have Tonemapping operators?

Posted: 2011-07-26T22:14:16-07:00
by anthony
rnbc wrote:Also, why reinvent the wheel? PFSTools interfaces quite nicely with ImageMagic. Just use the HDRI enabled version and openexr file format to interface between them, or something alike. It's even possible to build an entire pipeline to generate and process HDRs from raws and deliver nice looking finished images using dcraw + imagemagick + pfscalibration + pfstools + pfstmo.
Can you give us (well me as I have never used PFSTools) some pointers and, perhaps display an example. Maybe even the original image this discussion has been using as an example.

Re: Does Image Magick have Tonemapping operators?

Posted: 2011-07-27T17:57:25-07:00
by rnbc
Yes anthony, I won't forget and will post a full example, from source images to final, detailing the full pipeline. Just give me a few days ;)

I did it, that's why I'm saying it can be done. Just have to dig around a bit, and don't have the time right now.

Re: Does Image Magick have Tonemapping operators?

Posted: 2011-07-27T19:14:48-07:00
by anthony
Thanks look forward to it.

Generating final images from HDR data

Posted: 2011-08-06T16:21:12-07:00
by rnbc
Hello again.

Here I'll give an example of how to process a file containing high dynamic range image data into a final image, ready for display, by using both pfstools and imagemagick. To generate the high dynamic range data you'll need a few exposures of the same scene, and I recommend reading the manual for PFScalibration. Of course, you can also use HDR data generated with any other program.

I'll use pfstmo_mantiuk06 as a tonemapping operator, but any other tonemapping operator could be used, or you might even not need a tonemapping operator, as you'll see.

Since some of those operators cut global contrast too much for my taste, but are quite effective in reducing contrast in a "natural" way I'll use a direct mapping simultaneously, and blend both results, so that you can give more or less weight to the tonemapping operator, to suit your tastes, instead of simply not using those "aggressive" tonemapping operators.

These are examples only! You should change parameters, and tonemapping methods, and generally play around with pfstools to suit your taste! Reading the manual is also advisable, even more since I included placeholders instead of numeric values for the parameters.

The values I suggest later have worked for this image:

Image
--> click for larger version <--


They probably won't work for most other images.

This was copied/adapted from a php script I made to automatically process HDR images a year ago. I hope there aren't any gross mistakes...

Ok, so let's start with our EXR file containing the data, input.exr :

1 - Tonemapping

pfsin --frames 0:1:0 input.exr | \
pfstmo_mantiuk06 --factor $factor --saturation $saturation | \
pfsgamma --gamma 2.2 --mul 1.0 | \
pfsoutexr --compression PIZ --fix-halfmax temp00.exr

2 - Contrast stretch (direct mapping)

convert input.exr -auto-level -linear-stretch $black%x$white% -gamma 1.0 -compress Piz temp01.exr

3 - Blending both results

composite -blend $blend_factor% temp00.exr temp01.exr -matte -compress Piz temp02.exr

4 - Final image processing

convert temp02.exr -auto-level -gamma $gamma_correction_luminance \
-channel Red -gamma $gamma_correction_red \
-channel Green -gamma $gamma_correction_green \ // setting the RGB gamma separately allows changes in white balance
-channel Blue -gamma $gamma_correction_blue \
+channel -depth 16
//-sigmoidal contrast $sigmoidal_contrast_factorx$sigmoidal_contrast_grey% \ // use sigmoidal contrast only if needed
//+sigmoidal contrast $sigmoidal_contrast_factorx$sigmoidal_contrast_grey% \ // you can decrease contrast also
-set option:modulate:colorspace hsb -modulate 100,$saturation_correction,100 \ // hsb avoids color clamping
-auto-level -linear-stretch $contrast_stretch_black%x$contrast_stretch_white% -clamp \
-depth 8 -interlace line -quality 98 -sampling-factor 1x1 output.jpg

Example parameters for 1:

$factor = 0.3
$saturation = 0.8

Example parameters for 2:

$black = 0 // black out zero pixels
$white = 0 // white out zero pixels

Example parameters for 3:

$blend_factor = 50 // blend half-half

Example parameters for 4:

$gamma_correction_luminance = 3
$gamma_correction_red = 1.04
$gamma_correction_green = 1.0
$gamma_correction_blue =1.1
$sigmoidal_contrast_factor = 2.5
$sigmoidal_contrast_grey = 33
$saturation_correction = 200
$contrast_stretch_black = 0.01
$contrast_stretch_white = 0.01

Suggestions, questions, please go ahead :)

Re: Does Image Magick have Tonemapping operators?

Posted: 2011-08-06T17:19:19-07:00
by fmw42
As not all of us have this software, perhaps you would not mind posting your end result.

Re: Does Image Magick have Tonemapping operators?

Posted: 2011-08-06T17:42:23-07:00
by rnbc
fmw42 wrote:As not all of us have this software, perhaps you would not mind posting your end result.
See above, I've included the final result in the post ;)

Also in the same flickr set you have more examples of images made with that pipeline, with pfstmo_mantiuk06 and other tonemapping operators.

Anyway, the idea was to show how one can make a practical pipeline for HDRI processing using ImageMagick and PFSTools, so if you don't have PFSTools my explanation is probably useless...

Re: Does Image Magick have Tonemapping operators?

Posted: 2011-08-07T11:16:35-07:00
by fmw42
Thanks. Interesting Results! You have many different results that look quite different. I suppose there are many different approaches to tonemapping and one result may look good to one person and not so good to others. Or the results may depend upon what features you want to enhance.

Anyway, here are a few results from my scripts, redist (gaussian historgram redistribution) and dualtonemap.

Original (reduced by 4x)
Image


Redist:
redist -m RGB 50,40,60 cascata.png cascata_rdist_rgb_50x40x60.jpg
Image

Same but with post process sharpening:
convert cascata_rdist_rgb_50x40x60.png -sharpen 0x3 cascata_rdist_rgb_50x40x60_sharp0x3.jpg
Image


Dualtonemap:
dualtonemap -m both -s 0,70,1.2 -h 0,90 cascata.png cascata_dualtonemap_s0x70x1p2_h0x90.jpg
Image


Same but with post process sharpening:

convert cascata_dualtonemap_s0x70x1p2_h0x90.png -sharpen 0x3 cascata_dualtonemap_s0x70x1p2_h0x90_sharp0x3.jpg
Image

Re: Does Image Magick have Tonemapping operators?

Posted: 2011-08-07T16:24:32-07:00
by rnbc
fmw42, the thing is: you should try your approaches with a real high dynamic range image. Try this ones, sorry about the low speed but that's my PC in a relatively low speed connection.

The image I've shown was obtained from the data in cascata_praia_da_ursa.exr, and sala_com_janela.exr is a real challenge, featuring a huge contrast.

PS: If you open them in photoshop some will be all white, other all black. You should move the exposure slider (left inferior corner) to see the image.

Re: Does Image Magick have Tonemapping operators?

Posted: 2011-08-07T19:32:47-07:00
by fmw42
All I get is bilevel and completely white in IM. Same in my old photoshop cs. I am not experience with HDR images. So I guess I will need to recompile IM as Q16 HDRI to get anything meaningful? Perhaps my system won't deal with .exr. Do you have any other format and can you provide a smaller image for cascata_praia_da_ursa?

Re: Does Image Magick have Tonemapping operators?

Posted: 2011-08-07T20:15:56-07:00
by rnbc
Try:

convert input.exr -auto-level -gamma 2.0 -depth 16 output.png

I made the result available in the same place. It actually displays well because this image has a relatively low contrast. With higher contrast images you really need tonemapping.

This will give you a 16 bit png with the luminance values directly mapped, using y=sqrt(x), allowing a potential dynamic range of 32 EVs. Should be enough for any picture. Anyway, EXR should work fine with an imagemagick compiled with HDRI support.

Re: Does Image Magick have Tonemapping operators?

Posted: 2011-08-07T21:36:09-07:00
by fmw42
convert cascata_praia_da_ursa.exr -auto-level -gamma 2.0 -depth 16 cascata_praia_da_ursa.png

is still totally white, probably because the input image is fully white due to not downloading in HDRI mode.


Image: cascata_praia_da_ursa.png
Format: PNG (Portable Network Graphics)
Class: PseudoClass
Geometry: 1760x2640+0+0
Resolution: 72x72
Print size: 24.4444x36.6667
Units: Undefined
Type: Bilevel
Base type: Bilevel
Endianess: Undefined
Colorspace: Gray
Depth: 8/1-bit
Channel depth:
gray: 1-bit
Channel statistics:
Gray:
min: 255 (1)
max: 255 (1)
mean: 255 (1)


So I guess I will have to recompile to Q16 HDRI tomorrow.

Thanks

Re: Does Image Magick have Tonemapping operators?

Posted: 2011-08-08T15:30:57-07:00
by fmw42
Here is my result on the one image after recompiling to Q16 HDRI.

Resize the image:
convert cascata_praia_da_ursa.exr -resize 25% cascata_praia_da_ursa2.exr

Prepare for Display:
convert cascata_praia_da_ursa2.exr -auto-level -gamma 2 cascata_praia_da_ursa3.exr
convert cascata_praia_da_ursa3.exr cascata_praia_da_ursa3.jpg

Image


Dualtonemap Script:

dualtonemap -c -m both -s 0,70,2 -h 0,80 cascata_praia_da_ursa2.exr cascata_praia_da_ursa2_dualtonemap_c_s0x70x2_h0x80.jpg

Image

convert cascata_praia_da_ursa2_dualtonemap_c_s0x70x2_h0x80.jpg -sharpen 0x3 cascata_praia_da_ursa2_dualtonemap_c_s0x70x2_h0x80_sharp0x3.jpg

Image


Redist Script:



redist 50,40,80 cascata_praia_da_ursa3.exr cascata_praia_da_ursa3_rdist_rgb_50x40x80.jpg

Image

convert cascata_praia_da_ursa3_rdist_rgb_50x40x80.jpg -sharpen 0x3 cascata_praia_da_ursa3_rdist_rgb_50x40x80_sharp0x3.jpg

Image

Re: Does Image Magick have Tonemapping operators?

Posted: 2011-08-08T16:53:44-07:00
by rnbc
Well, basically you're filtering out low frequencies. Works somewhat, but the results are not that good...

Now, before reinventing the wheel I think you should study the tonemapping algorithms available in pfstmo, because if you have such nice ideas before reading about them, I wonder what you'll be able to do afterwards. Some of those articles (each algoritms has associated articles, and they are quite readable) are true wonders.