Interpolating slices in a stack
A colleague asked for a macro that for an entire stack would average two adjacent slices in a stack and insert the result between the originals.
In this collection of macros the macro "interleave stacks" creates a running average of 2 stack and interleaves back into the original and sets the Z scale metadata to the original divided by 2.
After writing it, I realized that the Z rescaling command in ImageJ might do the same thing much faster. I was surprised, however, that the interpolation stretched throughout the stack. For the application requested, the macro solution is required.
Top group: Original data.
Middle group: result of macro.
Each original slice is preserved and the inserted slice is a function of only the two surrounding slices.
Bottom group:
Image > Scale > with X scale 1,
Y scale 1,
Z scale 2, interpolation bilinear.
Slices are averaged with weights based on distance over a range of the stack. Only the first and last slice are preserved unchanged.
About the macro:
It uses average intensity to combine the two images, but there are other methods that could be in the function projectStackVariableWidth("Average Intensity", 2);
The macro “Projections of variable width” allows you to test the different methods.
"Max Intensity", "Average Intensity", "Standard Deviation", "Min Intensity", "Median"
Also, a custom function could be added, such as a difference followed by other math.
Also, reslicing, then rescaling in Y, then reslicing again might be faster.
Of course there is morphing software...
last updated 20190605