6
\$\begingroup\$

I have a list of images in a folder where num denotes the index of image and I used num to run the iterations in a "for loop". The code is supposed to segment brain part from the brain CT images. Here is the link for region growing algorithm.

How do I increase the performance of my region-growing algorithm?

% CORD_XY(1),CORD_XY(2) is the seed point
% LEN Denotes the number of images in a folder 
% num is used to iterate in "for loop"
% "img" here is single image from the folder in DICOM format
for num= 1:LEN 
 img = dicomread(files(num,1).name);
 [row, col] = size(img);
 th = 20;
 diff = 10;
 J = regiongrowing(img, CORD_XY(1), CORD_XY(2), th);
 value1 = sum(sum(J > 0));
 if num > 10)
 th = 55;
 elseif num <= 10
 while diff < 0.2 * value1 && diff ~= 0 && th < 60
 value1 = sum(sum(J > 0));
 th = th + 10;
 J = regiongrowing(double(img), CORD_XY(1), CORD_XY(2), th);
 value2 = sum(sum(J > 0));
 diff = value2 - value1; 
 end
 end
end 
J = regiongrowing(img, CORD_XY(1), CORD_XY(2), th-10);
asked Feb 21, 2016 at 17:04
\$\endgroup\$
2
  • \$\begingroup\$ @Santosh how many iterations does this typically take until your convergence criteria are met? \$\endgroup\$ Commented Mar 7, 2016 at 19:42
  • \$\begingroup\$ It takes 4 to 5 iterations which i feel is very less. I am not using the above technique anymore and looking for alternatives. Thanks. \$\endgroup\$ Commented Mar 21, 2016 at 19:13

1 Answer 1

2
\$\begingroup\$

I don't have the Image Processing Toolbox, so I can't test your code, but I'll go through what I can.

Never do diff = 10; diff is a useful builtin function in Matlab, so using it as a variable name will cause the function to be useless. The same goes with max, sum, size and so on.

value1 = sum(sum(J > 0)); is a bit faster than value1 = sum(J(:)>0);, so with regards to performance you did the right thing. In my opinion however, sum(J(:)>0) is a bit cleaner, and it can also be scaled to more dimensions.

Instead of elseif N <= 10 you can simply do else, as they mean the same thing in this context.

If it takes 4-5 iterations pretty consistently, then maybe you can increase the initial value of th to e.g. th = 40. It will result in fewer iterations for most images, so a faster algorithm. You might benefit from guessing a good value, run the algorithm, if you don't hit convergence, jump to a lower value. This will perform better for most of the images, but will be slower for some. In total, it's likely faster.

answered Jul 13, 2016 at 10:14
\$\endgroup\$

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.