Extracting highlights from HDR image

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?".
Post Reply
imbennu
Posts: 5
Joined: 2015-11-16T14:35:33-07:00
Authentication code: 1151

Extracting highlights from HDR image

Post by imbennu »

Hi all,
Maybe a very basic question, but after googling a bit, I found no example on this specific kind of operation.
Basically I'd like to extract highlights from input HDR image (*.hdr) to a PNG (or JPG)
As an example, lets imagine the typical sunny landscape: the produced map should only have a smoothed white spot corresponding to the sun and everything else black.

I tried a few commands, such as

Code: Select all

convert <source.hdr> -levels 80,100% <dest.png>
and a few others using sigmoidal contrast, but results looks too posterized.

Is there a specifc operator or multiple passes before obtaining such map?
Thanks!
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Extracting highlights from HDR image

Post by fmw42 »

try just using the grayscale image as a mask. Unix syntax:

Code: Select all

convert image \( -clone 0 -colorspace gray \) -compose multiply -composite result
You can apply other operators such as -gamma, -levels or -sigmoidal-contrast to the grayscale image if that helps.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Extracting highlights from HDR image

Post by snibgo »

imbennu wrote:... the produced map should only have a smoothed white spot corresponding to the sun and everything else black. ... results looks too posterized.
What range of input values do you have? Digital cameras tend to "burn out" highlights, so your source image might have a very small number of values that correspond to the sun.

But I'm not sure what you want. Perhaps you want your output to be white where the sun is, and black elsewhere. If so, a simple "-threshold" might do.

As always, sample input and out images might explain the problem.
snibgo's IM pages: im.snibgo.com
imbennu
Posts: 5
Joined: 2015-11-16T14:35:33-07:00
Authentication code: 1151

Re: Extracting highlights from HDR image

Post by imbennu »

fmw42 wrote:try just using the grayscale image as a mask. Unix syntax:

Code: Select all

convert image \( -clone -colorspace gray \) -compose multiply -composite result
You can apply other operators such as -gamma, -levels or -sigmoidal-contrast to the grayscale image if that helps.
I'm trying this, I'm on windows so I removed the '\' escape:

Code: Select all

convert <src.hdr> ( -clone -colorspace gray ) -compose multiply -composite <dst.png>
although it gives me error:

Code: Select all

convert.exe: invalid argument for option `-clone': -colorspace @ error/convert.c/ConvertImageCommand/978
but maybe I'm missing something

EDIT:
..yes:

Code: Select all

convert <src.hdr> ( -clone 0 -colorspace gray ) -compose multiply -composite <dst.png>
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Extracting highlights from HDR image

Post by fmw42 »

My typo, it should be either -clone 0 or +clone

You could also try

Code: Select all

convert image -black-threshold XX% result
Pick a suitable XX%
imbennu
Posts: 5
Joined: 2015-11-16T14:35:33-07:00
Authentication code: 1151

Re: Extracting highlights from HDR image

Post by imbennu »

Yep, I tried also threshold...
But gamma gave best results,

Code: Select all

( -clone 0 -colorspace Gray -gamma 0.1 )
using very low values around 0.1 and then converted to grayscale.

Thanks!! :)
Russell
Posts: 1
Joined: 2016-10-12T09:16:38-07:00
Authentication code: 1151

Re: Extracting highlights from HDR image

Post by Russell »

fmw42 wrote:My typo, it should be either -clone 0 or +clone

You could also try

Code: Select all

convert iimage -black-threshold XX% result
Pick a suitable XX%
Great tips guys!
I was struggling with the same problem...
Thank you so much :)
Post Reply