Author Topic: HDR Composition Script  (Read 17778 times)

Offline vicent_peris

  • PTeam Member
  • PixInsight Padawan
  • ****
  • Posts: 986
    • View Profile
    • http://www.astrofoto.es/
HDR Composition Script
« on: 2008 November 15 13:58:12 »
NOTE: The HDRComposition script has been superseded by the new HDRComposition tool. More information here:

http://pixinsight.com/forum/index.php?topic=2320.0

==================

Managing high dynamic ranges has never been so easy. We present here a HDR image compositing tool that, starting from raw calibrated data, allows us to achieve the result below, in just a few mouse clicks:



This image is composed of exposures ranging from 2.5 second to 30 minutes, acquired with a Canon 300D and FC-100 and 80ED telescopes by José Luis Lamadrid and me.

This script is based on the algorithm I published on this forum:

http://pixinsight.com/forum/viewtopic.php?t=422
http://pixinsight.com/forum/viewtopic.php?t=423

The JavaScript implementation of this algorithm has been created by Oriol Lehmkuhl, and it is distributed with version 1.3 of PixInsight.


The HDR Composition Algorithm

The algorithm composes high dynamic range linear images. This means that, for the whole dynamic range of the objects, linearity is preserved. So having a HDR linear image is equivalent to having a digital sensor with a multi-million electron photosite well depth.

To compose the HDR image, each indivual image is multiplied by a factor to match the flux of the other images in the stack. The final result is like a fragmented pyramid, where shorter exposures are superimposed over saturated areas of the longer ones:



To find the fitting factor between images, the algorithm compares the illumination differences in the same image regions between successive image pairs. For the example above, the 30 minute exposure has been multiplied by 0.004 to fit the illumination level of the 2.5 second exposure.


The Script Interface

The script interface is based on rather simple concepts. You have three main sections:

    The image selection interface, where you can select the images to combine.
    The parameters to control the HDR composition algorithm.
    Post-processing options to compress the dynamic range of the resulting HDR image.

First we must tell the script which images we want to combine. This is done by simply clicking the Add button and selecting the desired riles. The script will determine automatically which images have shorter and longer exposures.

The images being combined must be properly calibrated and registered. Keep in mind that this script doesn't performs the calibration and registration works. It only does the HDR composition and dynamic range compression work.

The algorithm parameters are divided into three sections. The first parameters are related to the intensity maps the we use to compare illumination levels between images. We need to define the selection limit for pixels between two illumination ranges. One illumination range must be higher than the other, thus we will name the two ranges as highlights and lowlights. The default parameters will usually do a good work; they set the highlight illumination limits to [0.6,0.8], and the lowlight ones to [0.2,0.4], being both intervals expressed in the [0,1] range. Keep in mind that we must know exactly what's the difference in illumination between the highlights and the lowlights, so it is a good practice to establish the lowlight high limit below the highlight low limit.

As we have said, the algorithm superimposes the shorter exposures over the saturated areas of the longer ones. For setting the illumination threshold of the longer exposure in which the shorter exposure is superimposed, the script builds a binary mask. Usually the default 0.8 value works fine. As always, accuracy is limited by noise, so the two images will never fit perfectly; the parameter Mask smoothness will smooth the joints between image pairs. Usually this is a very accurate algorithm, limited by the noise and sensor linearity, so smoothing the mask by removing only 2 - 3 pixels will work in most cases. The Mask growth parameter expands the mask to cover bloomings correctly, which is crucial if we are working with non-ABG CCD sensors.

We have three output image options. For very large dynamic range images (as the M42 presented at the beginning), working in the 64-bit floating point format is advisable. You have also the option to retrieve the calculated masks, for your convenience. Finally, there is an option to neutralize the sky background; this works very well for astronomical images, but usually makes no sense when composing daylight HDR images.

The third section performs the dynamic range compression through two basic steps:

    An image histogram modification to raise the illumination of the darkest areas.
    A HDR Wavelet Transform to compress the dynamic range of the HDR image.

Being the composition result a HDR linear image, we need a very small value for the midtones balance. The example M42 image has a 0.0002 midtones balance applied.

For a quick dynamic range compression, the script allows us to control two main parameters of the HDRWaveletTransform tool: The number of wavelet layers to be flattened, and the number of algorithm iterations. When we activate the post-processing options, the script will produce two images: the original HDR linear composition, and the processed image. These post-processing options let you see quickly if all went fine, so you can work on the original HDR composition to fine tune the results through PixInsight tools.


Examples

Here we present three additional examples of results obtained with this script. The first one is the Cat's Eye nebula with data acquired by Romano Corradi through the Nordic Optical Telescope at the Roque de los Muchachos Observatory, in the Canary Islands (Spain).

These data can be downloaded here: http://www.ing.iac.es/~rcorradi/HALOES/.

The result is the combination of various exposures through O-III (teal), H-alpha (orange) and N-II (red) narrow filters with the ALFOSC camera:

O-III: 6x5 min, 1x2 min and 1x30 sec.
H-alpha: 3x10 min, 1x100 sec.
N-II: 3x10min, 1x1 min.

Applying two iterations of the HDRWaveletTransform process with three layers, we can have the nebula structure exposed throughout its whole dynamic range:



To see this image at full resolution:

http://forum-images.pixinsight.com/legacy/HDRscript/ngc6543not2.jpg

(Note the bright and large haloes caused by the interference filters located near the telescope's focal plane).

Below you can see how the algorithm recovered the blooming areas. As the shorter exposures have a lower signal to noise ratio, we can see these areas with a higher contribution of the noise. But scaling of the exposures has been done perfectly, because any artificial illumination step can be seen in the result:





The second example is the NGC 7331 image done with the 3.5 meter Zeiss telescope at Calar Alto by Vicent Peris. The image was acquired through B and V Johnson filters and a r' SDSS filter. For each filter, ten and one minute exposures were acquired.

Here are the original stretched images:



And a crop on the nucleus of the original linear images, where we can see the bloomed galaxy core:



This is the result after composing the HDR image and postprocessing it with HDRWT and a moderate histogram stretching:



The last example is a "daylight" photo (it's a street at night) taken by Rogelio Bernal with a Canon 40D DSLR. Here is the original sequence of linear images:



Here you can see the composed HDR image with raised midtones:



And the processed HDR image:



With the help of HDRWaveletTransform and color saturation curves, we can recover the entire tonal range of the scene.


Conclusion

This script gives a one-minute solution to one of the hardest problems in astronomical image processing. But most importantly, this solution is based on simple but efficient algorithms, in a quest for absolute respect to the acquired data. Human intervention is reduced to a minimum, and the HDR composition process gives a resulting image of the object "as is". We no longer need "expert" but doubtful "copy and paste procedures": just have your real data in a few mouse clicks. Let's concentrate on extracting all the beauty from our images.


Acknowledgements

Special thanks to Rogelio Bernal, who let us experiment with his raw data, and to Juan Conejero, who kindly revised the script's source code.


Vicent.
« Last Edit: 2010 November 20 12:05:35 by Pleiades »

Offline Nocturnal

  • PixInsight Jedi Council Member
  • *******
  • Posts: 2727
    • View Profile
    • http://www.carpephoton.com
HDR Composition Script
« Reply #1 on: 2008 November 16 09:36:32 »
This looks very promising Vicent! I have some M42 subs that are very suitable for experimenting with this. I will try it soon and let you know how it went.
Best,

    Sander
---
Edge HD 1100
QHY-8 for imaging, IMG0H mono for guiding, video cameras for occulations
ASI224, QHY5L-IIc
HyperStar3
WO-M110ED+FR-III/TRF-2008
Takahashi EM-400
PIxInsight, DeepSkyStacker, PHD, Nebulosity

Offline Nocturnal

  • PixInsight Jedi Council Member
  • *******
  • Posts: 2727
    • View Profile
    • http://www.carpephoton.com
HDR Composition Script
« Reply #2 on: 2008 November 16 20:56:20 »
I did a quick experiment while waiting at the airport just now. I'm returning from the AIC where I met Jack Harvey.

I had a stack of 1m and 10m subs of M42 and used the default settings in the HDR utility to add them together. I then processed the results with just curves and histogram.

http://gallery.tungstentech.com/main.php?g2_itemId=950

I think it looks pretty darn nice, the core has more detail than an earlier version of just the 10m stack. Thanks Vicent!
Best,

    Sander
---
Edge HD 1100
QHY-8 for imaging, IMG0H mono for guiding, video cameras for occulations
ASI224, QHY5L-IIc
HyperStar3
WO-M110ED+FR-III/TRF-2008
Takahashi EM-400
PIxInsight, DeepSkyStacker, PHD, Nebulosity

Offline OriolLehmkuhl

  • PixInsight Addict
  • ***
  • Posts: 177
    • View Profile
    • http://www.astrosurf.com/brego-sky
HDR Composition Script
« Reply #3 on: 2008 November 17 01:11:42 »
Hi Sander,

after all this hard work with Vicent to build this script it's nice to see that work's fine with your data even with the default settings :) Congrats for this result!

Regards,

Offline Simon Hicks

  • PixInsight Old Hand
  • ****
  • Posts: 333
    • View Profile
HDR Composition Script
« Reply #4 on: 2008 November 20 02:14:59 »
Hi Vincent, Oriol,

Fantastic script! This is a really powerful one. Many thanks for investing the time to create it.

I have one quick question....the script looks at the relative intensity levels in the various images and scales them. It has no knowledge of the exposure times, or any other settings.

So I presume that instead of using different exposure times, I could have different ISO settings, or even a combination of the two?

So I could take some 0.5, 1, 5 and 10 minute images at ISO400, and then do some 10 minute images at ISO1600 and load them all into the script? As long as they are all linear calibrated images.

Regards
               Simon

Offline Jack Harvey

  • PTeam Member
  • PixInsight Padawan
  • ****
  • Posts: 975
    • View Profile
    • PegasusAstronomy.com & Starshadows.com
howdy
« Reply #5 on: 2008 November 20 06:44:53 »
Vincent yes I like the script.  However I am blown away by the Cats Eye you have done.  Fantastic resolution!

Jack
Jack Harvey, PTeam Member
Team Leader, SSRO/PROMPT Imaging Team, CTIO

Offline ManoloL

  • PixInsight Addict
  • ***
  • Posts: 220
    • View Profile
HDR Composition Script
« Reply #6 on: 2008 December 24 07:10:18 »
Hola a todos:
Finalmente he podido probar el script partiendo directamente de las imágenes que me ha generado DSS de unos grupos de exposiciones de 1, 5, 15, 60 y 300 seg.
Las imágenes las he alineado con DinamicAlignment y recortado 10 píxeles en la periferia. Las he reducido de tamaño a la mitad, pues sin reducción me quedo sin memoria, y he obtenido la imagen que muestro en una captura de pantalla de como queda al sencillamente ajustar el histograma:

http://wrunch.com/images/rgh1230131161b.jpg

No cabe duda que el script funciona extraordinariamente.
Muchas gracias por proporcionarnos esta estupenda herramienta.

Felices Navidades a todos.

Manolo L.
Saludos.

Manolo L.

Offline Jack Harvey

  • PTeam Member
  • PixInsight Padawan
  • ****
  • Posts: 975
    • View Profile
    • PegasusAstronomy.com & Starshadows.com
Java Script ver
« Reply #7 on: 2008 December 24 14:13:40 »
AM I missing something?  I put two 16 bit images in the Add and then execute the Java Script for HDR compostion.  An hour later, all I see on the screen is the clock showing the program still working.  Uisng a Macbook Pro with 4 gb ram which is a pretty fast machine so whats up?
Jack Harvey, PTeam Member
Team Leader, SSRO/PROMPT Imaging Team, CTIO

Offline Nocturnal

  • PixInsight Jedi Council Member
  • *******
  • Posts: 2727
    • View Profile
    • http://www.carpephoton.com
HDR Composition Script
« Reply #8 on: 2008 December 24 14:20:08 »
Hi Jack,

if you can upload the images somewhere I'd be glad to give it a try.
Best,

    Sander
---
Edge HD 1100
QHY-8 for imaging, IMG0H mono for guiding, video cameras for occulations
ASI224, QHY5L-IIc
HyperStar3
WO-M110ED+FR-III/TRF-2008
Takahashi EM-400
PIxInsight, DeepSkyStacker, PHD, Nebulosity

Offline Jack Harvey

  • PTeam Member
  • PixInsight Padawan
  • ****
  • Posts: 975
    • View Profile
    • PegasusAstronomy.com & Starshadows.com
Images
« Reply #9 on: 2008 December 24 14:46:12 »
Are you on Skype as I can send them to you with the Skype FTP?
Jack Harvey, PTeam Member
Team Leader, SSRO/PROMPT Imaging Team, CTIO

Offline vicent_peris

  • PTeam Member
  • PixInsight Padawan
  • ****
  • Posts: 986
    • View Profile
    • http://www.astrofoto.es/
HDR Composition Script
« Reply #10 on: 2008 December 24 15:59:51 »
It's not normal, Jack... I have an Asus notebook with 2 GB RAM and I can combine four or five, 5 - 6 megapixel images without problems... Usually the script takes its time because it's not native C++ code, but not as much as one hour! For two images, perhaps 1 minute! Could you upload two stretched JPEGs so we can take a look?

Manolo, me das una alegría navideña, hombre.  :lol: Me alegro mucho de que te vaya bien!! Si quieres juntarlas todas a resolución original, puedes hacerlo por partes. Por ejemplo, la de 1 con la de 5, la de 1 y 5 con la de 15, la de 1, 5 y 15 con la de 60, etc. Te recomiendo que nada más combinar le pases unos HDRWavelets un tanto agresivos para que salgan todas las mentiras.  :wink: Así puedes comprobar si ha funcionado bien.


Feliz Navidad / Merry Christmas
Vicent.

Offline Jack Harvey

  • PTeam Member
  • PixInsight Padawan
  • ****
  • Posts: 975
    • View Profile
    • PegasusAstronomy.com & Starshadows.com
Images
« Reply #11 on: 2008 December 24 16:07:12 »
Since I am now using the OS operating system I can no longer use Smart FTP.  SO I can transfer the files (jpegs) via Skypte FTP if you use Skype?
Jack Harvey, PTeam Member
Team Leader, SSRO/PROMPT Imaging Team, CTIO

Offline Jack Harvey

  • PTeam Member
  • PixInsight Padawan
  • ****
  • Posts: 975
    • View Profile
    • PegasusAstronomy.com & Starshadows.com
HDR Composition Script
« Reply #12 on: 2008 December 24 16:12:56 »
Sander and VIncent  Can you get them off this Picasa web album?

http://picasaweb.google.com/coyyote/AstronomyWorkingFIle#
Jack Harvey, PTeam Member
Team Leader, SSRO/PROMPT Imaging Team, CTIO

Offline vicent_peris

  • PTeam Member
  • PixInsight Padawan
  • ****
  • Posts: 986
    • View Profile
    • http://www.astrofoto.es/
HDR Composition Script
« Reply #13 on: 2008 December 24 16:17:57 »
Jack,

I really don't see anything strange in these photos... how much megapixels are?


Vicent.

Offline Jack Harvey

  • PTeam Member
  • PixInsight Padawan
  • ****
  • Posts: 975
    • View Profile
    • PegasusAstronomy.com & Starshadows.com
image
« Reply #14 on: 2008 December 24 17:29:52 »
Came off a STL 11000 so 11 megapixel I believe
Jack Harvey, PTeam Member
Team Leader, SSRO/PROMPT Imaging Team, CTIO