View License

Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.

» Watch video

Highlights from
Region Growing

4.4 | 45 ratings Rate this file 323 Downloads (last 30 days) File Size: 54.7 KB File ID: #19084 Version: 1.0
image thumbnail

Region Growing


Dirk-Jan Kroon (view profile)


06 Mar 2008 (Updated )

Segmentation by growing a region from seed point using intensity mean measure

| Watch this File

File Information

Simple but effective example of "Region Growing" from a single seed point.

The region is iteratively grown by comparing all unallocated neighbouring pixels to the region. The difference between a pixel's intensity value and the region's mean, is used as a measure of similarity. The pixel with the smallest difference measured this way is allocated to the region.

This process stops when the intensity difference between region mean and new pixel becomes larger than a certain treshold


This file inspired Region Growing (2 D/3 D Grayscale).

MATLAB release MATLAB 7.5 (R2007b)
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (78)
01 Feb 2017 ignatious vs

thanks for the explanation

17 Jan 2017 Trista Chao

works well

06 Sep 2016 vasanthselvakumar R

help me to extract particular area of an image in automatic

Comment only
08 Aug 2016 Chada Keatmanee

it works well

21 Jul 2016 Mary

Mary (view profile)

Hi can any one help please ?
i tried this code and i get the following error:
Not enough input arguments.

Error in regiongrowing (line 29)
if(exist('y','var')==0), figure, imshow(I,[]); [y,x]=getpts; y=round(y(1)); x=round(x(1));

Comment only
06 Jul 2016 Iago Batista Oliveira

19 Jun 2016 iza

iza (view profile)

how to make one of the seed automatically grow in interested region?..anyone know?

Comment only

how to solve this.. help me,...Maximum recursion limit of 500 reached. Use set(0,'RecursionLimit',N) to change the limit. Be
aware that exceeding your available stack space can crash MATLAB and/or your computer.

30 Apr 2016 bushra mughal

while using this code [x,y] =getpts(fig)or [y,x] =getpts(fig)does not work plz help me how to calculate x and y value

Comment only
17 Mar 2016 hdchina2010

Thanks for the great work, but there exists a small bug in this code, Matlab uses horizontal axis (towards right) as X direction and vertical axis (towards bottom) as Y, and we get seem from Matlab document, [x, y] = getpts(fig), not [y,x] = getpts(fig) you wrote in the code, which could be quite misleading and take me hours to figure it out!

16 Mar 2016 Navneet Multani

where can i get description for this code??

Comment only
04 Mar 2016 asia malik

good job...thanks

08 Feb 2016 RahulDate

While using the code with given sample code and example (Line 21), I encountered following error:
Maximum recursion limit of 700 reached. Use set(0,'RecursionLimit',N) to change the limit. Be aware that exceeding
your available stack space can crash MATLAB and/or your computer.

Error in ismember>ismemberBuiltinTypes

Can anyone help me with it?


Comment only
01 Feb 2016 charuleelaa vanilavarasu

Can someone tell me how to run this code?
I keep getting an error.(Extremely new to matlab)

Comment only

yes i can help you mr wasim...

Comment only
17 Jan 2016 wasim akhtar

i am doing project on touchless fingerprint detection, can anybody help me with the region growing matlab code

Comment only
04 Jan 2016 ramesh thangaraj

03 Dec 2015 Aldo Zaimi

25 Nov 2015 ellen ellen

hi All
i run this code, but i face following Error:

??? Input argument "I" is undefined.

Error in ==> regiongrowing at 29
if(exist('y','var')==0), figure, imshow(I,[]); [y,x]=getpts;
y=round(y(1)); x=round(x(1)); end

does anyone khow how can i solve this?

Comment only
28 Jul 2015 Mohamed

Mohamed (view profile)

The measure of similarity is the difference between a pixel's intensity value and the region's mean currently being processed, so it is relative. Does this kind of region growing algorithm has a name ? like progressive or adaptive ? or this is just a different similarity measure ?

26 Apr 2015 sally

sally (view profile)

i have a grey scale lung CT image which ranges between 0-256 with regions of the values : 0 , 52 , then values > 90 which i want to segment .. i give the threshold value = 75 but still the resultant mask includes all the image, not the inner part with values > 75 only ..
what's wrong here ?

Comment only
30 Jan 2015 ABIN joy

??Attempted to access neg_list(0,:); index must be a positive integer or logical.

Error in ==> regiongrowing at 80
neg_list(index,:)=neg_list(neg_pos,:); neg_pos=neg_pos-1;

Comment only
24 Oct 2014 Maziyar

Very nice job.
Can anyone let me know how can we change color of region?

07 Oct 2014 Michael Skocik

Excellent algorithm; thank you!

11 Jul 2014 DENNIS Dietz

Simple program, easy to use on medical images.

20 Jun 2014 bo xia

bo xia (view profile)

hi thanks want details

25 May 2014 Mohammed ashraf

??? Subscript indices must either be real positive integers or logicals.

Error in ==> regiongrowing at 34
reg_mean = I(x,y); % The mean of the segmented region

how could this problem be solved please response ASAP

28 Apr 2014 syed umar

I am getting an error: "Not enough input arguments" Please help me how to solve the problem, Please tell me How to pass input arguments?

12 Mar 2014 NITHYA V R

want details

01 Mar 2014 Luke Xie

Luke Xie (view profile)

Thanks for the function. Good code to have in your image processing toolbox.

28 Nov 2013 adi

adi (view profile)

In order to avoid this error, you have to convert your image to type of double by:
I=im2double(I); (I is the image)

Comment only
27 Nov 2013 Sandy

Sandy (view profile)

??? Error using ==> minus
Class of operand is not supported.

Error in ==> regiongrowing at 69
dist = abs(neg_list(1:neg_pos,3)-reg_mean);

How could this problem be solved?

Comment only
18 Nov 2013 Fitroh Amaluddin

guys can u share the correct code?

Comment only
11 Oct 2013 Ana Djuricic


if someone knows example for region growing using multiple seed points, please share! Thank you!


30 Aug 2013 Gaurav Mittal

Worked like charm, thanks for providing this code.

16 Aug 2013 Francesco

Hi... I found an error executing this code. The details of error are follows:

Error using -
Integers can only be combined with integers of the same class, or scalar doubles.

Error in regiongrowing (line 69)
dist = abs(neg_list(1:neg_pos,3)-reg_mean);

Thanks !

Comment only
08 May 2013 Preeti

Preeti (view profile)

kindly reply to my question. I have sent u many mails that this code is not working fine for me as i am getting a white image only. I need the ROI which i selected with seed point. Please reply.

Comment only
23 Apr 2013 lin

lin (view profile)

well good!

21 Mar 2013 Rajesh Gothwal

Hi... I have found an error when i am executing this code. The details of error are follows:

??? Error using ==> minus
Integers can only be combined with integers of the same class, or
scalar doubles.
dist = abs(neg_list(1:neg_pos,3)-reg_mean);
Thanks !

Comment only
18 Aug 2012 nayana

nayana (view profile)

i should say that this is very helpful for beginners like me, but i have a doubt, on what basis can we determine the value to reg_max distance
if we choose to segment a particular region

09 Aug 2012 Preeti

Preeti (view profile)

I have tried the code on image size 512*512. after providing the x and y values, i get J of same size 512*512 with all white image. No segmentation has been done. Please suggest!

Comment only
05 Jun 2012 Mauro A

Can you give me some example parameters?

Comment only
29 May 2012 Deonne C

I can't download the file as well. Some one please help?

Comment only
17 Apr 2012 ding

ding (view profile)

Thank you

22 Mar 2012 Gene

Gene (view profile)

13 Mar 2012 aspirin crocin

i cant download d me!!!

30 Dec 2011 Deepak

Deepak (view profile)

Thq Dirk-Jan Kroon for such short code.I am working dicom image.I convert it into JPG.i have a problem over run time.

??? Undefined function or method 'regiongrowing' for input
arguments of type 'double'.

I even defined im2double() fnc.but i got an error...

Comment only
17 Dec 2011 Sivan Ran

How can I make it work for 3D images?

Thank you

Comment only
22 Nov 2011 fsdm fsdm

21 Nov 2011 kalarmago

What are x and y, I believe image(x,y) coordinate, but when I tested other x,y values (eg, x=308,y=244, I(x,y)=0.73) then the segmented result image is not desired.

Comment only
17 Oct 2011 saif

saif (view profile)

thank you

Comment only
12 Oct 2011 Xin He

Xin He (view profile)

very helpful thanks!

Comment only
26 Sep 2011 michiko

very helpful!Thank you very much!!!

29 May 2011 paramveer sran

i have downloaded this piece o code but when i tried to run on the same image i.e medtest.png i got the following error. could you plz tell me where is the problem and how to solve this
>> regiongrowing
??? Maximum recursion limit of 500 reached. Use set(0,'RecursionLimit',N)
to change the limit. Be aware that exceeding your available stack space can
crash MATLAB and/or your computer.

Error in ==> isstruct at 99

Comment only
30 Mar 2011 myriam robert

I change reg_maxdist to 10 and it's ok.
Does anybody have find how use the region growing for 3D matrix ?
thank you

Comment only
30 Mar 2011 myriam robert

I have a MRI coup from a 3D data matrix "Y" so it's Y( : , : , 14) .
the algorithm doesn't work on this coup. In the result I have only one white pixel ( the seedpoint).
I change the line 70 but it doesn't change anything.
can you help me please?

Comment only
07 Jan 2011 Aravind

can somebody explain how to segment a carotid artery ?

Comment only
05 Dec 2010 Hank Will

This looks pretty cool! But I wonder processing larger images with this routine (e.g. satellite data). Any suggestions? In my case I don't get any error, but processing a 10 Bit panchromatic imagery subset of just 15 Mb leads to no valuable results.
Would highly appreciate any thoughts about workflows for matlab for this purpose!

23 Nov 2010 Esther Kneepkens

Thank you a lot!

23 Jun 2010 Jess

Jess (view profile)

No need to change line 70 if use im2double with imread as given in the example (line 21 - comment section)

08 Jun 2010 Natarajan

code works except as Ron did . got to change the line 70.

However the i didn't get a segmented/thresholded output for 16 bit grey scale! Thanks

Would be great if someone could give an idea of whats the issue!

03 Feb 2010 anoop R

Very useful piece of code.

12 Dec 2009 taccini

Hello All,
first i want to thank Dirk about his work and all the matlab community because there are very helpful for me.
well i need to use the region growing for 3D matrix.
this code could be adapted or any one have some idea?

23 Sep 2009 jack lumber

31 Mar 2009 siti 85

cannot download.. why?

Comment only
21 Mar 2009 Torres Chhetri

its was a great help, would you like to extend your for taking random seed pixels for a colorful image. if u do that, it would be so great.

25 Feb 2009 Jag

Jag (view profile)

thanks, seems like a handy piece of code.
On R2008b I had to change line 70 to

dist = abs(neg_list(1:neg_pos,3)-double(reg_mean));

to get it to run with the sample image.

Comment only
20 Feb 2009 ucd puri

Hi, I figured out what was the problem, my data set was in int16 format so, it was eaisy to make amendments, but i am not sure if my region is segmented correctly. Regards tanuj

Comment only
06 Feb 2009 ucd puri

Hi All, This is an excellent piece of code. I am just an intermediate matlab programmer and have a couple of questions on this code.
(1) It works perect on normal images. But i have a dicom int16 medical image, when i give it as an input, i get an output image with only one pixel (the seed pixel that i selected) . I changes the code a little bit for example instad of imread, i used dicomread, and in place of imshow(I,[]) i used imshow(I,'displayRange',[]).
(2) the file explaination reads '"This process stops when the intensity difference between region mean and
new pixel become larger than a certain treshold (t)" but this t is 0.2 which you have defined in the file, what if i want to use an grey intensity level of say 600 as threshold. As my image is int16 dicom, it has 2^16 , so it grey sclae ranges from -32768 to + 32768.
thanks a lot for help in advance.

22 Jan 2009 Ida Haggstrom

19 Dec 2008 rasool shaik


01 Aug 2008 ryan hartadi

it works very good, so simple. need to de developed in other area

31 Jul 2008 Paolo L

very good, simple to read, simple to understand, it works fine for a start, useful for student exercises

18 May 2008 Zonglei Zhen

region growing is a very useful method for sgementation. This program is a good start of it.

22 Apr 2008 Roberto Mantia

It does what it should do. Very good !

17 Apr 2008 balamurugan samy


08 Apr 2008 jichao zhao

That is excellent one. I am wondering whether you can extend your work to colorful graph, not just gray scale.

26 Mar 2008 Xin Liu

It's very helpful. Thanks!

Contact us