Jump to content

Stargazers Lounge Uses Cookies

Like most websites, SGL uses cookies in order to deliver a secure, personalised service, to provide social media functions and to analyse our traffic. Continued use of SGL indicates your acceptance of our cookie policy.

sgl_imaging_challenge_banner_android_vs_ios_winners.thumb.jpg.803608cf7eedd5cfb31eedc3e3f357e9.jpg

vlaiv

Interesting thing about fractional binning

Recommended Posts

Fractional binning is not widely available as data processing technique so I'm working on algorithms and software for that as I believe it will be beneficial tool to both get proper sampling rate and enhance SNR.

In doing so, I came across this interesting fact that I would like to share and discuss.

It started with a question - if regular binning x2 improves SNR by x2 and binning x3 improves SNR by x3 and so forth, how much does fractional binning improve SNR?

Let's say for arguments sake that we are going to bin x1.5, how much SNR improvement we are going to get? It sort of stands to reason that it will be x1.5. In fact that is not the case!

I'm going to present a way of fractional binning that I'm considering and will derive SNR improvement in particular case of x1.5 binning - because it's easy to do so.

First I'm going to mention one way of thinking about regular binning and feature of binning that this approach improves upon. Binning method here discussed is software binning - not hardware one.

In regular binning x2 we are in fact adding / averaging 2x2 group of adjacent pixels. Following diagram explains it:

image.png.673197279466771ee7f070d462aa1bbb.png

We take signal from 2x2 group of pixels add it and store it in one pixel, we do the same for next 2x2 group of pixels. This leads to result being the same as if we used larger pixel (in fact x4 larger by area, x2 by each axis). SNR is improved, sampling rate is halved and there is another thing that happens - we increase pixel blur because we in effect use "larger" pixel. There is slight drop in detail (very slight) that is not due to lower sampling rate because of this.

There is a way to do the same process above that circumvents issue of pixel blur. I will create diagram for that as well help explain it (it is basis for fractional binning so it's worth understanding) :

image.png.f7c89353eb5c1c063b6861b4d853bdd0.png

Ok, this graph might not be drawn most clearly - but if you follow the lines you should be able to get what is going on. I'll also explain in words:

We in fact split image into 4 sub images. We do this by taking every 2x2 group of pixels and each pixel in that group goes into different sub image - always in the same order. We can see the following: samples are evenly spaced in each sub image (every two pixels in X and Y direction on original image), and sampling rate has changed by factor of 2 - same as with regular binning we have x2 lower sampling rate. Pixel size is not altered, and values are not altered in any way  - we keep the same pixel blur and don't increase it. We end up with 4 subs in place of one sub - we have x4 more data to stack and as we know if we stack x4 more data we will end up with SNR increase of x2.

This approach does not improve SNR of individual sub, but does improve SNR of whole stack in the same way as bin x2 improves individual sub - with exception of pixel blur.

Now let's see what that has to do with fractional binning. Here is another diagram (hopefully a bit easier to understand - I'll throw in some color to help out):

image.png.1dd0d9ce4b7affd4890e51f1bbbd161c.png

Don't confuse color with bayer matrix or anything like that - we are still talking about mono sensor, color just represents "grouping" of things. Black grid represents original pixels. Each color represents how we "fictionally" split each pixel - in this case each pixel is split into 2x2 grid of smaller pixels - each having exactly the same value. I stress again this is fictional split - we don't actually have smaller pixels or anything.

If we want to do fractional binning x1.5 - we will in fact sum / average outlined group of "fictional" pixels. Each purple outline will be spaced at distances 1.5 larger than original pixel size - so we have appropriate reduction in sampling rate. In reality algorithm will work by splitting subs like above - again to avoid pixel blur, but for this discussion we don't need that. We need to see how much SNR improvement there will be.

Let's take the case of averaging and examine what happens to noise. Signal (by assumption) is same across pixels involved so in average it stays the same. Reduction in noise will in fact be improvement in SNR.

We will be averaging 9 "sub pixels" so expression will be:

(total noise of summed pixels) / 9

What is total noise of summed pixels? Noise adds like square root of sum of squares. But we have to be careful here. This formula works for independent noise components. While noise in first pixel (red group) is 100% independent of noise in other pixels (orange, green and blue groups) it is in fact 100% dependent within group itself - and adds like regular numbers. It is 100% dependent because we just copy value of that pixels four times.

So expression for total noise will be:

square_root((4*red_noise)^2 + (2*orange_noise)^2+(2*green_noise^2)+(blue_noise)^2)

or

sqrt( 16*red_noise^2 + 4*orange_noise^2 + 4*green_noise^2 + blue_noise^2)

Because we assume that signal is the same over those 4 original pixels - and noise magnitude will be the same - so although red_noise, orange_noise, green_noise and blue_noise are not the same values in vector sense - they do have the same magnitude and we can just replace each with noise at this stage.

sqrt(16*noise^2 + 4*noise^2 + 4*noise^2 + noise^2) = sqrt(25 * noise^2) = 5*sqrt(noise^2) = 5*noise.

When we average above sub pixels we will end up with noise being 5*noise / 9, or SNR improvement will be 9/5 = x1.8

That is very interesting fact - we assumed that it will be x1.5 but calculation shows that it is x1.8

Now, either I made mistake in calculation above or this is in fact true.

Any thoughts?

 

Share this post


Link to post
Share on other sites
2 hours ago, vlaiv said:

 Noise adds like square root of sum of squares.

Any thoughts?

I think that only holds true in a continuous system. With discrete data, such as that from an imaging sensor, noise adds arithmetically.

An example of a continuous system would be where exposure time of a single image is increased. Then the noise component (being random) of two images would change with the square root of the exposure times. While the signal (being deterministic) with the simple ratio of them. However, once the image data is sampled, that becomes a discrete system with unchanging noise / signal parameters.


The insert below is a snap from a spreadsheet which attempts to be a numerical model. Consider the 6x6 array of pixels labelled 'Signal'. This can be thought of a single "image" of a small object that has a centre in the outlined square, with a signal value of 17. The pale yellow squares around it suggest what might be seen, compared with a darker background.
I have added some random noise values. So with both the signal and noise data for each individual pixel there are some SNR values.

Of course in practice it is impossible to separate the signal data from the noise data for each individual pixel, so all of this is strictly theoretical ;)

snr-spreadsheet.png.a7d0647542264a995c39e6bc14887250.png

Share this post


Link to post
Share on other sites
1 hour ago, pete_l said:

I think that only holds true in a continuous system. With discrete data, such as that from an imaging sensor, noise adds arithmetically.

An example of a continuous system would be where exposure time of a single image is increased. Then the noise component (being random) of two images would change with the square root of the exposure times. While the signal (being deterministic) with the simple ratio of them. However, once the image data is sampled, that becomes a discrete system with unchanging noise / signal parameters.


The insert below is a snap from a spreadsheet which attempts to be a numerical model. Consider the 6x6 array of pixels labelled 'Signal'. This can be thought of a single "image" of a small object that has a centre in the outlined square, with a signal value of 17. The pale yellow squares around it suggest what might be seen, compared with a darker background.
I have added some random noise values. So with both the signal and noise data for each individual pixel there are some SNR values.

Of course in practice it is impossible to separate the signal data from the noise data for each individual pixel, so all of this is strictly theoretical ;)

snr-spreadsheet.png.a7d0647542264a995c39e6bc14887250.png

I don't think this is very good way to do things. Your noise contains signal in it to start with. Where are negative values?

Noise can't be characterized by single number being error from true value. That is just error not noise. Noise has magnitude and is related to distribution of samples that represent true_value + error, or if you remove true_value it represents distribution of errors.

Having noise of 1 does not mean that error is 1. - it means that (depending on type of distribution of random variable - let's take Gaussian) - 68% of errors will be in range -1,1, 95% of all errors will be in -2,2 range and 99.7% of all errors will be in -3,3 range. For noise of magnitude 1 here is for example 0.15% probability that error will be larger than 3 - but it can happen.

If you have a pixel that has value of 17 - you can equally assign error of -1 or +1 to it, or -2 or 2 or even -5 and 5 (it can happen but with low probability). Your errors show bias - they are all positive values - so they don't have proper distribution to be considered noise (although they might be random).

If you want to create such spread sheet and do "micro case", you need to randomly produce number that has certain distribution. But I think it is better to operate on synthetic images rather than on cells - easier to process.

Here is example

image.png.35d02a3f0c8dcc95e180729e840b2b75.png

This is image with Poisson noise distribution for uniform light signal of value 25. Next to it is measurement of image - it shows that mean value is in fact 25 and standard deviation is 5 (which is square root of signal).

Here is same image binned 2x2 with measurement

image.png.50770ab0c3686b8cc9080c46b904c975.png

Now you see that signal remained the same but standard deviation in fact dropped by factor of 2.

SNR has improved by factor of x2.

Here is it now binned by x3

image.png.86f5c69cad7e914dc4fa99b910c22d5a.png

There is no question about that - binning works, and it works as it should. You should not think about errors being the noise - you need to think about distributions being the noise and having magnitude like a vector rather than being plain old number.

Here is an example: Let's do 2x2 pixel by hand - with noise that we invented, but we will try to at least honor distribution with the fact that errors can be both positive and negative.

Let's say that base number / true value is 25 for 4 pixels, but we don't know that we simply have:

25, 26

23, 26

Errors in this case are:

0, 1

-2, 1

What would be average error? Average error would in this case be 0, and that would imply that on average there is no error in values but there is. This is why we don't use simple average for errors but rather thing similar to sine and RMS - root mean squares.

In above example our average error will be - sqrt((1^2 + 1^2 + 0^2 + (-2)^2)/4) = sqrt(6/4) = ~1.225

This means that our error on average is 1.225 as displacement from true value (either positive or negative).

Let's average our pixels and see how much error will be then: (25+23+26+26) / 4 = 25

Error reduced - now it is closer to true value. That can be expected if you average some positive and some negative values then result will be closer to zero (you see why having all positive values did not produce good results for you?).

 

Edited by vlaiv

Share this post


Link to post
Share on other sites
1 hour ago, vlaiv said:

I don't think this is very good way to do things. Your noise contains signal in it to start with. Where are negative values?

Noise can't be characterized by single number being error from true value. That is just error not noise. Noise has magnitude and is related to distribution of samples that represent true_value + error, or if you remove true_value it represents distribution of errors.

There are no negative values for noise. Noise is a random additive component to the desired signal. So it follows that there can be no negative noise values. In all of this I am only looking at shot noise: the time dependent part of the total noise added to an individual pixel which comes from random photons that enter the telescope.

Once you have read an image off your sensor, its parameters are fixed. There is a component of the final ADU value of each pixel which will be signal and another that will be the sum of all the various noise sources. Binning does not reduce the level of noise as your experiment above shows (the average noise level is still 25 counts). it reduces the spread of the noise, as you say. A binned image can be post-processed by subtracting the ADU value of the average noise from each pixel. And only then has the level of noise in the image been reduced.

 

But going back to the original text, it says:

Quote

Pixel size is not altered, and values are not altered in any way  - we keep the same pixel blur and don't increase it. We end up with 4 subs in place of one sub - we have x4 more data to stack and as we know if we stack x4 more data we will end up with SNR increase of x2.

There isn't any more data. The total number of pixels is the same - just allocated to 4 different subs. So I cannot see how the SNR can be improved to a better ratio than ordinary binning would produce.

Edited by pete_l

Share this post


Link to post
Share on other sites
8 hours ago, vlaiv said:

When we average above sub pixels we will end up with noise being 5*noise / 9, or SNR improvement will be 9/5 = x1.8

That is very interesting fact - we assumed that it will be x1.5 but calculation shows that it is x1.8

Now, either I made mistake in calculation above or this is in fact true.

Any thoughts?

On the principle that "you don't get something for nothing" I would think the discrepancy arises from using upsampled pixels. The signal per upsampled pixel is not the same as if they were real pixels so when you bin red with orange, green and blue, intuitively you are introducing noise. Otherwise you could upsample 4x before binning 6x6 get an even better result of 2.0

Edited by kens
arithmetic error

Share this post


Link to post
Share on other sites
1 hour ago, pete_l said:

There are no negative values for noise. Noise is a random additive component to the desired signal.

Yes there is. Even with Poisson type noise.

Consider following example: We have a barber shop, people go in to have their hair cut. On average 2.4 people will come in to barber shop per hour. There will be hours when no one enters, and there will be hours where 4 persons appear. Signal in this case is 2.4, and measured value per hour can be 0 or 1 or 2 or 3 or 4 ....

If no one appears error for a given hour will be -2.4 or measured_value - true_value. If 4 people walk in on particular hour error will be 4 - 2.4 = 1.6.

Same is true for photons - there is certain brightness from a target that is expressed in number of photons per time interval - that is our value of signal. Measured value will be either less or more than this. Errors can be both negative or positive.

Noise on the other hand is average error value, or can be thought of as likelihood that measured value is close to true value. It has magnitude and that magnitude is always positive - like a vector, it has direction and size and we consider size to be always positive.

1 hour ago, pete_l said:

Once you have read an image off your sensor, its parameters are fixed. There is a component of the final ADU value of each pixel which will be signal and another that will be the sum of all the various noise sources. Binning does not reduce the level of noise as your experiment above shows (the average noise level is still 25 counts).

Binning both reduces error and hence spread of error, or average error value - noise. Signal is still 25 counts, but deviation from that signal - or average error goes down when you bin it.

Binning is nothing more than stacking images - same as stacking improves signal to noise ratio, so does binning. Same thing happens when you average four subs - you in fact average four "overlapping" pixels, and with binning - you average four adjacent pixels, and provided that you are oversampling - those 4 pixels will have roughly the same signal, same as in four subs.

2 hours ago, pete_l said:

There isn't any more data. The total number of pixels is the same - just allocated to 4 different subs. So I cannot see how the SNR can be improved to a better ratio than ordinary binning would produce.

There is no more data and splitting original sub into 4 subs is the same as binning - except for one thing - pixel blur. Pixel blur is consequence of pixels having finite size - larger the size more blur is introduced. Sampling should be done with infinitesimally small points, but in reality it is not. Because of this, there is a bit of blur. When you add 4 adjacent pixels, you are effectively getting the same result like using larger pixel. With splitting you are lowering sampling rate (larger space between sampling points) but you are keeping pixel size the same. Each of these 4 subs will be slightly shifted in alignment phase, but there will be no enlargement of the pixels and no pixel blur increase.

Share this post


Link to post
Share on other sites
8 minutes ago, kens said:

On the principle that "you don't get something for nothing" I would think the discrepancy arises from using upsampled pixels. The signal per upsampled pixel is not the same as if they were real pixels so when you bin red with orange, green and blue, intuitively you are introducing noise. Otherwise you could upsample 4x before binning 6x6 get an even better result of 2.0

I'm not sure it would produce result of 2.0. Let's do the math and see what happens. Instead of splitting each pixel in 4 smaller ones (upsampling by 2 as you would put it), let's do that with 4 and repeat the math.

This time we will be averaging 36 pixels instead of just 9, right? (6x6 grid instead of 3x3). So we need to divide total noise by 36.

Total noise in this case will be sqrt( (16*red)^2 + (8*green)^2 + (8*orange)^2 + (4*red)^2 ) = sqrt( 256*noise^2 + 64*noise^2 + 64*noise^2 + 16*noise^2 ) = sqrt(  400 * noise^2) = 20*noise

So total noise will be noise * 20 / 36, and we need reciprocal of that to see increase in SNR, so it will be 36/20 - and that is still x1.8

You gain nothing by splitting further.

It is respective "areas" of each pixel that add up to form larger pixel that determine SNR increase - not number of splits. I used splitting of pixel because that allows me use the same principle that I outlined before that does not introduce additional pixel blur.

By the way, there is explanation for this, one that is not immediately obvious. With integer binning we are not introducing correlation between noise of each pixel.

When we sum 2x2 grid of pixels, those 4 pixels contribute to value of one resulting pixel and no other pixels. Each resulting pixel will get its own unique set of 4 original pixels that make it up. With fractional binning - this is not the case.

Look at the image in my first post ("color coded" one) - resulting pixel will contain whole red group (single pixel) - half of orange and half of green group and only quarter of blue group. This means that green group gives value to both this pixel, but also next one in vertical. Orange does the same but gives value to the next right pixel, and blue will give value to 4 adjacent resulting pixels.

This introduces correlation in noise of those resulting pixels - their noise is no longer independent. This is concern if we are doing any sort of measurement, but it is not concern for creating nice image. In fact if we use any sort of interpolation algorithm when aligning our final subs for stacking (except original shift and add) - which implies sub pixel alignment of frames, we will be introducing both signal and noise correlation in pixels of aligned subs. It does not hurt the final image.

Share this post


Link to post
Share on other sites

Yes - I made an arithmetic error. To investigate further I tried to work out the optimal binning ratio that gives the best improvement of SNR over expected.

Lo and behold the optimum is 1.414 which has an SNR 1.707 vs the expected 1.414. Could that be a clue as to the source of the discrepancy?

Share this post


Link to post
Share on other sites
27 minutes ago, kens said:

Yes - I made an arithmetic error. To investigate further I tried to work out the optimal binning ratio that gives the best improvement of SNR over expected.

Lo and behold the optimum is 1.414 which has an SNR 1.707 vs the expected 1.414. Could that be a clue as to the source of the discrepancy?

I think it could - no wonder that numbers you got have to do with square root of two, that is something that does not surprise me (because we work in 2d and area is square).

1.414 is square root of 2 (well rounded down), and 0.707 is 1/sqrt(2).

We do have to be careful when doing things with arbitrary fractions. There are couple of reasons why I presented fractional binning in the way I have above. Doing x1.5 bin is going be beneficial in two things

1. It can be implemented in "split" fashion rather easily (not as easy with arbitrary fraction - you get very large number of subs that mostly repeat values) - alternative is to do actual binning on each sub and increase pixel blur.

2. It is symmetric

I'll expand on this a bit and we can then have a look at other example to see if there is indeed difference that I believe exists.

When we do x1.5 bin like I explained above we get certain symmetry. If we observe first 2x2 group of resulting pixels we can see that:

- first one contains one whole pixel, two halves of other pixels and quarter of fourth pixel

- second one will contain the same thing - one remaining half (other half of orange group), one full pixel (next original pixel or group if you will in X direction), 1/4 of blue group and again half of pixel in bottom row.

- same will be for third an fourth pixel - ingredients will be the same just geometrical layout will be different, but math involved for each will be the same.

Let's try now with different approach where we loose this sort of symmetry. Let's break up original pixels in groups of 9 (3x3) and bin 4x4 these little sub pixels.

If we go in X direction, first resulting pixel will consist of: 3x3, 3x1, 1x3 and 1x1. But second resulting pixel will consist out of a bit different "configuration" - it will be: 2x3, 2x3, 2x1, 2x1.

We need to do the math for each of these and see if they add up to same thing (and I'm guessing they are not, but we need to check just in case):

9^2 + 3^2 + 3^2 + 1^2 = 81 + 18 +1 = 100

6^2 + 6^2 + 2^2 + 2^2 = 36+36+ 4+4 = 80

So first pixel will have something like 16/10 = 1.6 improvement in SNR, but second pixel will have something like ~1.7889.

Now this seems a bit strange that different pixels have different SNR improvement - but again this is due to noise correlation, and if you do this on single subs and align those subs after - these SNR improvements will average out.

But the point is - we can't determine SNR improvement based on single resulting pixel case if there is asymmetry like above. In fact in above case we will have something like:

1.6, 1.7889, 1.6, 1.7889, ....

1.7889, 1.6, 1.7889, 1.6, ....

1.6, 1.7889, 1.6, 17889, ....

Each other pixel will have different SNR improvement in checker board pattern. There is about half of 1.6 and half of 1.7889 - and I honestly don't know how SNR improvement will average, will it behave like regular numbers or like noise. If it behaves like noise then average will be: sqrt ( 1.6^2 + 1.7889^2) = 2.4, but if it behaves like normal numbers average will be (1.6 + 1.7889) = 1.69445

It stands to reason that it will average like regular numbers, so I'm guessing that total average SNR improvement after stacking will be 1.69445

This logic is much harder to apply when you have bin like x1.414 because number of possible combinations of areas that go into resulting pixels is infinite, and each one will have slightly different SNR improvement - and in the end you have to average those out.

Probably easiest way to do it would be to actually implement "regular" fractional binning (that one is easy to measure because it works on single sub and does not need alignment and stacking afterwards) and test it on bunch of subs with synthetic noise and measure standard deviation of result to see what level of improvement there is for each fractional bin coefficient. Maybe we can derive some sort of rule out of it.

 

Share this post


Link to post
Share on other sites
6 minutes ago, vlaiv said:

1.6, 1.7889, 1.6, 1.7889, ....

1.7889, 1.6, 1.7889, 1.6, ....

1.6, 1.7889, 1.6, 17889, ....

Each other pixel will have different SNR improvement in checker board pattern. There is about half of 1.6 and half of 1.7889 - and I honestly don't know how SNR improvement will average, will it behave like regular numbers or like noise. If it behaves like noise then average will be: sqrt ( 1.6^2 + 1.7889^2) = 2.4, but if it behaves like normal numbers average will be (1.6 + 1.7889) = 1.69445

It stands to reason that it will average like regular numbers, so I'm guessing that total average SNR improvement after stacking will be 1.69445

This logic is much harder to apply when you have bin like x1.414 because number of possible combinations of areas that go into resulting pixels is infinite, and each one will have slightly different SNR improvement - and in the end you have to average those out.

Probably easiest way to do it would be to actually implement "regular" fractional binning (that one is easy to measure because it works on single sub and does not need alignment and stacking afterwards) and test it on bunch of subs with synthetic noise and measure standard deviation of result to see what level of improvement there is for each fractional bin coefficient. Maybe we can derive some sort of rule out of it.

This is actually not correct as there will be even third case where we have distribution like 2x2, 2x2, 2x2 and 2x2 (second pixel in second row of resulting pixels) which will have SNR improvement of x2

I'm doing this of the top of my head, but I think that resulting SNR in this case will be 3/8 * 1.6 + 3/8 * 1.7889 + 1/4 *2 = ~1.771 but can't be certain that I got it right this time (could be wrong again).

Maybe best thing to do is to implement it and measure - will do that tomorrow and post results.

Share this post


Link to post
Share on other sites

As I take it, you are exchanging uncorrelated noise for correlated noise. In the case of integer binning (2x2, 3x3, etc) the noise in the resulting pixels is uncorrelated, because each of the pixels is the result of the sum of different pixels in the input image. However, in the case of fractional binning, Each pixel contributes to nine pixels in the output, meaning that if a given pixel has a bit of a noise spike this is spread out over 9 pixels in the surroundings, causing local bias.

Share this post


Link to post
Share on other sites
2 minutes ago, michael.h.f.wilkinson said:

As I take it, you are exchanging uncorrelated noise for correlated noise. In the case of integer binning (2x2, 3x3, etc) the noise in the resulting pixels is uncorrelated, because each of the pixels is the result of the sum of different pixels in the input image. However, in the case of fractional binning, Each pixel contributes to nine pixels in the output, meaning that if a given pixel has a bit of a noise spike this is spread out over 9 pixels in the surroundings, causing local bias.

I figured that as well.

Do you by any chance have idea if this correlation is going to affect results of stacking? Does it change distribution of noise in such way that it lowers SNR gains in stacking?

I don't think that local correlation of noise is necessarily a bad thing in astro imaging. It certainly can be when you are doing measurements, but for regular photography I can't see any down sides except possibility of altered noise distribution.

Share this post


Link to post
Share on other sites
2 hours ago, vlaiv said:

I figured that as well.

Do you by any chance have idea if this correlation is going to affect results of stacking? Does it change distribution of noise in such way that it lowers SNR gains in stacking?

I don't think that local correlation of noise is necessarily a bad thing in astro imaging. It certainly can be when you are doing measurements, but for regular photography I can't see any down sides except possibility of altered noise distribution.

It means some of the power in the Fourier power spectrum of the noise moves to lower spatial frequencies, so the 1.8x suppression at the highest frequencies will be offset partly by an increase at slightly lower frequencies. A certain bumpiness in the background might be seen if you go pixel peeping

  • Like 1

Share this post


Link to post
Share on other sites
10 minutes ago, michael.h.f.wilkinson said:

It means some of the power in the Fourier power spectrum of the noise moves to lower spatial frequencies, so the 1.8x suppression at the highest frequencies will be offset partly by an increase at slightly lower frequencies. A certain bumpiness in the background might be seen if you go pixel peeping

I'm getting that sort of result, but here is what confuses me - it is more pronounced on low fraction than on high fraction.

If I'm binning by factor of x1.1, I'm getting quite a bit of artifacts in pure noise as a result of frequency distribution change - but it seems to be only in "one direction". FFT confirms this. It is probably due to error in implementation, but I can't seem to find it :D (as is often case with bugs).

Here is example:

image.png.8cd8d5f90f84f2c6c49c93fed5659f0e.png

Distribution is no longer gaussian - but more narrow, and there are vertical "striations" in the image. Here is raw power spectrum via FFT:

image.png.76ed358d4d1c06807a78fc75baec548c.png

It's obvious that higher frequencies are attenuated - but again it is in single direction - which is weird and should not happen. There is obviously a bug in software that I need to find.

On the other hand, here is bin x1.5 - effects is much less pronounced:

image.png.b887d4d18c09c15a6fbc73c47abf25be.png

Both image and distribution look ok, but power spectrum is still showing above "feature":

image.png.4eb068101e9096ad1abfd1e7c15a6ea0.png

 

 

Share this post


Link to post
Share on other sites

The banding is easily explained in the 1.1x case, as the weights by which pixels are added vary periodically. Looking just at the horizontal binning, in the first pixel the weights are 10 and 1, the second 9 and 2, the third 8 and 3, then 7 and 5, 6 and 5, 5 and 6, etc. At the first pixel the expected gain in S/N is a modest 11/sqrt(101), or just 1.0945,  with weights of 5 and 6, we get an improvement of 11/sqrt(36+25) or 1.4084. In the case of 1.5x this effect does not occur, because the weights alternate between 2, 1 and 1, 2 (again just looking at 1-D binning).

What I would do to debug is to first bin horizontally, and then bin the result vertically.

Share this post


Link to post
Share on other sites
3 minutes ago, michael.h.f.wilkinson said:

The banding is easily explained in the 1.1x case, as the weights by which pixels are added vary periodically. Looking just at the horizontal binning, in the first pixel the weights are 10 and 1, the second 9 and 2, the third 8 and 3, then 7 and 5, 6 and 5, 5 and 6, etc. At the first pixel the expected gain in S/N is a modest 11/sqrt(101), or just 1.0945,  with weights of 5 and 6, we get an improvement of 11/sqrt(36+25) or 1.4084. In the case of 1.5x this effect does not occur, because the weights alternate between 2, 1 and 1, 2 (again just looking at 1-D binning).

What I would do to debug is to first bin horizontally, and then bin the result vertically.

Managed to find a bug - no banding is now present, and power spectrum displays nice attenuation from center to edges.

I'm now trying to hunt down another bug (don't you just love programming :D ) - I get SNR improvement of x2 for binning x1.5 for some reason - which means values are not calculated correctly (or maybe my initial calculation was wrong - will figure it out on small image 3x3 if values are calculated correctly).

Share this post


Link to post
Share on other sites
Just now, vlaiv said:

Managed to find a bug - no banding is now present, and power spectrum displays nice attenuation from center to edges.

I'm now trying to hunt down another bug (don't you just love programming :D ) - I get SNR improvement of x2 for binning x1.5 for some reason - which means values are not calculated correctly (or maybe my initial calculation was wrong - will figure it out on small image 3x3 if values are calculated correctly).

BTW, the banding I refer to in the 1.1x case should not so much be visible as dark and light stripes, but more noisier and less noisy stripes. This could perhaps be detected by calculating variance per column or row

 

Share this post


Link to post
Share on other sites
Just now, michael.h.f.wilkinson said:

BTW, the banding I refer to in the 1.1x case should not so much be visible as dark and light stripes, but more noisier and less noisy stripes. This could perhaps be detected by calculating variance per column or row

 

It turns out that it was artifact due to wrong condition in for loop - < instead of <= :D - but you are right, that sort of artifact happens when you rotate image by very small angle and use bilinear interpolation. It is visible only in noise if you stretch your histogram right - due to different SNR improvement - small fraction of one pixel and large of another will have small SNR improvement, but equal size fractions will have SNR improvement of 1.414 ... So you get "wave" in noise distribution going over the image.

Share this post


Link to post
Share on other sites

I use fractional binning in my Jocular EAA tool (for colour binning). And I can imagine that in general it is very useful to be able to match binning to seeing, which is always going to be best suited to fractional values.

It is implemented using interpolation via the rescale function available in the scikit-image module of Python. I'd suggest there are as many ways to implement fractional binning as there are interpolation algorithms, but I imagine any reasonably sophisticated interpolation algorithms (that include antialiasing for example) will do what you need.

Martin

Share this post


Link to post
Share on other sites

Here are the results, and are quite "unexpected" to say the least :D

image.png.b36ba57192c61b87f7370e12778c5389.png

I ran gaussian noise on 512x512 image and measured standard deviation at 0.1 intervals (starting at 1 and ending up at bin x3).

Interestingly enough - it almost represents a straight line with dips at certain points - whole numbers and 1.5 and 2.5. Probably because level of correlation is small at those factors.

9 minutes ago, Martin Meredith said:

I use fractional binning in my Jocular EAA tool (for colour binning). And I can imagine that in general it is very useful to be able to match binning to seeing, which is always going to be best suited to fractional values.

It is implemented using interpolation via the rescale function available in the scikit-image module of Python. I'd suggest there are as many ways to implement fractional binning as there are interpolation algorithms, but I imagine any reasonably sophisticated interpolation algorithms (that include antialiasing for example) will do what you need.

Martin

This type of binning - at least how I see it is a bit different than using interpolation especially for bin coefficients larger than 2.

Take for example bilinear interpolation - it will only "consult" 4 neighboring pixels depending where interpolated sample falls. With factor larger than 2, fractional binning will operate on at least 9 pixels.

But you are right, as implemented above, fractional binning is very much like rescaling algorithm. I plan to implement it slightly differently though - like split algorithm described in first post - at least for some fractions (2 and 3 in denominator and suitable values in enumerator). That will remove this sort of pixel to pixel correlation and implement a sort of "weighing" in the stack, because some pixel values will be present multiple times.

 

Share this post


Link to post
Share on other sites
4 hours ago, michael.h.f.wilkinson said:

As I take it, you are exchanging uncorrelated noise for correlated noise. In the case of integer binning (2x2, 3x3, etc) the noise in the resulting pixels is uncorrelated, because each of the pixels is the result of the sum of different pixels in the input image. However, in the case of fractional binning, Each pixel contributes to nine pixels in the output, meaning that if a given pixel has a bit of a noise spike this is spread out over 9 pixels in the surroundings, causing local bias.

Agreed. It seems to me that all you do by processing correlated noise is to broaden the point spread function. Essentially adding blur. That would definitely suppress the appearance of noise, but it would alter any "data" in the image, too.
What I would like to see is that instead of a field of just noise, to analyse how this reacts with astronomical targets in the image.

Share this post


Link to post
Share on other sites
Just now, pete_l said:

Agreed. It seems to me that all you do by processing correlated noise is to broaden the point spread function. Essentially adding blur. That would definitely suppress the appearance of noise, but it would alter any "data" in the image, too.
What I would like to see is that instead of a field of just noise, to analyse how this reacts with astronomical targets in the image.

We are actually looking into exactly that issue in the development of a new software package named Sourcerer, in which we want to find the faintest possible real structures without finding heaps of false positives. Studying the effect of different blurring strategies is part of that research.

Share this post


Link to post
Share on other sites
Just now, michael.h.f.wilkinson said:

We are actually looking into exactly that issue in the development of a new software package named Sourcerer, in which we want to find the faintest possible real structures without finding heaps of false positives. Studying the effect of different blurring strategies is part of that research.

:) sounds good. I hope there's a large dollop of machine learning in there, driving an adaptive filter ........

Share this post


Link to post
Share on other sites
2 minutes ago, pete_l said:

Agreed. It seems to me that all you do by processing correlated noise is to broaden the point spread function. Essentially adding blur. That would definitely suppress the appearance of noise, but it would alter any "data" in the image, too.
What I would like to see is that instead of a field of just noise, to analyse how this reacts with astronomical targets in the image.

In above example there will be some broadening of PSF due to pixel blur - larger pixels, larger pixel blur so increased FWHM of PSF.

In split method if you oversampled to begin with - that does not happen.

I wondered why my initial calculation was wrong, it gave SNR improvement by factor of 1.8 but test resulted in 2.0. Then I realized that I did not account for correlation.

We can attest this by doing another experiment - splitting binned data into sub images. As correlation for bin factor of 1.5 happens to adjacent pixels - if I split result of binning, it should have proper distribution and 1.8 improvement in standard deviation. It should also show no modification to power spectrum. Let's do that :D

Here are results for x1.5 bin of gaussian noise with sigma 1:

image.png.bac171e30e205f4dfd757aecfcc1598b.png

And power spectrum of it:

image.png.5f4da5cc1193e3e398133d1dcba15ac0.png

It shows slight drop off towards the edges - high frequencies.

Hm, another twist :D

Here is result of splitting binned sub:

image.png.e7de78440d07fce289086ea6c977daf5.png

Standard deviation remains the same, but power spectrum is now "fixed":

image.png.18f7cd214b43664164a969e647a6b929.png

So this removed correlation as expected - and can be seen in power spectrum, but SNR improvement is still 2.0?

I'm sort of confused here

Share this post


Link to post
Share on other sites
1 minute ago, pete_l said:

:) sounds good. I hope there's a large dollop of machine learning in there, driving an adaptive filter ........

Actually, I tend to prefer statistical approaches to machine learning in this context. Our MTObjects program has shown that you can achieve high recall and precision just by detecting features for which the null hypothesis that the structure is noise must be rejected at the p=10^-6 level, without any assumptions on what sort of structure it is. With machine learning you run the risk that the method will find those structures it has been taught to find, and potentially ignore interesting new stuff. Our adaptive blurring filters are also being optimised by looking at the relationships with optimal kernel density estimation (after all, we want to estimate the density distribution of photons in the image optimally) .Machine learning can and will be used to do a classification of objects into known classes, preferably with an extra class label "Human help needed" for things that look like they don't fit into any known category well.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.