Skip to main content

Is there a fast method of generating a Standard Deviation image from a frame stack?


Imagine I have a stack of image frames, $(f_1, ..., f_N) \in F$, where each $f_i$ has the same set of $(x,y)$ dimensions. Using these frames, I'd like to create an image where each pixel in the image consists of the standard deviation of the values at the corresponding pixel position in each of the $f_i$.


Unfortunately, the following procedure is painfully slow (when applied to a $256 \times 256$ pixel image):



SDImage = ImageData@FrameStack[[1]];
For[a = 1, a <= ImageDimensions[FrameStack[[1]]][[1]], a++,
For[b = 1, b <= ImageDimensions[FrameStack[[1]]][[2]], b++,
SDImage[[a, b]] = StandardDeviation[Table[ImageData[FrameStack[[k]]][[a, b]], {k, 1, Length[FrameStack]}]];
Print[SDImage[[a, b]]];
];
];

SDImage = Image[SDImage]


Is there a faster method of doing this, or perhaps a built in tool (like in ImageJ)?



Answer



Assuming you have loaded a stack of images and stored in a variable called imageStack you can do the following to compute the standard deviation image over the entire stack:


imageStack = Import["ExampleData/CTengine.tiff"];
xyStd = Image@Thread[StandardDeviation[ImageData /@ imageStack], {1}];

This gives you the standard deviation image in z direction of the stack. For the upper example xyStd gives the following image:


Standard deviation image of engine example.


Edit


As Kuba pointed out, a better solution would be:



StandardDeviation[ImageData /@ imageStack]

Comments