Drexel dragonThe Math ForumDonate to the Math Forum



Search All of the Math Forum:

Views expressed in these public forums are not endorsed by Drexel University or The Math Forum.


Math Forum » Discussions » Software » comp.soft-sys.matlab

Topic: Speedup Help
Replies: 8   Last Post: Jul 28, 2014 7:56 AM

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View   Messages: [ Previous | Next ]
Matt

Posts: 23
Registered: 8/13/09
Speedup Help
Posted: Jul 23, 2014 3:59 PM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

Hi, All --

I am cycling through some geometry in 3D space and writing images that are essentially slices from the volume. The image generation routine is shown below. As you can see, it has several for loops and is quite slow. Any suggestions on speeding this thing up?

for oo = 1:Height
I = zeros(Depth,Width,'int8');
for jj = 1:r
rad = M(jj,4);
if abs(oo-(Height-M(jj,3))) < rad
front = ceil(Depth - M(jj,1) + rad);
back = floor(Depth - M(jj,1) - rad)+1;
left = floor(M(jj,2) - rad)+1;
right = ceil(M(jj,2) + rad);
for nn = back:front
for kk = left:right
if ((kk - M(jj,2))^2+(nn-(Depth-M(jj,1)))^2+ ...
(oo-(Height-M(jj,3)))^2)<=rad^2
I(nn,kk) = 1;
end
end
end
end
end
imwrite(logical(I),['data' num2str(oo,'%04d') 'r.tif']);
['File number ',num2str(oo,'%04d'),' has been processed']
end

Thanks a bunch.

Matt



Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© Drexel University 1994-2014. All Rights Reserved.
The Math Forum is a research and educational enterprise of the Drexel University School of Education.