Hi Wouter,
You probably don't see my changes because I have not yet merged my changes into the main branch. I have created a branch called 'bahtinov-mask-focus' in my kstars repo. If you check out this branch, then you will have my changes.
$ git branch bahtinov-mask-focus
$ git checkout bahtinov-mask-focus
$ git pull origin bahtinov-mask-focus
Here are globally the changes I made:
The in kstars/kstars/ekos/focus/focus.ui there is a combobox called focusDetectionCombo. This should have an extra value named Bahtinov Mask. In kstars/kstars/fitsviewer/fitsdata.cpp is the implementation of the bahtinov algorithm. And in kstars/kstars/fitsviewer/fitsview.cpp is the drawing of the lines on the image. Some extra parameters have been added to the Options class.
I am a little short on time this week to develop, but hope to get some time for it next week.
There is not much logging in the code, I usually test it visually by aiming at a star, with your bahtinov mask in place and then get the image in kstars. Then see if the focus module draws the right lines on top of the image.
I found out last week that that is not the case. Some lines are drawn, but they don't make sense. Probably because the lines are not detected right. It could also be that the coordinates for drawing the lines are incorrect, but I have to look into that some more. Printing the variables of the detected lines will usually help to see if the detection did work.
I have saved the images I captured and am feeding them into my example application (which I didn't share on github yet) which uses the exact same algorithm. I noticed that the example application had a really hard time recognizing the lines in the images because the image was too noisy. I have been tweaking the few parameters I have, but they seem to be quite different for each image I feed it.
So currently I am trying two things:
- add some sort of algorithm to analyse the data an determine the best values for the parameters
- implement a completely different algorithm to detect the lines in the image
The current line detection is as follows:
- start processing the image the same way as it is done in the Canny algorithm that was already implemented, namely get the image data and apply a MEDIAN and HIGH_CONTRAST mask
- apply sobel algorithm (determine horizontal, vertical and diagonal edges)
- apply thinning algorithm (sharpen the edges)
- apply threshold (make it a 3 color image: black, 50% grey and white)
- apply hysteresis (make it a black and white image)
- apply hough transform which gives back an array of lines detected in the image
- take the 3 brightest lines and use them to determine the focus offset
.1) sort the lines in order of angle
.2) determine the intersection between the two outer lines
.3) determine the distance between the intersection of the outer lines and the middle line, that is the offset
- place the data for drawing the lines in the BahtinovEdge class (derivative of Edge class used for drawing the focused stars)
- use the BahtinovEdge class to draw the lines on the image (in fitsview.cpp)
The alternative algorithm I was thinking off is the same algorithm used in the bahtinov-grabber application. Namely take the image, rotate it 180 degrees in steps of 1 degree en for each step calculate the average brightness of each horizontal line. When there is a diffraction line in the image positioned horizontally, then the average brightnes of that horizontal line will have a higher value. Store the highest value in an array.
After all rotation steps have been done, determine the three highest values in the array, these should be the three diffraction spikes of your bahtinov mask.
Then the processing continues from step 7 as described before.
I am also trying to apply a gaussian blur filter instead of the MEDIAN and HIGH_CONTRAST mask and see if that makes a difference.
I hope this information will help you on your way.
Kind regards,
AstroRunner