Sinsonglew Source: Http://www.cnblogs.com/sinsonglew Welcome reprint, Please also keep this statement. Thanks:)
1. Principle of Regional growth algorithm
Reference: wiki entry area growth algorithm;
From seed point seed, traverse the 4 neighborhood of the seed, and if a neighborhood pixel conforms to the threshold setting, it is scaled as a growth point and inserted into the seed queue as a new growth seed, and the old seed is removed until the seeded column is empty, and the pixel space (a picture) is split. As shown, the red lattice is the initial seed;
2. Example of Regional growth
3. Code implementation
Note: Development language for IDL,ENVI 4.8 version of the own development language
Regional Growth algorithm class file Regiongrow__define.pro
1FUNCTION Regiongrow::init, Region=region, seeds=seeds2 3Self._region= Ptr_new (/allocate_heap);4* (self._region) =Region ;5 6dims = size (region,/DIMENSIONS);7Self._width= dims[0];8Self._height= dims[1];9 TenSelf._ifront=0L; OneSelf._iback=n_elements (seeds); ASelf._seeds= Ptr_new (/allocate_heap); -* (self._seeds) = Make_array (self._width* Self._height,/long, value=0); -(* (self._seeds) [Indgen (self._iback)] =seeds; the -Self._hseeds= HASH (seeds, make_array (self)._iback,/byte, value=0)); - -RETURN,1 + - END + A PRO regiongrow::setthreshold, mint, Maxt atSelf._mint=Mint; -Self._maxt=Maxt; - END - - FUNCTION regiongrow::isgrowable, Value -RETURN, (self._mintLe value && value le self._maxt) in END - to FUNCTION regiongrow::hasseeds +RETURN, (self._ifrontLT self._iback); - END the * FUNCTION regiongrow::isnotseed, index $RETURN, (self._hseeds). Haskey (Index) EQ0);Panax Notoginseng END - the FUNCTION regiongrow::p opseed +Seed = (* (self._seeds)) [Self._ifront]; ASelf._ifront= self._ifront+1; the RETURN, seed; + END - $ PRO regiongrow::p ushseed, Index $(self.)_hseeds) [Index] =0; -(* (self._seeds)) [Self._iback] =index; -Self._iback= self._iback+1; the END - Wuyi FUNCTION Regiongrow::grow the -Growimg = Make_array (self._width, self._height,/byte, value=0); WuK =0; -while (self->hasseeds ()) Do BEGIN AboutK = +1; $;Print,"==========================>", K; -Seed = self->popseed (); -i = Floor (seed/self._width); -j = seed-i * self._width; AGrowimg[j,i] =255; + the ;;;;; Left -index = seed-1; $IF (J-1GE0) && (Self->isnotseed (index)) && self->isgrowable ((* (self)._region)) [J-1, I]) Then BEGIN theSelf->pushseed, index; the ENDIF the the ;;;;; Right -index = seed +1; inIF ((j+1) LT self._width) && (Self->isnotseed (index)) && self->isgrowable ((* (self)._region)) [j+1, I]) Then BEGIN theSelf->pushseed, index; the ENDIF About the ;;;;; up theindex = seed + self._width; theIF ((i+1) LT self._height) && (Self->isnotseed (index)) && self->isgrowable ((* (self)._region)) [j,i+1] then BEGIN +Self->pushseed, index; - ENDIF the Bayi ;;;;;D OWN theindex = seed-self._width; theIF ((I-1) GE0) && (Self->isnotseed (index)) && self->isgrowable ((* (self)._region)) [j,i-1] then BEGIN -Self->pushseed, index; - ENDIF the the Endwhile the the RETURN, Growimg - the END the the PRO Regiongrow::cleanup94 the* (self._region) = ! NULL; the thePtr_free, self._seeds;98 AboutDelvar, self._seeds; -Delvar, self._hseeds;101 102 RETURN103 END104 the PRO Regiongrow__define106 107struct = {Regiongrow,_region:P tr_new (),_seeds:P tr_new (),_hseeds: HASH (),_ifront:0L,_iback:0L,_width:0L,_height:0L,_mint:0,_maxt:0}108 RETURN109END
Regional Growth test main function file Region.pro
1 PRO Region2Grayimg = Read_tiff ('D:\ndvi.tif');3 ; help, Grayimg .4Seeds = WHERE (grayimg EQ221);5 6Executer = Obj_new ("Regiongrow", Region=grayimg, seeds=seeds);7Executer.setthreshold,186, the;8St = SYSTIME (1);9result =Executer.grow ();TenET = SYSTIME (1); One Help , result; A Print,"=====================>time:", (et-St); -; im =IMAGE (result); - theGR = Make_array (3,2048,1024x768,/byte, value=0); -Fr0, *,*] = result[*,*]; -Fr1, *,*] = result[*,*]; -Fr2, *,*] = result[*,*]; +Write_jpeg,"grow.jpg", GR,/TRUE -END
The results of the split water test are as follows:
Image segmentation-Region growth algorithm and IDL implementation