Hi Mike,
I have attached a new version of StarDetector.js to this post. This is an adaptation of the star detection routine that I have written for the next generation of the StarAlignment tool, which I'm going to release in a few days.
This version has the following main features:
* Much faster. You can use it now without performance problems in your scripts. Example 1: 1800x1300 image, 3100 stars detected in 1.40 seconds. Example 2: 4000x5000 image, 40,000 stars detected in 8.3 seconds. Benchmarked on a 6-core i7 990X workstation.
* More robust detection. The new algorithm is much more robust to detection of false star structures (such as small nebular features) and multiple/crowded stars.
* More accurate. The algorithm converges to valid centroid coordinates under difficult conditions such as nearby stars or nebulae, and diffraction spikes.
* The new detection algorithm is invariant to scale. This means that the same stars are now detected consistently for the same image, on small crops or on the whole image. This means also that the same stars are now detected for the same image under a wide range of scaling factors. Scale dependency was a severe limitation of previous StarAlignment versions.
The script now generates better control images (when the __TEST__ macro is #defined to a value > 0). In particular, the script generates a star mask with circles showing the dimensions of the detected star structures. Just select the star mask as a mask for the original image and apply an automatic screen stretch as necessary. The stars will be shown as red circles.
The algorithm no longer uses wavelet transforms to isolate structures (as this was the cause of the scale dependency that I have commented above). However, for the sake of compatibility, the structureLayers and noiseLayers parameters are still expressed as wavelet layers. I have written the structure detection phase in a way that mimics the wavelet-based implementation. Despite that, the structureLayers and noiseLayers parameters are much less sensitive in this version. This means that the difference between 4, 5 and 6 detection layers is not really important for most images, which is a good property because it contributes to the scale invariance of the algorithm.
Let me know if it helps, and keep up the nice work!