How to speed this up?

1 visualización (últimos 30 días)
Mario
Mario el 18 de Ag. de 2018
Comentada: Mario el 18 de Ag. de 2018
Hello,
I am trying to optimize (speed up) my code and I was wondering if someone can help me with this.
In my code I got used to using for loops (even though I know they are not computationally efficient), and a small part of my code is below which I want to address first:
subplot(1,3,2),imshow(CT (:,:,bri), []); % show image # 20 from CT dataset
hFH = imfreehand(); % Create a binary image ("mask") from the ROI object
%%code starts from here
binaryImage = hFH.createMask;
close ();
close all force
[sizex, sizey, sizez]= size(binaryImage);
for ir=1:Br_snimaka
blank = zeros(sizex,sizey,sizez);
for i=1:sizex
for j=1:sizey
for d=1:ir
blank(i,j,d)=binaryImage(i,j,1);
end
end
end
end
CT(~blank) = 0;
The input (CT) is a dataset of CT images which are passing through this code. And the idea is to draw one mask and then pass that mask (ROI area) to all other images.
Any suggestions on how to speed this up?
Thanks in advance!

Respuesta aceptada

Image Analyst
Image Analyst el 18 de Ag. de 2018
Try this instead of the for loop to do your masking:
binaryImage = hFH.createMask;
% Mask the image using bsxfun() function to multiply the mask by each channel individually.
CT = bsxfun(@times, CT, cast(binaryImage , 'like', CT));
  1 comentario
Mario
Mario el 18 de Ag. de 2018
This is awesome. Extremely fast, just what I was looking for. Thanks a lot Image Analyst.
I have more optimization issues that I will post in new posts. Thanks once again.

Iniciar sesión para comentar.

Más respuestas (0)

Community Treasure Hunt

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

Start Hunting!

Translated by