# FoFi – A free, automatic telescope focus finder software

At the time of publication this project is not even in ALPHA state. However, I feel now is the right time to publish it since it reached a state where at least the source code could be useful to others. You can find the source code on github here.

The software aims to support the amateur astronomer (and especially astrophotographer) with one of the most critical but also most annoying tasks: Finding the best focus position for the camera. The main goal is to provide a free and easy to use software that just does the job – automatically.

With a given configuration it should also be possible to execute “FoFi” from the command-line without requiring any user interaction. This way you can include a call to the Focus Finder into a script. This might be useful if the entire observation process should be automated and you want to re-focus from time to time to compensate the temperature drift.

# Fast “max entropy” thresholding for 16 bit images with CImg

In this article I shown a C++ implementation of the “max entropy” threshold algorithm using the CImg library. This implementation also performs for 16 and 32 bit / float images.

First, a little bit of context: Some time ago I implemented the OTSU threshold algorithm as a pre-processing step for image binarization. I used that threshold algorithm to distinguish the noise pixels from the potential “star” pixels. This worked quite well for the high contrast input images at that time. However, for weak stars it unfortunately failed badly.

# Easy 2D Signal-to-Noise Ratio (SNR) calculation for images to find stars without extracting the background noise (C++)

Calculation of a SNR for stars

This article shows how to calculate the 2D signal-to-noise ratio (SNR). Furthermore, it demonstrates how the $SNR$ can be used to decide if there is a potential star in the image.

Long story short – I was looking for a way to detect more or less reliably if a user selected a region which contains a star. I wanted to be able to clearly distinguish between the following two images:

### Solution with the CImg library

After a long journey I finally ended up with the following solution. It is based on the CImg library which in a way calculates the Signal-to-noise ratio (SNR):

CImg <uint16_t> image;
...
double q = image.variance(0) / image.variance_noise(0);
double qClip = (q > 1 ? q : 1);
double snr = std::sqrt(qClip - 1);

For the two images above the code gives the following results:

~/snr$./snr no_star.fits SNR: 0.0622817 ~snr$ ./snr test_star.fits
SNR: 1.5373

For many people this is where the journey ends. But for some of you it may just begin :). Follow me into the rabbit hole and find out why the solution shown above actually works…

# Finding perfect focus with V-Curve fitting based on a hyperbolic function

### What is a V-Curve?

A V-Curve is the result of moving the focus of a telescope from an outside focus position into the focus and then further into the same direction out of focus again. This way a V-Curve comes into existence where the focus position is on the x-axis and the focus measure on the y-axis (right figure). Probably not surprising this curve is called V-Curve since it is similar to a V. There are different ways to measure the focus – for example the “Half-Flux Diameter” (HFD) and the “Full width at half maximum” (FWHM). In this case the I use the HFD measure.

# How to execute a command within the emacs shell which was passed as command line argument

This topic is in fact not so closely related to astronomy. However, from a technical perspective I think it still fits onto this blog. Recently I was in a situation where I wanted to start a console command within the emacs shell – but directly via the command line. The xterm shell has the -e option for this purpose. Also the bash command provides the -c option. However, in emacs I was not able to find such an option. I also didn’t want to dive too deep into the LISP stuff. If you are in a similar situation the following solution might be what you need. A very small emacs LISP script will do the job:

(toggle-truncate-lines 1)
(insert (elt argv 0))
(comint-send-input)

This script first opens a new shell in emacs and then inserts the first argument passed to the script into the shell. The last line then executes the command. In the end emacs can be called the following way:

emacs --load exec_cmd.el "<my command>"

The following example calls xeyes with red eyes – this shows that passing parameters to the executable is also not a problem:

emacs --load exec_cmd.el "xeyes -center red"

This little trick helped me a lot since navigating and especially searching inside emacs is much more convenient than in xterm (at least in my eyes).

Last updated: June 16, 2022 at 13:33 pm