Night sky image processing – Part 3: Star clustering

Star clustering

This article is about finding all the pixels which belong to a star – also known as star clustering. A short C++ implementation based on CImg is shown below. In Part 2 of my “Night sky image processing” Series I was writing about thresholding. The result of the thresholding is a binary image. In this context it means the “1” pixels belong to stars, the “0” pixels belong to the background. I used Otsu’s method to calculate an according threshold value.

Introduction to star clustering

The binary image is now further examined in a process called clustering. In simple words the pixels which belong together (i.e. the neighbours) are grouped together. The result of this clustering process is a list of pixel groups which belong together – i.e. a list of stars and the pixels belonging to each star.

The implemented algorithm is based on the paper “Improving night sky star image processing algorithm for star sensors from Mohammad Vali Arbabmir et. al. However, in detail it is slightly different. My implementation assumes that the supplied image cannot be modified during the process. Hence I am using a set to put all white pixels into. To me this is a good compromise between memory consumption, performance and simplicity. However, the implementation can be further improved with respect to runtime performance when one would used a 2D array for the white pixels instead of a set.

The algorithm

The clustering algorithm is relatively straight forward:

Continue reading →

Night sky image processing – Part 2: Image binarization using the Otsu thresholding algorithm

Otsu thresholding for star recognition

This article is about image binarization using the Otsu method. A simple C++ implementation of the Otsu thresholding algorithm based on the CImg library is shown. In Part 1 of my “Night sky image processing” series I have taken a look on anisotropic diffusion in order to reduce the image noise.

Introduction to Thresholding

The next topic I want to have a look at is thresholding. In this step the algorithm decides which pixels belong to the background and which pixels belong to a star. However, before the algorithm can decide which pixels belong to a particular star (also called clustering – see part 3) it first has to generally decide which pixels belongs to any star and which pixels belong to the background. This process is called thresholding i.e. converting a grey-scale image into a binary image. There are many different thresholding algorithms out there. All have there advantages and drawbacks. I found ImageJ very helpful to test different thresholding algorithms.

Why Otsu Thresholding for astro images

After trying different ones I found that Otsu’s method does a quite good job. After further reading I found out that this method is especially useful for images with bi-modal histograms. To my knowledge night shy images usually do not have bi-modal histograms. However, so far Otsu’s method still gave very good results with my star images. Furthermore it is relatively efficient and simple to implement. For those reasons I decided to go this way.

Introduction to Otsu Thresholding

Otsu’s algorithm tries to find the threshold so that the variance of all pixel values in the foreground and the variance of all pixel values in the background becomes minimal. The variance is a measure of the spread. The smaller the variance of for example the foreground pixel values, the closer the gray levels of the pixels and the more likely it is that they belong together. At least that’s how I understand Otsu’s method.

The following formula calculates a kind of “mean” variance $\sigma^2_{within}(th)$ of the foreground variance $\sigma^2_{fg}(th)$ and the background variance $\sigma^2_{bg}(th)$. In fact it is no mean but a weighted sum of both. The weights are the number of pixels in the respective group:

$$\sigma^2_{within}(th)=\sigma^2_{fg}(th) \sum\limits_{i=0}^{th-1} {num(i)} + \sigma^2_{bg}(th) \sum\limits_{i=th}^{N-1} {num(i)}$$

Continue reading →

Night sky image processing – Part 1: Noise reduction using anisotropic diffusion with C++

effect of anisotropic diffusion
The effect of anisotropic diffusion on astro-images

For some time now I am looking into the field of night sky image processing. It is a huge topic and there are already a lot of different approaches and solutions to many of the existing problems. I have collected many star images over the time. To me it is very interesting to try different algorithms with my own data. This article starts with a problem every night sky photographer and astronomer is aware of: noise. I did some research and came across “anisotropic diffusion”.

What is anisotropic diffusion?

In short, anisotropic diffusion is a non-linear and space-variant transformation i.e. the transformation depends on the image content. The effect is that the resulting images preserve linear structures while at the same time smoothing is made along these structures. Additional information on anisotropic diffusion is available for example on wikipedia and here. Furthermore I found this youtube explanation quite helpful.

Continue reading →