コード例 #1
0
ファイル: LevelSet.cpp プロジェクト: buaaswf/Canny
ImageF drlse_edge(ImageF phi_0,ImageF g,float lambda,float mu,float alfa,float epsilon,int timestep, int iter,string sada,char * potentialFunction)
{
	ImageF phi=phi_0;

	for(int i=0;i<iter;i++)
	{
		phi=NeumannBoundCond(phi);
		ImageF *vx=new ImageF();
		ImageF *vy=new ImageF();
		(*vy)*(vx);
		ImageF *phi_x=new ImageF();
		ImageF *phi_y=new ImageF();
		*vx=gradientx(g);
		*vy=gradienty(g);
		*phi_x=gradientx(g);
		*phi_y=gradienty(g);
		ImageF *s=new ImageF();
		*s=ImageFSqrt( *vx, *vy);
		float smallNumber=1e-10;
		ImageF *Nx,*Ny;
		*Nx=*phi_x/(*s+smallNumber);
		*Ny=*phi_y/(*s+smallNumber);
		ImageF * curvature=new ImageF();
		*curvature=div(*Nx,*Ny);
		ImageF distRegTerm;
		if (strcmp(potentialFunction,"single-well"))
			/*
			compute distance regularization term in equation (13) 
			with the single-well potential p1.
			*/
			distRegTerm= 4*del2(phi)-*curvature;
		//printf("");

		else if (strcmp(potentialFunction,"double-well"))
		{
			distRegTerm=distReg_p2(phi);  // compute the distance regularization term in eqaution (13) with the double-well potential p2.

			printf("asda");

		}
		else printf("EEROR");

		//float eplsion=0.1;
		ImageF diracPhi=Dirac(phi,epsilon);
		ImageF areaTerm=diracPhi*g; 
		ImageF  *edgeTerm=new ImageF();
		*edgeTerm=diracPhi*(*vx**Nx+*vy**Ny) + diracPhi*g*(*curvature);
		//vx*vy;
		 phi=phi + timestep*(mu*distRegTerm + lambda**edgeTerm + alfa*areaTerm);
		return phi_0; 
	}
}
コード例 #2
0
ファイル: LevelSet.cpp プロジェクト: buaaswf/Canny
ImageF distReg_p2(ImageF phi)
{
	ImageF *phi_x=new ImageF();
	ImageF *phi_y=new ImageF();
	*phi_x=gradientx(phi);
	*phi_y=gradienty(phi);
	//ImageF s=ImageFSqrt(((*phi_x)*(*phi_x)) + ((*phi_y)*(*phi_y)));
	ImageF  s=ImageFSqrt(*phi_x,*phi_y);
	ImageF a=regFunction(s);
	ImageF b=regFunction(s);//此处的函数需该
	ImageF ps=

//ImageF b=(s>1);
}
コード例 #3
0
void CViGrA_Watershed::Segmentation(TImage_In &Input, TImage_Out &Output, double Scale, bool bEdges)
{
	typedef typename vigra::NumericTraits<typename TImage_In::value_type>::RealPromote	TmpType;

	vigra::BasicImage<TmpType>	gradientx	(Get_NX(), Get_NY());
	vigra::BasicImage<TmpType>	gradienty	(Get_NX(), Get_NY());
	vigra::FImage				gradientmag	(Get_NX(), Get_NY());
	vigra::IImage				labels		(Get_NX(), Get_NY());

	//-----------------------------------------------------
	// calculate the x- and y-components of the image gradient at given scale
	Process_Set_Text(_TL("calculate gradients"));

	recursiveFirstDerivativeX	(srcImageRange(Input)		, destImage(gradientx), Scale);
	recursiveSmoothY			(srcImageRange(gradientx)	, destImage(gradientx), Scale);

	recursiveFirstDerivativeY	(srcImageRange(Input)		, destImage(gradienty), Scale);
	recursiveSmoothX			(srcImageRange(gradienty)	, destImage(gradienty), Scale);

	//-----------------------------------------------------
	// transform components into gradient magnitude
	Process_Set_Text(_TL("calculate gradient magnitude"));

	combineTwoImages(
		srcImageRange(gradientx),
		srcImage(gradienty),
		destImage(gradientmag),
		GradientSquaredMagnitudeFunctor()
	);

	//-----------------------------------------------------
	// find the local minima of the gradient magnitude (might be larger than one pixel)
	Process_Set_Text(_TL("find local minima"));

	labels	= 0;

	extendedLocalMinima(srcImageRange(gradientmag), destImage(labels), 1);

	//-----------------------------------------------------
	// label the minima just found
	Process_Set_Text(_TL("label minima"));

	int max_region_label	= labelImageWithBackground(srcImageRange(labels), destImage(labels), false, 0);

	//-----------------------------------------------------
	// create a statistics functor for region growing
	vigra::ArrayOfRegionStatistics<vigra::SeedRgDirectValueFunctor<float> >gradstat(max_region_label);

	//-----------------------------------------------------
	// perform region growing, starting from the minima of the gradient magnitude;
	// as the feature (first input) image contains the gradient magnitude,
	// this calculates the catchment basin of each minimum
	Process_Set_Text(_TL("perform region growing"));

	seededRegionGrowing(srcImageRange(gradientmag), srcImage(labels), destImage(labels), gradstat);

	//-----------------------------------------------------
	// initialize a functor to determine the average gray-value or color for each region (catchment basin) just found
	vigra::ArrayOfRegionStatistics<vigra::FindAverage<TmpType> >averages(max_region_label);

	//-----------------------------------------------------
	// calculate the averages
	Process_Set_Text(_TL("calculate averages"));

	inspectTwoImages(srcImageRange(Input), srcImage(labels), averages);

	//-----------------------------------------------------
	// write the averages into the destination image (the functor 'averages' acts as a look-up table)
	transformImage(srcImageRange(labels), destImage(Output), averages);

	//-----------------------------------------------------
	// mark the watersheds (region boundaries) black
	if( bEdges )
	{
		regionImageToEdgeImage(srcImageRange(labels), destImage(Output), vigra::NumericTraits<typename TImage_Out::value_type>::zero());
	}
}