Page 1 of 1

Extracting highlights from HDR image

Posted: 2015-11-16T14:45:46-07:00
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!

Re: Extracting highlights from HDR image

Posted: 2015-11-16T14:55:07-07:00
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.

Re: Extracting highlights from HDR image

Posted: 2015-11-16T15:44:26-07:00
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.

Re: Extracting highlights from HDR image

Posted: 2015-11-16T16:04:59-07:00
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>

Re: Extracting highlights from HDR image

Posted: 2015-11-16T16:35:47-07:00
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%

Re: Extracting highlights from HDR image

Posted: 2015-11-16T17:24:44-07:00
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!! :)

Re: Extracting highlights from HDR image

Posted: 2016-10-12T09:22:56-07:00
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 :)