PixInsight Forum (historical)

PixInsight => Tutorials and Processing Examples => Topic started by: vicent_peris on 2008 November 15 13:58:12

Title: HDR Composition Script
Post by: vicent_peris 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:

(http://forum-images.pixinsight.com/legacy/HDRscript/m42_hdr_text.jpg)

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:

(http://forum-images.pixinsight.com/legacy/HDRscript/pyramid2.jpg)

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:


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:


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/ (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:

(http://forum-images.pixinsight.com/legacy/HDRscript/ngc6543not_300.jpg)

To see this image at full resolution:

http://forum-images.pixinsight.com/legacy/HDRscript/ngc6543not2.jpg (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:

(http://forum-images.pixinsight.com/legacy/HDRscript/ngc6543not_blooming1.jpg)

(http://forum-images.pixinsight.com/legacy/HDRscript/ngc6543not_blooming2.jpg)

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:

(http://forum-images.pixinsight.com/legacy/HDRscript/ngc7331_stretched.jpg)

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

(http://forum-images.pixinsight.com/legacy/HDRscript/ngc7331_linear.jpg)

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

(http://forum-images.pixinsight.com/legacy/HDRscript/ngc7331_hdr.jpg)

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:

(http://forum-images.pixinsight.com/legacy/HDRscript/street_RBA_sequence.jpg)

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

(http://forum-images.pixinsight.com/legacy/HDRscript/street_RBA_stretched.jpg)

And the processed HDR image:

(http://forum-images.pixinsight.com/legacy/HDRscript/street_RBA_HDRWT.jpg)

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.
Title: HDR Composition Script
Post by: Nocturnal 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.
Title: HDR Composition Script
Post by: Nocturnal 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!
Title: HDR Composition Script
Post by: OriolLehmkuhl 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,
Title: HDR Composition Script
Post by: Simon Hicks 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
Title: howdy
Post by: Jack Harvey 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
Title: HDR Composition Script
Post by: ManoloL 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.
Title: Java Script ver
Post by: Jack Harvey 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?
Title: HDR Composition Script
Post by: Nocturnal 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.
Title: Images
Post by: Jack Harvey on 2008 December 24 14:46:12
Are you on Skype as I can send them to you with the Skype FTP?
Title: HDR Composition Script
Post by: vicent_peris 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.
Title: Images
Post by: Jack Harvey 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?
Title: HDR Composition Script
Post by: Jack Harvey 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#
Title: HDR Composition Script
Post by: vicent_peris on 2008 December 24 16:17:57
Jack,

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


Vicent.
Title: image
Post by: Jack Harvey on 2008 December 24 17:29:52
Came off a STL 11000 so 11 megapixel I believe
Title: HDR Composition Script
Post by: Nocturnal on 2008 December 24 19:36:44
Hi Jack,

I combined stacked and calibrated but  unprocessed FITS files, not stretched jpegs. I'm not sure if that's important. I can recommend uploading your images to http://skydrive.live.com . It's a free service, 25 GB storage in 50 MB chunks. I do have Skype (qadude) but I'm not sure if that's a good way to transfer large files but you're welcome to try.
Title: Nope
Post by: Jack Harvey on 2008 December 25 07:07:32
Won't work with fits images either.  Wonder if its the version that is with the OS system????
Title: HDR Composition Script
Post by: Jack Harvey on 2008 December 25 08:22:24
Sander got the HDR to run on my images so it might most likely be a bug in the OS version???
Title: HDR Composition Script
Post by: Jack Harvey on 2008 December 28 08:53:27
Today again tried to do an HDR on a couple of 2 Mb tif images and again all I get with the Mac OS is the watch grinding away forever.  No result.  These are pretty small images and should have been done ASAP so must be a bug.
Title: HDR Composition Script
Post by: Juan Conejero on 2008 December 28 11:40:02
Jack,

I have tried the script with your images (from the Picassa album), and I've found a couple things:


- First, there is an error in the script source code that has been bundled with the Mac OS X release (version 1.4.2.461; I have to check if the same problem is present in the current Windows and Linux versions, but I think it isn't). To fix this problem, please do the following:

1. Open the Processing Console window. Then enter the following command in the command line (better copy and paste from this post to avoid errors):

Code: [Select]
open /Applications/PixInsight.app/Contents/MacOS/src/scripts/HDRComposition.js

2. The command above will open the script's source code file and load it in the Script Editor window. On the Script Editor, scroll to the bottom of the text and locate a line that is exactly like this:

Code: [Select]
if ( data.images < 2 )

It's line number 1273 (you can see the current line number written at the bottom of the Script Editor window.

3. Edit line 1273 above to change it as follows:

Code: [Select]
if ( data.images.length < 2 )

4. Save the script file by selecting File > Save on Script Editor's menu, ** not ** on PixInsight's main menu!

5. Now you can run the script as usual (Script > Utilities > ...)


- The second thing that I've found is that the script certainly takes a long time to process your images. I guess this happens because the script is iterating on every pixel of the images. Keep in mind that a script is interpreted JavaScript code, not native code that executes directly on the processor, so it is necessarily slow. If you have the patience to wait, the script will do its job. On my Mac it has taken about two minutes with your images.

Anyway, we'll try to improve the script to overcome this problem. Or maybe we'll have better news regarding HDR composition, but my lips are sealed  8)
Title: HDR Composition Script
Post by: Jack Harvey on 2008 December 29 07:03:58
Hooray!  Thanks
Title: Re: HDR Composition Script
Post by: ManoloL on 2009 August 05 13:34:22
Hola a todos:

Recientemente he comenzado a captar imágenes con una CCD en color (QHY8) y uno de los primeros trabajos que puedo mostrar sin avergonzarme es una M31.
En el procesado de dicha imagen he utilizado el script, pero me he encontrado unos hechos llamativos en las imágenes.
A continuación muestro un recorte muy aumentado de una de las exposiciones, ya debayerizada, de 15 minutos de la zona de transición al núcleo saturado de la galaxia:

(http://fotografiaastronomica.com/files/posted_images/user_41_centrogalxdby.jpg)

en ella aparecen unos anillos coloreados en la zona de transición.
El origen de estos artefactos se entiende al observar el mismo recorte de la imagen sin debayerizar:

(http://fotografiaastronomica.com/files/posted_images/user_41_centrogalxsindby.jpg)

Se puede ver como los sensores de los distintos colores tienen una sensibilidad muy diferente al color del nucleo que en principio se puede considerar como blanco.
Según se acerca al núcleo primero se saturan los rojos, luego los verdes y finalmente los azules. Ello provoca los anillos citados. De hecho he visto que empiezan a saturarse los pixeles rojos mientras los colindantes de azul no llegan al 50% de saturación.
En el procesado con el script con los parámetros por defecto me aparecia un llamativo anillo azul alrededor del nucleo.
Bajando los valores de los parámetros de la iluminación alta, y el valor para generar la máscara he mejorado algo la imagen, aunque sigo percibiendo algunas coloraciones extrañas en las zonas donde la imagen de la exposición larga ha sido sustituida por la de las exposiciones más cortas.
Lógicamente pienso que hay que generar una máscara que haga sustituir a los pixeles en cuanto uno de los canales este saturado, pero como los otros dos no lo estan y supongo que se usa la luminancia para el cálculo de la máscara, hay que ser más conservador y disminuir su valor, viendo la lúminancia que tienen los primeros píxeles con el canal rojo saturado.
El hecho de que los resultados son mejores bajando los parámetros del mapa de iluminación alta, es algo que he observado mediante sucesivas pruebas, pero no alcanzo a explicarme los motivos por los que ocurre
Espero que unas explicaciones y unos consejos al respecto no distraigan demasiado de sus ocupaciones a Vicent.


Hello everyone:

I apologize for not being able to correct all the mistakes of the automatic translator

I have recently begun to capture images with a color CCD (QHY8) and one of the first works that I can show without embarrassing that he is an M31
In the processing of the image I used the script, but I found some striking facts in the images.
Below shows a very grown from a cutting of the exhibits, and debayerized of 15 minutes of the transition zone to the saturated core of the galaxy:

http://fotografiaastronomica.com/files/posted_images/user_41_centrogalxdby.jpg

There are some colored rings at the transition.
The origin of these artifacts are meant to observe the same cut of the image without debayericer:

http://fotografiaastronomica.com/files/posted_images/user_41_centrogalxsindby.jpg

You can see how the sensors of different colors have different sensitivity to the color of the nucleus which in principle can be seen as white.
As it nears the core will saturate first red, then green and finally blue. This causes the rings above. In fact I've seen that start to saturate the red pixels while the adjacent blue do not reach 50% saturation.
In the processing script with the default settings, I found a striking blue ring around the core.
Lowering the values of the parameters of the high illumination, and the value to generate the mask image I have improved somewhat, but I receive some strange colors in the areas where the image of the long exposure has been replaced with shorter exposures .
Obviously I believe that we must create a mask that makes replacing the pixels in one of the channels that saturated, but as the other two are not suppose to be used for calculating the luminance of the mask, let's be more conservative and decrease its value, seeing that the luminance pixels are first saturated with the red channel.
The fact that the results are better by reducing the parameters of the map of high-lighting, is something that I have observed through successive tests, but fail to explain why that happens.
I hope that some explanations and advice in this respect does not distract too much from their occupations to Vicent.


Greetings.