Optimizing nested for loops for image analysis

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

回答 (1 件)

KALYAN ACHARJYA
KALYAN ACHARJYA 2019 年 6 月 20 日

0 投票

TPFsum=sum(TPFstack(:,:,1:z,:));
Is this?

1 件のコメント

Akarsh Lal
Akarsh Lal 2019 年 6 月 20 日
I think I didn't phrase my question correctly...what I'm trying to do is at each depth (z), I am trying to add up all of the frames that are there. So for example, at z = 3 there are 15 frames. It's almost like there is a video at each depth and I need to add up each frame of that video at each depth. I hope that clarifies what my goal is.
Thank you for your response!

サインインしてコメントする。

製品

質問済み:

2019 年 6 月 20 日

コメント済み:

2019 年 6 月 20 日

Community Treasure Hunt

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

Start Hunting!

Translated by