Code covered by the BSD License  

Highlights from
Fast 3D/2D Region Growing (MEX)

4.8 | 5 ratings Rate this file 142 Downloads (last 30 days) File Size: 5.9 KB File ID: #41666 Version: 1.4
image thumbnail

Fast 3D/2D Region Growing (MEX)



06 May 2013 (Updated )

A very fast 2D and 3D region growing algorithm implemented in c++.

| Watch this File

File Information

Native Matlab implementations of region growing algorithms are usually quite slow, especially for 3D input data. This submission is a mex implementation of a 3D/2D region growing algorithm. The region growing process is further accellereated by using priority queues for the neighbourhood pixels.
Example usage (requires image processing toolbox):
>> load mri
>> RegionGrowing(squeeze(D), 10);
This syntax opens a GUI for the selection of the seed point and visualizes the output. Fur further syntaxes see the header of the RegionGrowing.m file.

Required Products Image Processing Toolbox
MATLAB release MATLAB 8.2 (R2013b)
MATLAB Search Path
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (16)
01 Apr 2015 Christian Wuerslin

You're absolutely right. I fixed it. Thanks!

Comment only
20 Mar 2015 ganesan

line 250 : if (lLinInd < 0) return; forgets to clear aqQueue and pbCandidate before exiting

Comment only
12 Mar 2015 Christian Wuerslin

Hi Jonas,

thanks for the advice, I uploaded a fixed version!


Comment only
11 Mar 2015 Jonas Zimmermann

There is another memory leak: aqQueue does not get deallocated. Adding the following line to the main function (after the while block) should fix this issue:

delete[] aqQueue;

Comment only
07 Mar 2015 Jonas Zimmermann

Actually, to correct my own suggestion: pbCandidate should be initialized with
pbCandidate = new bool [lNX * lNY * lNZ]();

(otherwise it contains random values)

Comment only
26 Feb 2015 Jonas Zimmermann

Hi Christian,
Thanks for this nice implementation. However, there's a memory leak, because pbCandidate (or rather the data it points to) never gets deallocated.
How about allocating it with
pbCandidate = new bool [lNX * lNY * lNZ];
and deleting it after while block:
delete[] pbCandidate;

23 Oct 2014 Christian Wuerslin


nothing. In your case, just pass the gradient magnitude image to the region growing instead of the image. Something like:

[dX, dY] = gradient(image);
gradmag = sqrt(dX.^2 + dY.^2);
mask = RegionGrowing(gradmag, threshold, seed);

Cheers, Christian

Comment only
23 Oct 2014 TAY

TAY (view profile)

hi, may i know which part of the code shall i modify so that the seed growing is depend on the gradient magnitude of the image.

Comment only
26 Sep 2014 Felix

Felix (view profile)

Excellent submission!
However I added an input test to prevent my Matlab from crashing in case of homogeneous input:

if isscalar(unique(dImg(:))), error('All values inside dImg are equal!'); end

29 Jul 2014 Christian Wuerslin

Hola Joao,

you need to set up the mex compiler by typing
>> mex -setup
and then chose one of the shown options (you should at least have the lcc compiler). Then try to run the region growing again.


Comment only
05 Jul 2014 João Ribeiro

Hi Christian!
I got this error! Can you help me?! Thank you very much. :)

Trying to compile mex file...Error: Could not detect a compiler on local system
which can compile the specified input file(s)
Error using RegionGrowing (line 67)
Could not compile the mex file :(. Please try to do so manually!

Comment only
28 Apr 2014 syed umar

When I pressed run, i got this error :Please define one of the current images
Please tell me how to solve this as I am a bit new to matlab. Please help. Thank you.

Comment only
05 Mar 2014 Michael Völker

This is well done!

I have a minor suggestion for the visualization of the result (nargout == 0). For large No. of slices in a 3D data set, the output of montage() is very hard to grasp. My suggestion is to present only image slices that are part of the segmented volume:

Below line 89, add
% reduce montage size by selecting the interesting slices, only
slices = squeeze( sum(sum( dMask(:,:,1,:) ,1),2) > 0 );

And change line 90 to:
figure, montage(dImg(:,:,:,slices));

02 Dec 2013 Maxim

Maxim (view profile)

24 May 2013 Christian Wuerslin

Hi Chris,

actually there is nothing really new in this algorithm. I only decided to trade a little bit of accuracy for a lot of speed. This is done by using the differen queues which can be regarded as intensity difference bins. I saw a similar approach in a paper by Johan Berglund (2010 in "Magn Reson Imaging") in a slightly differen context, however, I do not know whether he came up with it himself.


Comment only
23 May 2013 Chris Walker

Nice work Christian. Did you develop the algorithm yourself? Will it appear as a published article?
Chris W

13 May 2013 1.1

Minor bugfix, corrected documentation errors.

19 Mar 2014 1.2

Added changes requested (and kindly supplied) by Michael

12 Mar 2015 1.3

Closed memory leaks. Thanks Jonas!

01 Apr 2015 1.4

Fixed another leak.

Contact us