Ejemplo n.º 1
0
/*
 * Smooths, thresholds and finds the worms contour.
 * The original image must already be loaded into Worm.ImgOrig
 * The Smoothed image is deposited into Worm.ImgSmooth
 * The thresholded image is deposited into Worm.ImgThresh
 * The Boundary is placed in Worm.Boundary
 *
 */
void FindWormBoundary(WormAnalysisData* Worm, WormAnalysisParam* Params){
	/** This function currently takes around 5-7 ms **/
	/**
	 * Before I forget.. plan to make this faster by:
	 *  a) using region of interest
	 *  b) decimating to make it smaller (maybe?)
	 *  c) resize
	 *  d) not using CV_GAUSSIAN for smoothing
	 */
	TICTOC::timer().tic("cvSmooth");
	cvSmooth(Worm->ImgOrig,Worm->ImgSmooth,CV_GAUSSIAN,Params->GaussSize*2+1);
	//cvSmooth(Worm->ImgOrig,Worm->ImgSmooth,CV_MEDIAN,Params->GaussSize*2+1);
	//cvSmooth(Worm->ImgOrig,Worm->ImgSmooth,CV_BLUR,Params->GaussSize*2+1,Params->GaussSize*2+1);
	TICTOC::timer().toc("cvSmooth");
	TICTOC::timer().tic("cvThreshold");
	cvThreshold(Worm->ImgSmooth,Worm->ImgThresh,Params->BinThresh,255,CV_THRESH_BINARY );
	TICTOC::timer().toc("cvThreshold");
	CvSeq* contours;
	IplImage* TempImage=cvCreateImage(cvGetSize(Worm->ImgThresh),IPL_DEPTH_8U,1);
	cvCopy(Worm->ImgThresh,TempImage);
	TICTOC::timer().tic("cvFindContours");
	cvFindContours(TempImage,Worm->MemStorage, &contours,sizeof(CvContour),CV_RETR_EXTERNAL,CV_CHAIN_APPROX_NONE,cvPoint(0,0));
	TICTOC::timer().toc("cvFindContours");
	TICTOC::timer().tic("cvLongestContour");
	if (contours) LongestContour(contours,&(Worm->Boundary));
	TICTOC::timer().toc("cvLongestContour");
	cvReleaseImage(&TempImage);

}
Ejemplo n.º 2
0
/*
 * Smooths, thresholds and finds the worms contour.
 * The original image must already be loaded into Worm.ImgOrig
 * The Smoothed image is deposited into Worm.ImgSmooth
 * The thresholded image is deposited into Worm.ImgThresh
 * The Boundary is placed in Worm.Boundary
 *
 */
void FindWormBoundary(WormAnalysisData* Worm, WormAnalysisParam* Params){
	/** This function currently takes around 5-7 ms **/
	/**
	 * Before I forget.. plan to make this faster by:
	 *  a) using region of interest
	 *  b) decimating to make it smaller (maybe?)
	 *  c) resize
	 *  d) not using CV_GAUSSIAN for smoothing
	 */

	/** Smooth the Image **/
	TICTOC::timer().tic("cvSmooth");
	cvSmooth(Worm->ImgOrig,Worm->ImgSmooth,CV_GAUSSIAN,Params->GaussSize*2+1);
	TICTOC::timer().toc("cvSmooth");

	/** Dilate and Erode **/
//	cvDilate(Worm->ImgSmooth, Worm->ImgSmooth,NULL,3);
//	cvErode(Worm->ImgSmooth, Worm->ImgSmooth,NULL,2);


	/** Threshold the Image **/
	TICTOC::timer().tic("cvThreshold");
	cvThreshold(Worm->ImgSmooth,Worm->ImgThresh,Params->BinThresh,255,CV_THRESH_BINARY );
	TICTOC::timer().toc("cvThreshold");


	/** Dilate and Erode **/
	if (Params->DilateErode==1){
		TICTOC::timer().tic("DilateAndErode");
		cvDilate(Worm->ImgThresh, Worm->ImgThresh,NULL,3);
		cvErode(Worm->ImgThresh, Worm->ImgThresh,NULL,2);
		TICTOC::timer().toc("DilateAndErode");
	}


	/** Find Contours **/
	CvSeq* contours;
	IplImage* TempImage=cvCreateImage(cvGetSize(Worm->ImgThresh),IPL_DEPTH_8U,1);
	cvCopy(Worm->ImgThresh,TempImage);
	TICTOC::timer().tic("cvFindContours");
	cvFindContours(TempImage,Worm->MemStorage, &contours,sizeof(CvContour),CV_RETR_EXTERNAL,CV_CHAIN_APPROX_NONE,cvPoint(0,0));
	TICTOC::timer().toc("cvFindContours");

	CvSeq* rough;
	/** Find Longest Contour **/
	TICTOC::timer().tic("cvLongestContour");
	if (contours) LongestContour(contours,&rough);
	TICTOC::timer().toc("cvLongestContour");
	cvReleaseImage(&TempImage);

	/** Smooth the Boundary **/
	if (Params->BoundSmoothSize>0){
		TICTOC::timer().tic("SmoothBoundary");
		CvSeq* smooth=smoothPtSequence(rough,Params->BoundSmoothSize,Worm->MemStorage);
		Worm->Boundary=cvCloneSeq(smooth);
		TICTOC::timer().toc("SmoothBoundary");

	} else {
		Worm->Boundary=cvCloneSeq(rough);
	}



}