Code covered by the BSD License  

Highlights from
Region Growing (2D/3D grayscale)

5.0 | 11 ratings Rate this file 301 Downloads (last 30 days) File Size: 289 KB File ID: #32532 Version: 1.5
image thumbnail

Region Growing (2D/3D grayscale)


Daniel (view profile)


14 Aug 2011 (Updated )

Recursive region growing algorithm for 2D/3D grayscale images with polygon and binary mask output

| Watch this File

File Information

A recursive region growing algorithm for 2D and 3D grayscale image sets with polygon and binary mask output. The main purpose of this function lies on clean and highly documented code.

[P, J] = regionGrowing(cIM, initPos, thresVal, maxDist, tfMean, tfFillHoles, tfSimplify)

- cIM: 2D/3D grayscale matrix
- initPos: Coordinates for initial seed position
- thresVal: Absolute threshold level to be included
- maxDist: Maximum distance to the initial position in [px]
- tfMean: Updates the initial value to the region mean (slow)
- tfFillHoles: Fills enclosed holes in the binary mask
- tfSimplify: Reduces the number of vertices with line simplification

- P: VxN array (with V number of vertices, N number of dimensions). P is the enclosing polygon for all associated pixel/voxel
- J: Binary mask (with the same size as the input image) indicating 1 (true) for associated pixel/voxel and 0 (false) for being outside


Region Growing and Line Simplification inspired this file.

Required Products Image Processing Toolbox
MATLAB release MATLAB 7.12 (R2011a)
Other requirements Optional: Line Simplifcation by Wolfgang Schwanghart
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (25)
04 Nov 2015 Nassir H. Salman

a lot of thanks Mr Daniel
, the algorithm of 2D/3D gray scale image is excellent , i tried it , it works correctly for segmentation, boundary, no. of pixel...but i tried to display the segmented area only with white background, there is some problem .so could you pls help me to do that.
thank u, Nassir

Comment only
04 Nov 2015 Nassir H. Salman

Matlab is great software and thanks to Mathworks

Comment only
08 Jun 2015 jack nn

hi thanks.
I want to test this code.
I use this:
>> th = 0.35 * max(max(I));
>> [P, J] = regionGrowing(I, [30,50], th, 300, 'true', 'true', 'false');

but the result is this message:

RegionGrowing Opening: Initial position (30|50|1) with 0 as initial pixel value!
RegionGrowing Ending: Found 10390 pixels within the threshold range (418 polygon vertices)!

can you help me? Is there any mistake?

Comment only
20 Oct 2014 Lena Veis

Nice work..

26 Sep 2014 Ander Biguri  
01 Dec 2013 adi

adi (view profile)

Hi, I tried to run the code and the segmentation I get is in a circle shape and not exactly the shape of the segment.
Is this the way the code works? because according the picture it looks like a free shape

Comment only
10 May 2013 Daniel

Daniel (view profile)

Please contact me via 'braggpeaks|a|', since my deposited address is expired. Thanks, Daniel.

Comment only
25 Mar 2013 Isabel

Isabel (view profile)

10 Jan 2013 gang

gang (view profile)

thks very much good job!

05 Dec 2012 Hanbo Chen  
03 Aug 2012 Yang

Yang (view profile)

13 May 2012 Omer Demirkaya

The following two statements should be replaced.
sumSQR = meanI*meanI; % sum of squares

stdI = sqrt((sumSQR - N*meanI*meanI)/(N-1)); % update standard deviation

Comment only
13 May 2012 Omer Demirkaya

Daniel good work.
I have a suggestion about an efficient mean and standard deviation calculations within your while loop.

Here is the inintilization of the parameters outside the loop.

meanI = regVal; % Mean intensity
sumSQR = 0; % sum of squares
stdI = 0; % Standard deviation
N = 1; % number of pixels

And then within your while loop after the statement,

J(xv+i, yv+j, zv+k) = true;

one can add the following lines of code to progessively calculate mean and standard deviation
gI = cIM(xv+i, yv+j, zv+k);
sumSQR = sumSQR + gI*gI;
meanI = (N*meanI + gI)/(N+1); % update mean
N = N+1; % increment number of pixels
stdI = (sumSQR - N*meanI*meanI)/(N-1); % update standard deviation


Comment only
04 May 2012 Daniel

Daniel (view profile)

Hello Michael. Unfortunately, that's true. I think the easiest way is to give over a handle to the desired axis as an additional input argument.

Comment only
04 May 2012 Michael

Hey Daniel, running the 2d example with no initial seed produces an error if multiple figures are open, because get(himage,'XData') returns a cell array, and is then used in axes2pix() which accepts only numerical arrays. I'm not sure of the best way to deal with this, aside from including a 'close all' in the code.

Comment only
03 Apr 2012 maram

maram (view profile)

i want to segment a mammographic image(from mias database. after choosing the seed the result is like a curve!

Comment only
02 Apr 2012 Daniel

Daniel (view profile)

Hello moram, could you please provide some further informations (e.g. what exactly are you trying to do)?

Comment only
02 Apr 2012 maram

maram (view profile)

it works very well with the example associated!!but once i tried on another image i failed!

03 Mar 2012 Daniel

Daniel (view profile)

The selection of a seeding position currently works only for 2D input images, since the function does not know, in which slice you may set the initial point. One (easy) way is to check whether the input image is 3D and show up the medial (or a random) slice.

Comment only
27 Feb 2012 Gomathi C

when i try this code for a 3d image setting the initpos value as [] while calling, it gets the input seed point from me. But, unfortunately I get the following error.

??? Attempted to access initPos(3); index out of bounds because

Kindly help me to figure out what I have to do to make the program run.

Comment only
01 Dec 2011 Ramachandran M.G.

good work

01 Dec 2011 Ramachandran M.G.  
19 Nov 2011 Daniel

Daniel (view profile)

Hello marwa. I'm sorry, i am not sure what you mean with "the same characteristics". Do you mean within the same intensity-range? You are welcome to contact me via mail. With regards, Daniel

Comment only
17 Nov 2011 marwa hadhoud

this is a good work, but i need to ask you, if there is a possibility to make this code search on all the image about all the separated regions in the image that have the same charactristics.

29 Aug 2011 Jerod Rasmussen

This is great! Worked intuitively right out of the box! Could use an academic reference if available.

15 Aug 2011 1.5

some cosmetic changes, attached example.mat

Contact us