www.pudn.com > Image_segment.rar > main.cpp


// main.cpp : Defines the entry point for the console application. 
// 
 
#include  
#include  
using std::cout; 
using std::cerr; 
using std::endl; 
 
#include "../cimpl/cimpl.h" 
using namespace CIMPL; 
 
#include "../cimpl/cimpltoolboxes.h" 
using namespace IO; 
using namespace MathCore; 
using namespace Analysis; 
using namespace Blas; 
using namespace Lapack; 
using namespace LevelSetMethods; 
using namespace ImageProcessing; 
using namespace PDE; 
using namespace ImageMagick; 
 
 
 
 
int main(int argc, char* argv[]) 
{ 
 
	if(argc != 11) 
	{ 
		Utility::RunTimeError("You need to enter 10 command line arguments!"); 
	} 
	char *imname =  argv[1]; 
	bool normalized = (atoi(argv[2]) == 1) ? true : false; 
	float initScale = atof(argv[3]); 
	float scaleJump = atof(argv[4]); 
	float endScale = atof(argv[5]); 
	float angleLimit = atof(argv[6]); 
	float ratioLimit = atof(argv[7]); 
	float smoothWeighting = atof(argv[8]); 
	float stopError = atof(argv[9]); 
	int accuracy = atoi(argv[10]); 
	if( accuracy != 1 && accuracy != 2 && accuracy != 3 && accuracy != 5 ) 
	{ 
		Utility::RunTimeError("The commandline argument 'accuracy' can only be 1, 2, 3, or 5!"); 
	} 
 
	MatrixList RGB = ToFloat(ImRead(imname)); 
	if(RGB.Planes() == 4) 
	{ 
		RGB.PopBack(); 
	} 
 
	MatrixList image; 
	Matrix im; 
 
	cout << "Processing "  << imname << endl; 
	bool grayscale = true; 
	if(RGB.Planes() == 3) 
	{ 
		cout << "Color image (" << RGB.Rows() << "x" << RGB.Columns() << ")" << endl << endl; 
		image = RGB2Lab(RGB); 
		grayscale = false; 
	} 
	else if(RGB.Planes() == 1) 
	{ 
		cout << "Gray scale image (" << RGB.Rows() << "x" << RGB.Columns() << ")" << endl << endl; 
		im = RGB[0]; 
		grayscale = true; 
	} 
 
 
	if(grayscale) 
	{ 
		PerfTimer pt; 
		pt.Tic(); 
		Matrix edges = SegmentEF(im, normalized, initScale, scaleJump, endScale, angleLimit,  
			ratioLimit, smoothWeighting, stopError, accuracy); 
		double el = pt.Toc(false); 
		cout << endl << "Total Time: " << el << " seconds" << endl; 
		ImWrite( edges, "edges.png"); 
		ImWrite( (im-330.0f)*ToFloat(1-edges), "segmentation.png"); 
	} 
	else 
	{ 
		//Matrix edges = SegmentEF(image, false, 4, 1, 10, 60, 25, 1.0, 0.2, 2); 
		//Matrix edges = SegmentEF(image, true, 5, 1, 15, 90, 15, 2.0, 0.1, 2); 
		PerfTimer pt; 
		pt.Tic(); 
		Matrix edges = SegmentEF(image, normalized, initScale, scaleJump, endScale, angleLimit,  
			ratioLimit, smoothWeighting, stopError, accuracy); 
		double el = pt.Toc(false); 
		cout << endl << "Total Time: " << el << " seconds" << endl; 
		ImWrite(edges, "edges.png"); 
		MatrixList tmpIm; 
		tmpIm.PushBack((RGB[0]-330.0f)*ToFloat(1-edges)); 
		tmpIm.PushBack((RGB[1]-330.0f)*ToFloat(1-edges)); 
		tmpIm.PushBack((RGB[2]-330.0f)*ToFloat(1-edges)); 
		ImWrite(tmpIm, "segmentation.png"); 
	} 
 
 
	return 0; 
 
 
 
 
 
 
}