Speed up convolution and supersampling in 3D binary matrix

1 visualización (últimos 30 días)
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.

Respuesta aceptada

Emanuele Gandola
Emanuele Gandola el 10 de Mzo. de 2017
Thank you Deepak, I found this really usefull solution
function [matrixZ,Zplanes] = denoising3D (matrix,planes);
Zplanes = planes * 7;
B = imgaussfilt3(matrix);
[r,c,z] = size(B);
matrixZ = zeros (r,c, Zplanes);
for i = 1: r
img(:,:) = B(i,:,:);
imgZ = imresize(img, [c Zplanes]);
matrixZ(i,:,:) = imgZ;
end
end
imgaussfilt3 is a new volumetric function implemented in the last version of image processing toolbox that is brilliant! And for the rescalig I threated the volume as a group of slice using imresize. In this way I reduced the computational time of 100 about times

Más respuestas (1)

Deepak Bhatia
Deepak Bhatia el 3 de Mzo. de 2017
Looking at the nested loop structure, I recommend looking into vectorization in MATLAB as it might reduce code execution time.

Categorías

Más información sobre Biomedical Imaging en Help Center y File Exchange.

Productos

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by