Jump to content

SkySurveyBanner.jpg.21855908fce40597655603b6c9af720d.jpg

Getting too old for this game - Sum or Median/Average??


Merlin66

Recommended Posts

I thought I knew what I was doing.....but now I see some images with hours and hours of exposures - " 17 hours exposure of NGC ****"

Geee 17 hours, even allowing for shot noise, and just a few photons arriving every minute, the sum of such an exposure would/ should burn out everything but the faintest stuff in the background.

Then I see....they may be average/median combined exposures.....well, to me that's not a SUMMED multi-hour exposure!!! You average a sub with say 20k ADU and another of 15k ADU you get a result of (20+15)/2 = 17.5k ADU. When you sum them you'd have 35k ADU with a better shot SNR.

Help me here...I think I'm loosing it.

Link to comment
Share on other sites

  • Replies 32
  • Created
  • Last Reply

For signal and noise purposes sum and average are the same.  Average is just delivers a lower pixel value (that must be stored using floating numbers) since it's divided by the number of subs. This affects both signal and noise the same so the end result is the same. Median is basically the same as computing the average while getting a better rejection of bad pixels but just 80% of the improvement in signal to noise compared with sum/average. None of these stacking algorithms should be used for astrophotography unless you have a low number of subexposures as SD mask, Sigma clip and other adaptive algorithms provide both a better noise suppression and good rejection of bad pixels.

Link to comment
Share on other sites

Noise I can just about understand but:

""For signal and noise purposes sum and average are the same.  Average is just delivers a lower pixel value""

Surely we need a higher pixel value to "build the faint data" - what's the using of collecting 10 x 10k of data and then analysing on 10k (average)??????

(A faint part just visible at 1k ADU would still be a "faint part" at 1k?????)

Link to comment
Share on other sites

I'm slowly translating the "light gathering" article I wrote for the Swedish astronet.se forum to address this and other questions I have seen often raised on SGL.  The pixel value in a single sub is just a arbitrary measurement which exact value is determined by the efficiency of the camera system (the number of electrons generated by the photons hitting the camera - quantum efficiency), the rate of photons hitting the individual pixels (Etandue - depends on pixel scale and aperture) and some constants used to translate the number of electrons generated  (e.g. electrons/ADU) to a digital value of some specified range (dependant on camera, drivers and settings). A pixel value is therefore basically an arbitrary value that you can multiply with any value, the only thing that matters is the ratio between signal  and noise (using the strict definitions of signal, noise and signal-to-noise-ratio). However practically you need to consider saturating the pixels, accuracy of the recorded result (usually a 8-16 bit integer) and many other details due to the limitations of technology. 

Assuming we won't hit any of those limits then adding many subexposures (signals) means that we are also averaging the noise of the individual exposures. This means we are adding signal faster than noise (noise is proportional to the square-root of the signal) which means we are getting a better SNR. For the pixels where this is true adding four times the signal (~exposure time) results in an image "twice as good" that allows more detail to be brought out.

Link to comment
Share on other sites

Your last paragraph:

""adding signal faster than noise (noise is proportional to the square-root of the signal) which means we are getting a better SNR. For the pixels where this is true adding four times the signal (~exposure time) results in an image "twice as good" ""

I agree 100%!

In my mind I can see this...the total signal has increased...but then what's the case when you "average" rather than add....

When the image has been recorded and available as a fits etc the saturation issue is not the same as in the CCD chip.

I can display an image (on my computer) which has has had 50ADU or summed to 500K ADU......

Link to comment
Share on other sites

Sum or Median/Average should be written Sum/Average or Median.

An average is just a sum of the images divided by the number of the images. Statistically they are the same, and the images will look exactly the same -- just with a different level.  A median is a different process (for each pixel;  sort all the values in order, pick the middle value). It is noisier than an average, but more robust (less likely to thrown out by a single bright/faint image)

The best of both worlds is a clipped average as others say.

Link to comment
Share on other sites

Frazer,

Please bear with me one last time....

Mathematically, at least in my mind, when we sum the set of individual exposures A+B+C etc then the total signal will increase. This then allows fainter signals to be recorded as they stack up....The shot noise decreases as the square...

In any averaging my brain tells me I'm NOT adding to the total signal but ending up with (A+B+C)/3 as the total signal....were does the improved recording of the fainter detail come from? Just the reduced SNR?

If you are all in agreement, then obviously I'm missing something fundamental in the analysis.

Link to comment
Share on other sites

Frazer,

Please bear with me one last time....

Mathematically, at least in my mind, when we sum the set of individual exposures A+B+C etc then the total signal will increase. This then allows fainter signals to be recorded as they stack up....The shot noise decreases as the square...

In any averaging my brain tells me I'm NOT adding to the total signal but ending up with (A+B+C)/3 as the total signal....were does the improved recording of the fainter detail come from? Just the reduced SNR?

Yes, precisely. Consider that when you divide the signal, you also divide the noise...

Link to comment
Share on other sites

I always remember the DSS help that stated...

Why combine?

The answer is simple: only to increase the Signal to Noise Ratio (SNR).

Is the resulting image more luminous? No.

Is the resulting image more colorful? No.

I am no mathematician/statistician, far from it but the terminology used is a bit iffy and as already stated sum is not summing it is adding/dividing i.e. calculating the mean. Average/median is calculating the median.

Sigma removes outliers before "averaging" so that 1 or two bad subs/pixels don't skew the results as they get rejected.

There is no magical "Additive" algorithm that won't also add the noise and the change in SNR will be zero.

Link to comment
Share on other sites

Guys, I appreciate the imput.....

My problem, with spectra, is that the higher the signal the better the SNR....so I keep adding the subs to maximise the total signal.....

This does indeed improve the SNR and in my simple mind shows a far clearer and "smoother" spectrum.

I'll just stick to what works for me and stay away from astrophotography - I'll leave that to Olly!!

(IMHO, I think they would better be calling it "scaling" rather than "average")

Link to comment
Share on other sites

Scaling is indeed what it is - averaging is a more precise definition in that it tells you what the scaling is.  It's the total (sum)  divided by the number of samples (subs in our case).  IOW the sum scaled by the number of samples.  After using floating point arithmetic to calculate the sum the result is scaled so that it is still within the range of an integer (usually 16bit).  This is what software like DSS does. Others such as FITS Liberator look at the data of a single image and assess the range - then it adjusts the black level (by subtracting a constant) and the white level by scaling the result, to provide a useful image for viewing.  These levels are presented in a histogram and may be altered as the user feels fit.   This image is displayed in a window.  A useful output otpion is to save the result (as a TIFF file) and automatically open Ps and load it into that for editing.  I find this very useful for examining individual frames/subs so that I can reject duff ones.  HTH :)

Link to comment
Share on other sites

I am no mathematician/statistician, far from it but the terminology used is a bit iffy and as already stated sum is not summing it is adding/dividing i.e. calculating the mean. Average/median is calculating the median.

No, they all do exactly what it says on the tin. Sum or add will indeed sum the values. Average will calculate the mean by summing the values and dividing by the number of subs. Median will sort the values and pick the middle one.

Link to comment
Share on other sites

Guys, I appreciate the imput.....

My problem, with spectra, is that the higher the signal the better the SNR....so I keep adding the subs to maximise the total signal.....

This does indeed improve the SNR and in my simple mind shows a far clearer and "smoother" spectrum.

You could quite well be correct that you are seeing better spectra with adding but in that case it would be caused not by SNR but by the assumptions and idiosyncrasies built into the software you are using. The math is clean and easy, the reality with camera and software limitations are much more messy...

Link to comment
Share on other sites

No, they all do exactly what it says on the tin. Sum or add will indeed sum the values. Average will calculate the mean by summing the values and dividing by the number of subs. Median will sort the values and pick the middle one.

This is my understanding too, I just don't know how  these adaptive algorithms differ from the others and what is the minimum requirement for them to work.

Regards,

A.G

Link to comment
Share on other sites

OK.....

One last question, before I take my pill and lie down.....

I can usually get a "first approximation" of shot noise (square root) from the total strength of the signal... ie a 10000ADU signal would have approx 100snr....

Now if I have 5 of these subs I'd expect to see a SNR = 224

If I end up after summing with an average which is still around 10,000 ADU then my SNR would still be 100??????????????

How do I estimate/ measure the actual SNR?

Link to comment
Share on other sites

OK.....

One last question, before I take my pill and lie down.....

I can usually get a "first approximation" of shot noise (square root) from the total strength of the signal... ie a 10000ADU signal would have approx 100snr....

Now if I have 5 of these subs I'd expect to see a SNR = 224

If I end up after summing with an average which is still around 10,000 ADU then my SNR would still be 100??????????????

How do I estimate/ measure the actual SNR?

Your shot noise calculation is right, but only valid  for a single exposure. When you're averaging multiple exposures together, you need to divide that shot noise contribution by the square root of the number exposures.

Link to comment
Share on other sites

No, they all do exactly what it says on the tin. Sum or add will indeed sum the values. Average will calculate the mean by summing the values and dividing by the number of subs. Median will sort the values and pick the middle one.

Okay, then please explain the purpose of just summing the values and doing nothing with the result other than having a "brighter" image with equally "bright" noise, how does this improve the SNR ratio? If it is used to make something visible like the "Screen Transfer Function" in PI then I can understand, otherwise I need some more explaining :grin: In your first post you say they are the same, they can't be if one divides by the number of subs and the other doesn't. Summing doesn't make sense on its own. Lets ignore floating point/integer because any respectable image integration algorithm will either use FP or scaled integer maths so as not to lose precision.

Regarding your original question Merlin, FITS files can work in 32 bits per pixel, quite a large number, and if you had 16 bit values (65536), you could have 2^16 (65536) subs before you'd saturate then you can scale the result to fit 8 bits per pixel once processing/stretching the histogram is complete. In fact I think that FITS files can also have 64 bits per pixel which is 32 orders of magnitude larger, also they can operate in floating point which is even larger...

Link to comment
Share on other sites

Stuart,

Summing does make sense (at least to me) - as I said before it increases the total signal and decreases the shot noise.

Please remember I'm looking at faint spectra rather than faint star images in an astrophoto.

Fraser - thank's for the info!

So I think we are saying that an almost invisible (ie VERY low ADU) star image in the sub, is still a VERY low ADU image in an "averaged" stack - (17 hrs is a lot of stacking!!) but improves its "contrast" due to ONLY the improved SNR.....

Link to comment
Share on other sites

Okay, then please explain the purpose of just summing the values and doing nothing with the result other than having a "brighter" image with equally "bright" noise, how does this improve the SNR ratio?

Each exposure is a measurement of the signal plus *or minus* an error.  When you add multiple exposures together, the signal always adds because it is always positive (by definition) and constant (basic assumption in all of this!). However, because the error can be positive or negative (i.e. it gives either an under- or over-estimate of the signal), sometimes it adds and sometimes it subtracts. So the ratio of signal to noise always increases the more measurements (exposures) you add together.

Averaging is exactly the same as summing, because all you've done is divide each pixels by exactly the same value. That can't change the statistical properties in any way (if you ignore numerical truncation, as Stuart points out).

Link to comment
Share on other sites

Okay, then please explain the purpose of just summing the values and doing nothing with the result other than having a "brighter" image with equally "bright" noise, how does this improve the SNR ratio? 

Much like velocities in relativity adding noise isn't straightforward. Since noise is random it will tend to partially cancel out when added or subtracted. The result is that the level of the noise only increases as the square root of the exposure time or the number of sums. The signal on the other hand will behave as normal. Futhermore the noise level of signal that is has a Poisson distribution is equal to the square root of the signal. If the signal is proportional to the number of subs we thus get:

SNR when adding/averaging = signal/noise = N/sqrt(N) = sqrt(N)  

Link to comment
Share on other sites

Your shot noise calculation is right, but only valid  for a single exposure. When you're averaging multiple exposures together, you need to divide that shot noise contribution by the square root of the number exposures.

Slight caveat to this -- shot noise (aka poisson noise) happens at a photon level, not at an ADU level.  So taking the square root of the counts in an image is only valid if the gain of the CCD is 1.0.  If the gain is different, you need to convert the ADUs to electrons (photons) before taking the square root...

Link to comment
Share on other sites

Just did the recalc based on Fraser's input (square root of the number of subs) - this leads to a SIGNIFICANT improvement in SNR ie from 223 to 490!!!!!

What this means to me, I think, is that I need to know how many subs were used in every "stack" we analyse............also, all things being equal (!!??) you get a better SNR with a larger stack, than you'd get with a longer exposure!!

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue. By using this site, you agree to our Terms of Use.