A Couple of small feature requests

Got an idea for something that SharpCap should do? Share it here.
Forum rules
'+1' posts are welcome in this area of the forums to indicate your support for a particular feature suggestion. Suggestions that get the most +1's will be seriously considered for inclusion in future versions of SharpCap.
User avatar
admin
Site Admin
Posts: 17530
Joined: Sat Feb 11, 2017 3:52 pm
Location: Vale of the White Horse, UK
Contact:

Re: A Couple of small feature requests

#41

Post by admin »

Hi,

thanks for continuing to dig into this...

The focus score works like this

* If RAW image, debayer to colour
* If colour, simple convert to luminance (R+G+B)/3
* Calculate mask based on black threshold
* Erode mask by 3 pixels to avoid edge effects
* Calculate laplacian of luminance
* Calculate standard deviation of laplacian, only considering points in the eroded mask (A)
* Calculate mean of image brightness, only considering points in the eroded mask (B)
* Focus score is A/B

It's an interesting point that you make about the normalization to the brightness of the sample. To first order, I'd expect that to be OK, since regardless of the focus, you have the same number of photons arriving, so the total brightness should be the same. However, if the circle of confusion due to being out-of-focus starts to get large then you may have dark areas from around the target starting to mix into your measuring area, which would bring the average brightness down, which could possibly be the domininant effect in some cases?

I can try putting a version together that doesn't do the normalization if you want to see if it helps.

cheers,

Robin
Borodog
Posts: 485
Joined: Fri Jan 01, 2021 7:25 pm

Re: A Couple of small feature requests

#42

Post by Borodog »

Yes, I would appreciate that. I feel pretty strongly that normalizing is a mistake under constant lighting & transparency conditions. Not normalizing should also give a clearer, i.e. stronger, signal, because as I said, it's actually measuring 2 things at once, blurring and intensity.

I also feel like you would do better simply binning the raw image at least 2x2 rather than debayering and then converting to monochrome. There is no non-interpolated information in the debayered image and the binning automatically converts to luminance with increased SNR. As I said, in Autostakkert nearly everyone bins 6x6 to increase SNR and it can still easily identify critical focus. Personally I would think that *all* of the focus methods for color cameras should be binning at least 2x2.
Borodog
Posts: 485
Joined: Fri Jan 01, 2021 7:25 pm

Re: A Couple of small feature requests

#43

Post by Borodog »

Also, to your point about dividing by the total brightness "being ok" because the same number of photons should be arriving . . . then why do it? Dividing the standard deviation of the Laplacian by what is supposed to be a constant doesn't accomplish anything, except when it is not actually constant, in which case it's bad.
User avatar
admin
Site Admin
Posts: 17530
Joined: Sat Feb 11, 2017 3:52 pm
Location: Vale of the White Horse, UK
Contact:

Re: A Couple of small feature requests

#44

Post by admin »

Hi,

interesting point about the 2x2 binning rather than the debayer/luminance convert - I will try that.

The theory with the normalization was that it meant that the focus graph is not affected by things like varying intensity due to thin cloud, which is perhaps more relevant when lunar or solar observing. As you can imagine, if you are imaging through thin but variable cloud then your focus scores can be seriously affected by the brightness variations if they are not normalized.

I feel an option coming on...

cheers,

Robin
Borodog
Posts: 485
Joined: Fri Jan 01, 2021 7:25 pm

Re: A Couple of small feature requests

#45

Post by Borodog »

I understand the theory, but the math just does not work that way. Other imagers and I have found that normalizing the image actually has the opposite effect to what you want. In a dimmer image, the SNR is lower. There is no way around this. When you normalize it, the contrast calculated by the Laplacian goes UP because of the relative increase in noise (even though the absolute noise goes down), and the dimmer image is given a higher quality/focus score, all else being equal. We've tested this by normalizing variable transparency videos in PIPP, and the result is that the dim sections are invariably scored as higher quality by Autostakkert. The dimmer the section, the higher the quality. And this is with 6x6 binning to try to maximize the SNR. I will try to find the link to the thread where another imager (I think it was Ittaku over on CN) documented this phenomenon.
Borodog
Posts: 485
Joined: Fri Jan 01, 2021 7:25 pm

Re: A Couple of small feature requests

#46

Post by Borodog »

I found the post I was thinking of, but it wasn't exactly what I recalled. The principle is exactly the same, though. In this case, Con (Ittaku) was imaging and had auto-histogram on in FireCapture, which automatically scales the gain to preserve the histogram level. He had one passing cloud and in Autostakkert, that section is marked as the highest quality, by a substantial margin:

https://www.cloudynights.com/topic/8443 ... p=12193048

Image

I did test this last year with PIPP's "Stretch Histogram White Point" option to recover this data:

Image

from variable transparency and noticed at the time that the sections of the video that were originally dark had the highest quality scores in Autostakkert.
User avatar
admin
Site Admin
Posts: 17530
Joined: Sat Feb 11, 2017 3:52 pm
Location: Vale of the White Horse, UK
Contact:

Re: A Couple of small feature requests

#47

Post by admin »

Hi,

once again, good info :)

You are right, the dimmer image has lower SNR, so by scaling up the relative effect of the noise is increased. However, it may be possible to model the effect of this (at a rough approximation, noise is proportional to sqrt(signal) if the read noise can be ignored). That would allow the rescale of the brightness to not affect the component of the measurement coming from the noise, which may be useful.

There will definitely need to be an option - I'm fairly sure the current rescaling came about because of difficulties people were having with solar images, which are of course less noisy.

cheers,

Robin
Borodog
Posts: 485
Joined: Fri Jan 01, 2021 7:25 pm

Re: A Couple of small feature requests

#48

Post by Borodog »

I will be interested to see if you can come up with a focus score that is impervious to variable transparency. If you have a focus test camera + lens you should be able to mimic this by turning down the exposure during recording to get a darker, relatively more noise image. You should be able to focus sweep then at different exposures and see if you can come up with a score that is brightness independent but still yields good focus scores.

I still think there is a potential problem with any sort of brightness normalization masked by a black level. If ADU start getting clipped by the black level, your normalization is out the window. The total integrated brightness goes down, and since you are dividing by it, the focus score goes UP. I am not sure why you need a black level at all for planetary focusing, especially if you were to bin to increase the SNR.
Borodog
Posts: 485
Joined: Fri Jan 01, 2021 7:25 pm

Re: A Couple of small feature requests

#49

Post by Borodog »

Tried the intensity based method tonight. It also shows increasing focus scores for clearly worsening focus.


intensity.jpg
intensity.jpg (495.51 KiB) Viewed 1175 times
User avatar
admin
Site Admin
Posts: 17530
Joined: Sat Feb 11, 2017 3:52 pm
Location: Vale of the White Horse, UK
Contact:

Re: A Couple of small feature requests

#50

Post by admin »

Hi,

I spent a good deal of yesterday evening playing around with attempts to normalize the focus score. Not a trivial thing to do so that it works reliably :) Even rounding in the debayer procedure (or binning for that matter) means that if you halve the brightness of a frame it does not exactly halve the laplacian variance score.

I have an option now in the contrast detection option to turn normalization on/off - this provides some choice while I think about it more. I hope to put out a new 4.1 version next week which will have this in.

For the contrast range, the best results will come by making sure that the selection area does not include anything outside the planet disk (no background) - either that or set the black level high enough that the background and the darker parts of the planet are ignored. Even so, this may be another case of normalization causing issues...

cheers,

Robin
Post Reply