Speed up convolution and supersampling in 3D binary matrix
Show older comments
HAllo! and thanks in advance to averybody.
I have a 3D matrix made by confocal microscopy images that have the same resolution on x,y axes and about 1/7 of resolution on z axes. To perform a supersampling on z axes I wrote this code that perform a convolution with a gaussian function on Z axes and than an uppersampling for each Z vector.
function [matrixZ,Zplanes] = denoising3Z (matrix,planes);
x = [1,1,1];
h = @(x) gaussmf(x,[4,0]);
Zplanes = planes * 7;
[r,c] = size(matrix{1,1});
matrixZ = zeros (r,c, Zplanes);
for i = 1: r
for j = 1 : c
vectorZ = zeros(1,6);
for z = 1 : planes
vectorZ(1,z) = matrix{1,z}(i,j);
end
vectorCZ(1,:) = filter(h(x),2,vectorZ(1,:));
V2 = imresize(vectorCZ, [1 Zplanes], 'bilinear');
matrixZ(i,j,:) = V2(1,:);
end
i
end
end
It works very well but it has to repeat these operation for 6 million of Z vector per images and the entire operation takes a long time. How I can speed up the process? It is possible to create a filter volume and applicate the volume to the matrix in just one pass? Probably it should be a bit more rapid. Thanks.
Accepted Answer
More Answers (1)
Deepak Bhatia
on 3 Mar 2017
0 votes
Looking at the nested loop structure, I recommend looking into vectorization in MATLAB as it might reduce code execution time.
Categories
Find more on Biomedical Imaging in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!