Optimizing nested for loops for image analysis
Show older comments
I am analyzing 4-dimensional images. The four dimensions are x and y for the resolution of the image, z for the depth of the image, and f for how many frames there are at each z (depth). I need to go through each z and sum all of the frames into one single frame. Right now, I am using nested for loops to go through each pixel of each image but this is very slow. Does anyone know how to optimize the code so that I can do this operation faster?
This is the code below:
Thank you!
clear all;
res = 1024;
frames = 20;
z = 15;
mkdir('SHG');
mkdir('TPEF');
% mkdir('Composite');
A = TIFFStack('freshex_6x_100mW_zstack_00001.tif', [], [1 z frames]);
% SHGstack = im2single(reshape(A(:,:,1,:,:), [res,res,z,frames]));
% TPFstack = im2single(reshape(A(:,:,2,:,:), [res,res,z,frames]));
%SHGstack = reshape(A(:,:,1,:,:), [res,res,z,frames]);
TPFstack = reshape(A(:,:,1,:,:), [res,res,z,frames]);
for i =1:res
for j = 1:res
for k = 1:z
%SHGsum(i,j,k) = sum(SHGstack(i,j,k,:));
%SHGmean(i,j,k) = mean(SHGstack(i,j,k,:));
TPFsum(i,j,k) = sum(TPFstack(i,j,k,:));
%TPFmean(i,j,k) = mean(TPFstack(i,j,k,:));
end
end
end
Answers (1)
KALYAN ACHARJYA
on 20 Jun 2019
TPFsum=sum(TPFstack(:,:,1:z,:));
Is this?
1 Comment
Akarsh Lal
on 20 Jun 2019
Categories
Find more on Video Formats and Interfaces 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!