File Exchange

image thumbnail

Region Growing

version 1.0 (54.7 KB) by

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

46 Ratings



View License

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

Comments and Ratings (81)

sahai james

how can i run this program

Taein Jeon


Sangita Pal

itz helpful..

ignatious vs

thanks for the explanation

Trista Chao

works well

help me to extract particular area of an image in automatic

it works well


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));


iza (view profile)

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

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.

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


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!

where can i get description for this code??

asia malik

good job...thanks


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?


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


yes i can help you mr wasim...

wasim akhtar

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

Aldo Zaimi

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?


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 ?


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 ?

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;


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

Excellent algorithm; thank you!


Simple program, easy to use on medical images.

bo xia

bo xia (view profile)

hi thanks want details

??? 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

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?


want details

Luke Xie

Luke Xie (view profile)

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


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)


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?

guys can u share the correct code?


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


Gaurav Mittal

Worked like charm, thanks for providing this code.


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 !


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.


lin (view profile)

well good!

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 !


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


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!

Mauro A

Can you give me some example parameters?

Deonne C

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


ding (view profile)

Thank you


Gene (view profile)

i cant download d me!!!


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...

Sivan Ran

How can I make it work for 3D images?

Thank you

fsdm fsdm


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.


saif (view profile)

thank you

Xin He

Xin He (view profile)

very helpful thanks!


very helpful!Thank you very much!!!

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

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

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?


can somebody explain how to segment a carotid artery ?

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!

Thank you a lot!


Jess (view profile)

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


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!

anoop R

Very useful piece of code.


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?

jack lumber

siti 85

cannot download.. why?

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.


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.

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

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.

Ida Haggstrom

rasool shaik


ryan hartadi

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

Paolo L

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

Zonglei Zhen

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

Roberto Mantia

It does what it should do. Very good !

balamurugan samy


jichao zhao

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

Xin Liu

It's very helpful. Thanks!

MATLAB Release
MATLAB 7.5 (R2007b)

Inspired: Region Growing (2D/3D grayscale)

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

» Watch video