Jump to content
Maarten Langeveld

Stacking two photo's : wrong mathematics ?!

Recommended Posts

Stacking two photo's in Affinity Photo, I get different results between 'mean' and 'median'.

Which really surprises me since with two samples the mean and median mathematically have the same outcome, while in Affinity the respective results differ a lot !

I would have expected same results in Affinity Photo. What's going (wr)on(g) ?

Share this post


Link to post
Share on other sites

Interesting. Looking at the docs, it suggests that median removes content that is not consistent in each image - suitable for object removal and noise reduction. So I wonder if there's some extra calculations in play there that makes it more suitable for that. I expect they've taken a median calculation and expanded it to suit that purpose? I'm only guessing though. Not sure how it could really work properly with two images.

Share this post


Link to post
Share on other sites

It’s an interesting question.
If there are only two images and a pixel is ‘different’ (however it measures this) in each/either, how does Photo decide which one is the ‘inconsistent’ one of the two? They are both inconsistent with each other wherever the pixels are different so I would expect a function which “removes pixel content that is not consistent in each image” to leave lots of holes in the result where the differences were.

Share this post


Link to post
Share on other sites

So working with three images whereby I've loaded the same image twice and then chosen a different image and put them into a stack, the median does exactly as you'd expect and disregards the image that is different. However, hiding one of the duplicated images, leaving just two images that are different seems to reveal a picture whereby some pixels are selected from one image and some from the other almost like there's some weird masking taking place (which is kind of expected to some degree). So it looks like it's choosing one or the other image to show for each pixel. How it's deciding that I'm not sure, but a true mathmatical median should be taking into account that there's an odd or even number of samples, and if it's even, taking the two middle ones and doing a mean between those to arrive at the result. Would that be useful from an imaging point of view? I'm not too sure, but it's kind of interesting what is happening - could be useful as an effect maybe?

Share this post


Link to post
Share on other sites

Loading a pair of images twice (4 images stacked : two same pairs) results in same error as with two different images. Mathematically the median should have same result as the mean which it does not with Affinity. Curious...

Share this post


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

It’s an interesting question.
If there are only two images and a pixel is ‘different’ (however it measures this) in each/either, how does Photo decide which one is the ‘inconsistent’ one of the two? They are both inconsistent with each other wherever the pixels are different so I would expect a function which “removes pixel content that is not consistent in each image” to leave lots of holes in the result where the differences were.

With even number of images the median should be calculated as the mean of the two middle observations, which Affinity apparently does not. Curious how Affinity calculates the median when even number of images is stacked...

Agree with you suggestion: next to the 'outlier' stack operator a 'remove outlier' stack operator should be more than welcome.

Share this post


Link to post
Share on other sites
On 12/3/2019 at 9:50 AM, Maarten Langeveld said:

Curious how Affinity calculates the median when even number of images is stacked...

For something really curious, try duplicating an experiment I did with the simplest set of test files I could think of: two greyscale 8bit PNG files, each consisting of 2 pixel-aligned vertical stripes, one of which is 100% white & the other 100% black. The only difference between the two files is one is the mirror image of the other. Compare the Info panel results for the mean (on the left) & median (on the right) operators:

mean.jpg.ac05d641ca82d0c9f688cb13251eb587.jpg median.jpg.31b4bda83cb729332914062cf670034c.jpg

Assuming I did not do anything stupid (always a possibility), both should result in K values of exactly 50% ... but neither one does. O.o

If you want to check my work, Black & White.zip includes the 2 png files (Black-white.png & White-black.png) plus the .afphoto stack file (Black & White Stack.afphoto).


Affinity Photo 1.7.3, Affinity Designer 1.7.3, Affinity Publisher 1.7.3; macOS High Sierra 10.13.6 iMac (27-inch, Late 2012); 2.9GHz i5 CPU; NVIDIA GeForce GTX 660M; 8GB RAM
Affinity Photo 1.7.3.155 & Affinity Designer 1.7.3.1 for iPad; 6th Generation iPad 32 GB; Apple Pencil; iPadOS 13.1.2

Share this post


Link to post
Share on other sites
On 12/3/2019 at 2:09 PM, Maarten Langeveld said:

I would have expected same results in Affinity Photo. What's going (wr)on(g) ?

Good call. As far as the feature is supposed to copy the Photoshop feature (as it seems), and how median is usually calculated with numeric values (for even series taking the average or two middle values, otherwise taking the middle one, when comparing the channel values), there seems to be an error in the operation.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×

Important Information

Please note the Annual Company Closure section in the Terms of Use. These are the Terms of Use you will be asked to agree to if you join the forum. | Privacy Policy | Guidelines | 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.