# Resize 3D binary image by averaging

7 views (last 30 days)
Xiaoli on 16 Jan 2017
Commented: Image Analyst on 12 Sep 2020
Hi, I want to reduce the size of a binary image stack by averaging the values in 3D. For example if the image is 1260*1260*6. I wrote the code below to process the image to average the values in every 4*4*2 cube thereby creating a new matrix that is 315*315*3 in size.
X(1:315)=4;
Y(1:315)=4;
Z(1:3)=2;
A=mat2cell(imagestack_1,[X],[Y],[Z]);
average=cellfun(@mean2,A);
The problem with this code is that its very slow. Please suggest a faster way. My actual image is super big 2000*2000*2000, so please consider the size when suggesting solutions.
Also, the object in the binary image whose size I want to reduce is cylindrical in shape (like a bunch of circles with equal size stacked together). Since I don't know how to average only the values in the circle, I am first cropping the largest square from the circle and then performing the average. If anyone can think of a way to average only the values in the circle.
I am not using imresize or interp3 because I don't any kind of interpolation, I just want a simple arithmetic average as 1 in the object represents solid and 0 represents void space, so I want to know the mean of solid and void space.
##### 2 CommentsShowHide 1 older comment
Xiaoli on 16 Jan 2017
Hey, thanks, here are the memory stats from matlab
>> memory
Maximum possible array: 62253 MB (6.528e+10 bytes) *
Memory available for all arrays: 62253 MB (6.528e+10 bytes) *
Memory used by MATLAB: 811 MB (8.501e+08 bytes)
Physical Memory (RAM): 32692 MB (3.428e+10 bytes)
• Limited by System Memory (physical + swap file) available.

Image Analyst on 16 Jan 2017
To convolve in 3-D, which can compute a local average, use the convn() function.
Image Analyst on 12 Sep 2020
Sorry, I don't remember asking that question.
But you asked one. But it doesn't seem related to this one, so ask it in a new question after you read this link.