Hi Simon :)
I think I've read a number of times in the tutorials and other places in the forum the importance of being able to mask at every stage, and this is something I am now doing with great effect.
Well, I'm not of the opinion that every stage should be masked... but indeed if properly used it will show a significant improvement. The key point here, as always, is to know exactly what you are doing, and what do you want as a result. Image processing is not like cooking a cake, following instructions. It is more likely to the work of a sculptor. You have to uncover the David from the stone :); follow the path the image shows.
Would it make sense to be able to somehow put a square around a single (typical) star and make that the kernel for the filter? And the same would apply to the deconvolution process. Being able to just sample a star from the the actual image might be a very handy addition.
You may try something like this... make a preview over a star, create a new image with it, and use the Binarize process to make it black and white (convert it to grayscale before it). Now manually copy the shape into the MorphologicalFilter's Structuring Element.
As I said earlier, a more refined way to do this, with a "grayscale" structuring element is not possible with the current algorithm. We may find a way to solve this... or just implement the "standard" grayscale morphological transforms I described to you in the previous post. To put it in simple words, one adds or substracts the structuring element to the image, and then looks for the statistical value that is desired. The problem, as is quickly shown, this leads to a change in the overall brightness, it is not just a change in the size of the structures. I have some ideas in mind to partially solve this... but since this process is not a priority right now, it must wait :)
Now, about deconvolution. What you said has been implemented with the first release of both processes: Deconvolution and WienerDeconvolution.
Just look, under the PSF section, for the External PSF tab. There you may include a view as a PSF. The way this works is slighty different for both processes. Deconvolution needs square images, grayscale, while Wiener works with any kind of images.
A word of caution: using a star as the PSF theoreticaly is the best option, but in the practice the results may not be good. Experiment modifying it with morphological filters, curves and the histogram. Also, it is important that the star has been very well centered on the image to be used as PSF, or the deconvolved image will be shifted.
1. The centres become very bright very quickly and can lead to millions of equally blinding pinpoint stars very quickly. And dynamic range extension seems to leave dark rings around the base. I'm using a starmask, so dynamic range extension might be great for the centre of the star, but what is it doing to the background?....is this being decreased during the dynamic range extension process? If so then this would lead to dark rings around the stars. Is there a way of avoiding this, i.e. of getting the background within the starmask to remain the same after deconvolution and dynamic range extension as the background it started with?
To protect star centers use a inverted luminance mask (and the star mask as the deringing support).
Here is a quick explanation on how the dynamic range extension works. Internally, all pixels are handled as floating point numbers, or in other words, as real numbers. It doesn't matter if they go out of range, because they are just numbers, and not interpreted as pixel values. If you set it the lower boundary to "S", and the upper to "H", that "real valued" image will be rescaled so S will be zero, and H 1 (mathematically, [img-S]/[H-S]). Then, every pixel out of the new normalized range values will be clipped (will become 0 or 1). So, if you just increase the extension for the highlights, the image as a whole will be darkened. Imagine that we set it in a way that 2.0 will be the point for white values... when rescaled, the image will be divided by 2, so the brightness will be the half for every pixel. If you are using a star mask, and their sizes are larger than the star itself, you'll see that "ringing" or donut effect. This is just a problem with the mask (or it's combination with the extension). You may try to increase the extension for the shadows, to compensate the effect... but this will leave artifacts if the stars are surrounded with nebulosities or other features that vary the "background" brightness.
A best solution is to fine tune the mask... or don't use it at all (I'm talking about a Star Mask... a mask based on the luminance may prove to be much better in this case). As I said above, use StarMask to build deringing supports for the Deconvolution process, mainly, but I would not trust in it too much as a suitable mask (if you are not capable of fine tune it... I'm not :D, Juan is the expert with that tool).
2. Again, with an odd shaped star (maybe some guiding error, or maybe a slight flaring) the deconvolution can actually enhance the oddness of shape by packing more intensity into the odd bits rather than evolving towards a nice circle. I can increase the standard deviation and change a few other parameters to give a nice round shape, but these make the stars bigger rather than tighter. Making stars bigger is not a problem, I can do that easily!
The PSF is not the ideal image you want to generate. It is the model of the deformation the image underwent to reach the current state. So, this is why it is said that the stars are the "perfect" choise to build PSFs... they are supposed to be (ideally) point sources, so their shape is exactly how the image have been degraded. In the real world, matching exactly the stars with the PSF does not give the optimal results, but indeed is a very good starting point. In your case, instead of using a star as external psf, try to reproduce that shape with the gaussian options (change the ratio and angle, and keep the standard deviation low. Change the function order if needed). Another option, that works well if you have traking errors parallel to the x or y axis of the chip, is to use a motion blur psf. Because of pixel discretization, this doesn't work very well for other angles.
Now about your method. Seems to work very well, but there are lots of faint stars that have not been reshaped. What I'd to is to use morphological filters (with and without masks) to erase all stars, and even other small scale features (also, blur it a little disabling some wavelet layers). Do it to a duplicate of the image. Now, using PixelMath, apply: "img-deletedstars", without rescaling, and create the result as a new image. Close the "blured" image.
That new image will contain all the bright, high frecuency features. Now, again with PixelMath, apply "img-stars", againg without rescalling. The result will be all the large scale features, and the dark high frecuency (small scale) ones.
Process the small scale image to get rounder stars, and then add the result to the large scale image, rescaling the result. This should work ;)
About your second approach, a note: you may create star masks (with the exact current shape) with wavelets disabling the residual layer, and setting all other deringing parameters to the maximum. You'll have to use a trial/error process to find how many layers to discard (or, in other words, where the residual layer is), and which is the best scaling function.
Now, your method works well, but has some side effects... I would try to blur the star just a little bit, and make use of morphological filters to make them rounder before deconvolution. Also, you may try several iterations of this procedure, instead of a crude single processing. BTW, this is exactly the idea behind noise reduction. It works better by slowly approaching the solution, than getting it straight with a strong blur. The same happens with iterative deconvolution algorithms, like Richardson-Lucy. ;)
Thank you very much for your motivation to find another ways to perform these tasks. This is exactly what motivated us from our very beggining: beeing a "source" for innovations and imagination. Please keep those ideas coming. Who knows? maybe we'll end with a new process automating all of this, thanks to your ideas :D
PS: I'll work a with your sample images, and see what happens.