# Division of each slice in a stack by the following one

Hey all!

I have a stack of images and I would like do divide each slice by the following one.
I could not achieve this so far using “Process --> Image Calculator”.

Could you give me a solution for this? Maybe I need to use Macros?

Thomas

Welcome to the forum, @twckr!

You can for example do the following:

1. Make sure your stack is Image > Type > 32-bit
2. Image > Duplicate… your stack A to create stack B
3. Duplicate the last slice in A and the first slice in B using Image > Stacks > Tools > Stack Sorter and the Duplicate button
4. Divide A / B using Process > Image Calculator as you suggested.

Creating a macro or script from this would involve a few more lines, because step 3 above is not recordable in the Macro Recorder.

1 Like

Jan already replied but you’ll find below a short example within a macro !
Cheers,
Romain

``````run("Confocal Series (2.2MB)");	 // open a stack image
ori = getTitle; // get its title
getDimensions(width, height, channels, slices, frames); // and infos

// prepare sub-stacks
selectImage(ori); // select your stack , and duplicate from 1st to (last -1) image
run("Duplicate...", "title=first duplicate channels=1 slices=1-"+(slices-1)	);
selectImage(ori);// select your stack , and duplicate from 2nd to last image
run("Duplicate...", "title=next duplicate channels=1 slices=2-"+slices );

// use image calculator
imageCalculator("Divide create 32-bit stack", "first","next");
rename("ImgCalc_First_divide_Next");
run("Fire");

run("Merge Channels...", "c1=first c2=next keep");
rename("Merge_First=Red_Next=Green");
``````
2 Likes

@imagejan, @romainGuiet thank you very much for you help!

Both solutions work fine fore me!

1 Like