Imagine I have a stack of image frames, (f1,...,fN)∈F, where each fi 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 fi.
Unfortunately, the following procedure is painfully slow (when applied to a 256×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:
Edit
As Kuba pointed out, a better solution would be:
StandardDeviation[ImageData /@ imageStack]
Comments
Post a Comment