필터 지우기
필터 지우기

Speed up convolution and supersampling in 3D binary matrix

조회 수: 3 (최근 30일)
Emanuele Gandola
Emanuele Gandola 2017년 3월 1일
답변: Emanuele Gandola 2017년 3월 10일
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.

채택된 답변

Emanuele Gandola
Emanuele Gandola 2017년 3월 10일
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

추가 답변 (1개)

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

카테고리

Help CenterFile Exchange에서 Biomedical Imaging에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by