# Multiply two Images

Hi,

I want to calculate the variance over 10 Images. For that I need two multiply two GRAYSACLE Images mathematical and pixel wise. So for example you have the two pixel with the same coordinates and their values 10 and 12, you get the new pixel value 120. If the result is higher than 255 (maximum of the 8 Bit GRAYSCALE Format), the pixel value should be 255. Unluckily the Image.mul() function does not calculate that. Is there an efficient way to solve that Problem? Without two for-loops with Image.get_pixel / Image.set_pixel.

Tobi

Um, just think about what you want to do a little bit more… Most pixel values are like 150-200. You will immediately saturate the image to 255 per pixel. The way multiply works right now is like it is because unless you make the image 16-bits per pixel or more there’s no way to store the accumulation.

So… are you sure what you want trying to do is the right way? Is there another way to do what you want?

It’s not a huge problem if the values can’t get higher than 255. The reason is the formula of the variance. I use a special formula so I don’t need to store to many pictures [variance: Sk = Sk-1 + (xk – Mk-1)*(xk – Mk)]. As you can see I subtract the mean of the picture xk and afterwards I multiply them. So most values of the pixel will be very low at the multiplication and the rest of it will be very high or at the maximum. And that’s totally fine.
And if I subtract the old variance with the new one I get a binary picture. With that I can get the movements of the video and run some algorithm over. Just a little comment on what I’m doing.
I tried it out on matlab and it worked perfect.

So is there an efficient way to calculate the “mathematical” multiplication pixel wise on an 8 bit picture?
You don’t need to worry about saturation. And if a counter overflow occurs it should stay at the maximum.
Or do you have another way to calculate the variance?