Does Image Magick have Tonemapping operators?

Discuss digital image processing techniques and algorithms. We encourage its application to ImageMagick but you can discuss any software solutions here.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Does Image Magick have Tonemapping operators?

Post by fmw42 »

rnbc wrote: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.

In the dualtonemap, I am not doing any frequency filtering, simply non-linear intensity/contrast adjustments in two overlapping ranges. In comparison to the examples you showed for this image, in my opinion, this was as good as the ones you showed. My gaussian redist, clearly did not work as well with such a broad dynamic range, but was better than using a unform distribution. Both do not filter frequencies. They adjust the histogram distribution.

The only frequency manipulation was the post-process sharpening.

Nevertheless, I will try to look at some of the algorithms if they are clearly explained and have enough mathematical detail that I can do something with them as scripts. If coding is needed, then that is beyond my capabilities. Do you have a "favorite" method from their list of pfstmo techniques?
rnbc
Posts: 109
Joined: 2010-04-11T18:27:46-07:00
Authentication code: 8675308

Re: Does Image Magick have Tonemapping operators?

Post by rnbc »

I noticed the (large) halos, so I assumed you were using a highpass.

I think mantiuk06 is one of the best available. It does true wonders! But durand02 and some others are also good.

From the images I made available here as EXRs...

mantiuk06:

Image

durand02

Image

I think it's truly wonderful how they can convey the sense of contrast of the original scene in such a limited output contrast, without destroying detail and without obvious halos.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Does Image Magick have Tonemapping operators?

Post by fmw42 »

Yes, haloing is a potential downside to my dualtonemap approach. But the results are quite reasonable even without all your other processing for channel separate contrast and and gamma correction and saturation, which if added to my dualtonemap or redist could improve things further. It would be interesting to see your results without all the extra processing so as to compare apples to apples from the basic tonemapping effects.

However, I will download your two other images and see what happens.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Does Image Magick have Tonemapping operators?

Post by fmw42 »

Here are my results from your next image. Not quite as good as yours, but I don't know what other processing you added besides the psfto command.

Resize Image by 25%
convert sala_com_janela.exr -resize 25% sala_com_janela2.exr
convert sala_com_janela.exr -resize 25% -auto-level -gamma 2 sala_com_janela3.exr
convert sala_com_janela.exr -resize 25% -auto-level -gamma 2 sala_com_janela3.png

Image

Redist (Gaussian)
redist 50,50,40 sala_com_janela3.exr sala_com_janela3_rdist_rgb_50x50x40.jpg

Image

Add some saturation:
convert sala_com_janela3_rdist_rgb_50x50x40.jpg -modulate 100,150 convert sala_com_janela3_rdist_rgb_50x50x40_mod100x150.jpg

Image


Dualtonemap:
dualtonemap -c -r 100 -m both -s 0,15,2 -h 10,200 sala_com_janela2.exr sala_com_janela2_dualtone_c_r100_s0x15x2_h10x200.jpg

Image


Add some saturation:
convert sala_com_janela2_c_r100_s0x15x2_h10x200.jpg -modulate 100,150 sala_com_janela2_dualtone_c_r100_s0x15x2_h10x200_mod100x150.jpg

Image


Here is my other duotonemap script result:

Duotonemap:

duotonemap -r 100 -l 0.4 -h 0.6 -t 20 sala_com_janela3.png sala_com_janela3_duotone_r100_l0p4_h0p6_t20.jpg

Image


Add some brightness and contrast:
convert sala_com_janela3_duotone_r100_l0p4_h0p6_t20.jpg -brightness-contrast 10,20 sala_com_janela3_duotone_r100_l0p4_h0p6_t20_bc10x20.jpg

Image


Add some saturation also:
convert sala_com_janela3_duotone_r100_l0p4_h0p6_t20_bc10x20.jpg -modulate 100,150 sala_com_janela3_duotone_r100_l0p4_h0p6_t20_bc10x20_mod100x150.jpg

Image
Last edited by fmw42 on 2011-08-08T22:08:51-07:00, edited 2 times in total.
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Does Image Magick have Tonemapping operators?

Post by anthony »

Well it looks as if that "mantiuk06" tonemap does produce a far better result.
The results produced by Fred either has low contrast in the window, or low contrast in the room.

So it comes down to working out exactly how they work.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Does Image Magick have Tonemapping operators?

Post by fmw42 »

anthony wrote:Well it looks as if that "mantiuk06" tonemap does produce a far better result.
The results produced by Fred either has low contrast in the window, or low contrast in the room.

So it comes down to working out exactly how they work.

It would appear to be true, especially if his results are not postprocessed with other contrast and saturation effects.
rnbc
Posts: 109
Joined: 2010-04-11T18:27:46-07:00
Authentication code: 8675308

Re: Does Image Magick have Tonemapping operators?

Post by rnbc »

The exact command line is a simplification of the general pipeline I suggested, since I only did tonemapping and post-processing, without blending with the high contrast scene again in the middle:

Code: Select all

~tfc/pfstools/installed/bin/pfsin --frames 0:1:0 sala_com_janela.exr | ~tfc/pfstmo/installed/bin/pfstmo_mantiuk06 --factor 0.3 --saturation 0.8 | pfsgamma --gamma 2.2 --mul 1.0 | pfsoutexr --compression PIZ --fix-halfmax temp00.exr ; ~tfc/ImageMagick/installed/bin/convert temp00.exr -auto-level -gamma 3 -sigmoidal-contrast 6x50% -set option:modulate:colorspace hsb -modulate 100,150,100 -auto-level -linear-stretch 0.01%x0% -clamp -depth 8 -interlace line -quality 98 -sampling-factor 1x1 sala_com_janela.jpg
rnbc
Posts: 109
Joined: 2010-04-11T18:27:46-07:00
Authentication code: 8675308

Re: Does Image Magick have Tonemapping operators?

Post by rnbc »

So yes, there is some post-processing, but the magic, shall we say, is made by mantiuk06.

I think you should read the papers about those algorithms because there is a lot of tricks they use to convey contrast when there isn't contrast, and some of them are not obvious. For example, increasing the saturation of the areas where contrast had to be more severely decreased.
rnbc
Posts: 109
Joined: 2010-04-11T18:27:46-07:00
Authentication code: 8675308

Re: Does Image Magick have Tonemapping operators?

Post by rnbc »

Try this one, without any post-processsing:

Code: Select all

~tfc/pfstools/installed/bin/pfsin --frames 0:1:0 sala_com_janela.exr | ~tfc/pfstmo/installed/bin/pfstmo_mantiuk06 --factor 0.3 --saturation 0.8 | pfsgamma --gamma 2.2 --mul 1.0 | pfsoutexr --compression PIZ --fix-halfmax temp00.exr ; ~tfc/ImageMagick/installed/bin/convert temp00.exr -auto-level -clamp -depth 8 -interlace line -quality 98 -sampling-factor 1x1 sala_com_janela.jpg
The result is more natural, darker but balanced.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Does Image Magick have Tonemapping operators?

Post by fmw42 »

rnbc wrote:So yes, there is some post-processing, but the magic, shall we say, is made by mantiuk06.

I think you should read the papers about those algorithms because there is a lot of tricks they use to convey contrast when there isn't contrast, and some of them are not obvious. For example, increasing the saturation of the areas where contrast had to be more severely decreased.
Yes, I started to look over some of the papers. But most appear to be more complex than I could script. Saturation increase is a trick I even used in some of my post-processing as well as sharpening. The key to me is how well they work without any post processing.

I have just been playing with using -evaluate log 10000 as a preprocess in place of -gamma 2. In the one image I have been testing, it seems to work slightly better than -gamma (i.e. a power law ,e.g. -evaluate pow 0.5 = -gamma 2)

I would agree that things get much harder when the dynamic range is so much higher.

If the psfto algorithms are open source, then perhaps Anthony or Magick should look at the code and see if some or all of these tonemapping techniques could be folded into IM via a delegate library.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Does Image Magick have Tonemapping operators?

Post by fmw42 »

rnbc wrote:Try this one, without any post-processsing:

Code: Select all

~tfc/pfstools/installed/bin/pfsin --frames 0:1:0 sala_com_janela.exr | ~tfc/pfstmo/installed/bin/pfstmo_mantiuk06 --factor 0.3 --saturation 0.8 | pfsgamma --gamma 2.2 --mul 1.0 | pfsoutexr --compression PIZ --fix-halfmax temp00.exr ; ~tfc/ImageMagick/installed/bin/convert temp00.exr -auto-level -clamp -depth 8 -interlace line -quality 98 -sampling-factor 1x1 sala_com_janela.jpg
The result is more natural, darker but balanced.

As I do not have pfsto installed, perhaps you could just post the resulting image.

However, it looks like you are doing some pre and post processing (saturation and gamma) with psfto and IM.

Out of curiosity, what is with the compression PIZ? What is that?
rnbc
Posts: 109
Joined: 2010-04-11T18:27:46-07:00
Authentication code: 8675308

Re: Does Image Magick have Tonemapping operators?

Post by rnbc »

You must do some kind of post, since pfstools works in a linear scale space and monitors work in gamma ~2.0 or similar. Also the huge range of possible values inside an EXR (negative values, whiter than white) must be mapped into 8bit somehow... but in the last example my only "post" was conversion into gamma 2.2 and mapping into 0-1 (or 0-255 in case of ImageMagick).

Here is the result:

Image

PIZ is a wavelet lossless compression, part of the OpenEXR standard.

Yes, all those algorithms are open source and well documented, but you won't be able to "script" them... they will require some heavy C programming inside ImageMagick, and the infrastructure for some of them isn't really there (absolute luminance values, for instance).

PS: That last version, full screen, in a nice monitor, it looks as if I'm in that room.... fabulous! I prefer the version I posted previously to be seen in a bright background (in a forum, etc...).
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Does Image Magick have Tonemapping operators?

Post by fmw42 »

I have been playing around with something like the Durand Bilateral Filtering in HSB space with log rather than gamma and processing of the base and detail images and the saturation. Here is what I got so far:

convert sala_com_janela2.exr -auto-level -evaluate log 10000 -colorspace HSB -separate \
\( -clone 1 -evaluate multiply 2 \) \
\( -clone 2 -selective-blur 0x5+10% \) \
\( -clone 2 -clone 4 +swap -compose divide -composite -level 40,100% \) \
\( -clone 4 +level 30x90% \) \
\( -clone 5 -clone 6 -compose multiply -composite \) \
-delete 1,2,4,5,6 -set colorspace HSB -combine -colorspace RGB \
sala_com_janela2_al_log10000_hsb_sb_0x5x10_sat2_l40x100_pl30x90.jpg

Image


convert sala_com_janela2.exr -auto-level -evaluate log 10000 -colorspace HSB -separate \
\( -clone 1 -evaluate multiply 1.5 \) \
\( -clone 2 -selective-blur 0x5+10% \) \
\( -clone 2 -clone 4 +swap -compose divide -composite -level 40,100% \) \
\( -clone 4 +level 30x90% \) \
\( -clone 5 -clone 6 -compose multiply -composite \) \
-delete 1,2,4,5,6 -set colorspace HSB -combine -colorspace RGB \
sala_com_janela2_al_log10000_hsb_sb_0x5x10_sat1p5_l40x100_pl30x90.jpg

Image

Note there appears to be some strange "ringing-like" artifacts introduced by the -selective-blur approx to bilateral filtering on the left wall.

Replacing the -selective-blur with -adaptive-blur seems to remove those artifacts:


convert sala_com_janela2.exr -auto-level -evaluate log 10000 -colorspace HSB -separate \
\( -clone 1 -evaluate multiply 2 \) \
\( -clone 2 -adaptive-blur 0x5 \) \
\( -clone 2 -clone 4 +swap -compose divide -composite -level 40,100% \) \
\( -clone 4 +level 30x90% -write tmp4.png \) \
\( -clone 5 -clone 6 -compose multiply -composite \) \
-delete 1,2,4,5,6 -set colorspace HSB -combine -colorspace RGB \
sala_com_janela2_al_log10000_hsb_ab_0x5_sat2_l40x100_pl30x90.jpg


Image

Using the same technique, here is you other image:


convert zona_zen_vodafone2.exr -auto-level -evaluate log 10000 -colorspace HSB -separate \
\( -clone 1 -evaluate multiply 2 \) \
\( -clone 2 -adaptive-blur 0x5 \) \
\( -clone 2 -clone 4 +swap -compose divide -composite -level 40,100% \) \
\( -clone 4 +level 20x90% -write tmp4.png \) \
\( -clone 5 -clone 6 -compose multiply -composite \) \
-delete 1,2,4,5,6 -set colorspace HSB -combine -colorspace RGB \
zona_zen_vodafone2_al_log10000_hsb_ab_0x5_sat2_l40x100_pl20x90.jpg

Image

Here is the first image with the same technique:


convert cascata_praia_da_ursa4.exr -auto-level -evaluate log 10000 -colorspace HSB -separate \
\( -clone 1 -evaluate multiply 2.5 \) \
\( -clone 2 -adaptive-blur 0x5 \) \
\( -clone 2 -clone 4 +swap -compose divide -composite -level 60,100% \) \
\( -clone 4 +level 0x90% \) \
\( -clone 5 -clone 6 -compose multiply -composite \) \
-delete 1,2,4,5,6 -set colorspace HSB -combine -colorspace RGB \
cascata_praia_da_ursa4_al_log10000_hsb_ab_0x5_sat2p5_l60x100_p0x90.jpg

Image

convert cascata_praia_da_ursa4.exr -auto-level -evaluate log 5000 -colorspace HSB -separate \
\( -clone 1 -evaluate multiply 2.5 \) \
\( -clone 2 -adaptive-blur 0x5 \) \
\( -clone 2 -clone 4 +swap -compose divide -composite -level 60,100% \) \
\( -clone 4 +level 0x90% \) \
\( -clone 5 -clone 6 -compose multiply -composite \) \
-delete 1,2,4,5,6 -set colorspace HSB -combine -colorspace RGB \
cascata_praia_da_ursa4_al_log5000_hsb_ab_0x5_sat2p5_l60x100_p0x90.jpg

Image
rnbc
Posts: 109
Joined: 2010-04-11T18:27:46-07:00
Authentication code: 8675308

Re: Does Image Magick have Tonemapping operators?

Post by rnbc »

The first images have small scale ringing, as you say. Maybe you can solve that simply by processing a larger image and than resampling to a smaller one?

The last images have ugly halos... no good.

Your efforts are interesting nevertheless.

I think it would be really useful to implement some sort of generic bilateral filtering in imagemagick. Both for HDR and noise reduction, etc...
rnbc
Posts: 109
Joined: 2010-04-11T18:27:46-07:00
Authentication code: 8675308

Re: Does Image Magick have Tonemapping operators?

Post by rnbc »

Just a few thoughts...

When defining a bilateral filter the question of "distance calculation" always arises, since this is where the magic is, so to say, and otherwise it's just a simple Gaussian blur. Some suggestions:

- Luminance distance
- RGB distance, as the distance between points in 3D space
- Alpha channel distance
- Some other function?...
- k*(d^2), where d is one of the previous distances
- k*(d^x), where d is one of the previous distances
- User defined function?...
Post Reply