Night sky image processing - Part 6: Measuring the Half Flux Diameter (HFD) of a star - A Simple C++ implementation In Part 5 of my "Night sky image processing" Series I wrote about measuring the FWHM value of a star using curve fitting. Another measure for the star focus is the Half Flux Diameter (HFD). It was invented by Larry Weber and Steve Brady. The main two arguments for using the HFD is robustness and less computational effort compared to the FWHM approach.
An article about the HFD can be found here. Another short definition of the HFD I found here. The original paper from Larry Weber and Steve Bradley can be found here.

Let's start with the definition: "The HFD is defined as the diameter of a circle that is centered on the unfocused star image in which half of the total star flux is inside the circle and half is outside."
This definition can also be written in a mathematical fashion:


where:
•  is the pixel value minus the mean background value (!)
•  is the distance from the centroid to each pixel
•  is the number of pixels in the outer circle
•  is the Half Flux Radius for which the sum becomes 
I decided to put the formula here because it makes it easier to explain what is going on. In contrast to the definition in the other article I decided to name  Half Flux Radius () instead. This is because as far as I understand the formula  is just the "mean radius" (and not the diameter) for which the sum becomes . In fact all the "magic" is that the difference  becomes negative for all the pixels which are inside the inner circle () and positive for all which are outside the inner circle (). After transposing the equation  can easily be calculated.

NOTE: It is important to subtract the mean background value from each pixel before calculating the HFD value. Otherwise - depending on how big the mean background value is - one might get quite interesting results. The right image shows the result if the mean background value is not subtracted. The calculated HFD value almost does not change for the different stars. The reason is quite simple: "Every little helps." The flux of the many "black" pixels around adds up and has a significant effect on the calculation of the HFD. In fact there are just a few very bright pixels (lets say with ~16000 ADUs). In contrast there are > 2500 pixels with ~500 ADUs what in sum creates a much bigger flux than a few very bright pixels. The visual impression - the dark background in the star images - might lead into a wrong direction here. If the mean background is not subtracted, the result is shown in figure on the right. In case a.) the flux is the same for each pixel (a more theoretical case of course). Then the two areas  and  would be equal and the HFD would be the radius of the inner circle. This actually makes quite clear what the HFD actually means. In this case the HFD would be . The derivation is quite simple:



One exception is the case when there is no flux at all (i.e. a totally black image). Then the HFD is actually not defined since there would be a division by 0. However, for this implementation I decided to return a theoretical value of  in this rather theoretical case.

In case b.) there is just noise but no star. The noise is more or less equally distributed and hence the  behaves similar to case a.).

In case c.) we have a star which is focused quite good. Then the distribution of flux changes so that more flux is in the center of the centroid. The  decreases. Note that the  even gives acceptable values for stars which are quite far out of focus. This makes it generally more stable than the FWHM method.

Below is the C++ code for my HFD implementation. The second part of the code just generates an image to demonstrate the effect of HFD for different star images. The test data can also be downloaded here. The source file can also be downloaded here. The command to compile the code above is: The output when executing is:
Note that the test images have been centred manually. Hence the accuracy might not be the best. Still, there are two conclusions which can be drawn from the right image:

• The green circle () correlates very well with the star focus
• It even correlates when the star is far out of focus
In the final part - Part 7 of my "Night sky image processing" Series I will put all the things together.
Last updated: December 26, 2015 at 14:52 pm