# Math operations on several images

Hello,

I want to divide pixel intensities on an image (8 bit) by a unique factor, say 6. I do this on 6 images having the same size. The next step is to add them in one image output, pixel by pixel, so that each pixel output stays in the 8 bit range.

How can I do that under Fiji ?

Thank you

Hello Tryphon -

If you add 6 images together and divide by 6, you are taking
the average of the images. In this specific case, the following
should work:

``````Image > Stacks > Images to Stack
Image > Stacks > Z Project...`
``````

`Images to Stack` works on all of the images you have
open (so open the images to average first). Then choose
`Average Intensity` in the `Projection type` drop-down
when you run `Z Project...`

If you don’t necessarily want to calculate the standard average
and need greater control over the math you do, you could use
`Process > Image Calculator...` to add the images together
two at a time (checking `32-bit (float) result` to avoid
overflow). You can then use the various commands under
`Process > Math` to do other math, for example, to divide by
by your factor of 6 by running `Process > Math > Divide...`.
Then run `Image > Type > 8-bit` to convert your image
back to an 8-bit image. (It appears that you may have to run
`Image > Adjust > Brightness/Contrast` before
converting back to 8 bits to get the conversion to scale properly.)

Thanks, mm

So efficient and fast ! Never tried Z Project but it did what I want.

I tried your second method too. The only thing I did not catch is the use of Brightness/Contrast : I need to apply the same operations on the images (then same B/C parameters ?).

Anyway I can finish my macro thanks to you.

Thank you mm.

Hello Tryphon -

No, the `Brightness/Contrast...` wasn’t for the original
images, only for the 32-bit image before converting back to
8-bit.

I don’t understand in detail what is going on, but, sensibly, the
32-bit-to-8-bit conversion does some kind of scaling, and the
way I found to get that scaling to work for your use case was
to run `Brightness/Contrast...`.

But if `Z Project...` works for you, I wouldn’t mess with the
added complexity of using `Image Calculator...`, step by
step, two images at a time.

Thanks, mm