MATLAB: Somehow the code doesn’t work and I don’t know why

3-d skeletonbwlabelnImage Processing Toolboximdilatestrelwhile loop

I'm writing an algorithm to succesfully segment 3D images of roots in soil. I have to seperate the main root from the first order branches and so on. In order to do so I have made a skeleton, which I used to find the junctions between branches. I use these points as the centre of a growing logical sphere which I multiply with the original binary (tresholded) image. As soon as there are 2 objects in my image, the sphere needs to stop growing so I can segment the image.
I wrote this code to do this:
mid_point = {31,38,39};
number_of_objects = 1;
count = 1;
while(number_of_objects < 2)
volume = zeros(dimx,dimy,dimz);
volume(mid_point{:})=1;
B = imdilate(volume,strel('sphere', count) );
new_im = (g_thres.*abs(1-B));
[a number_of_objects] = bwlabeln(new_im);
count = count+1;
end
The dimensions are 100*100*80, however it will also be used on way bigger images (1000*1000*1000), so using a for loop isn't really an option I think.
When I run the code, after 30 minutes there are still no results and than I terminate it, since it isn't usefull if it is that slow. Can somebody please explain to me why this code doesn't work (or is at least very slow).
Thank you very much,
Charles

Best Answer

Worked it out myself.
sphere = zeros(dimx,dimy,dimz);
sphere(seed_point{:})=1;
B = bwdist(sphere) <= count;
I put this in a while loop which increased count at every iteration. This way the sphere would become bigger every iteration untill my criteria are met.
Related Question