⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 gsn2.c

📁 图像中非刚性曲线的蛇形检测算法
💻 C
字号:
/****************************************************************************
 File Name  : gsn2.c
 Purpose    : 1. Manual deformation of gsnake
 	      2. Energy calculation
 Date	    : Aug 31,1995

GSNAKE API is jointly developed by the Information Technology Institute (ITI), Singapore, and the School of Applied Science, Nanyang Technological
University (NTU), Singapore. 

These software programs are available to the user without any license or royalty fees. Permission is hereby granted to use, copy, modify, and distribute this software and its documentation for any purpose. ITI and NTU gives no warranty, express, implied, or statuary for the software and/or documentation provided, including, without limitation, waranty of merchantibility and warranty of fitness for a particular purpose. The software provided hereunder is on an "as is"  basis, and ITI and NTU has no obligation to provide maintenance, support, updates, enhancements, or modifications.

GSNAKE API is available for any UNIX compatible system. User feedback, bugs, or software and manual suggestions should be sent via electronic mail to one of the following, who may or may not act on them as he/she desires :

		asschan@ntu.ac.sg
		kflai@iti.gov.sg
***************************************************************************/


#include "gsnake.h"
#include "xwindow.h"


void getparam(int ac, char **av, int *Mfactor, int *level, char **outfile);
void testmain(char *imgfile, int level, int mag, char *outfile);
void printhelp();

main( int argc, char **argv )
{
	int level = 2;
	int magnify = 1;
	char *outfile = NULL;

	if (argc==1) printhelp();
	else {
		getparam(argc, argv, &magnify, &level, &outfile);
		testmain(argv[1], level, magnify, outfile);
		return(0);
	}	
}         


void testmain( char *imgfile,	/* image file */
	       int level,	/* pyramid level */
	       int mag,		/* magnification factor */
	       char *outfile)	/* output file */
{
	int row, col;		/* image of size colxrow*/
	GSNAKE mysnake;		/* GSNAKE object */
	SNAXEL *sptr;		/* SNAXEL object */
	short register i;
	
	if (mysnake.putRawImg(imgfile) ) exit(-1);
	
	row = mysnake.PYRAMID::rawImg->getRow();
	col = mysnake.PYRAMID::rawImg->getCol();
	mysnake.generate(level,1);
	
	/* Autoinitialising of a closed snake */
	/* centre at cg of image, radius= smaller of row/col divide by 4 */
	printf("\nCreating template from image dimension ..");
	mysnake.CONTOUR::init(row/2, col/2,(double)MIN(row,col)/4);
	printf("\nPerforming localisation of contour.");
	mysnake.localize();
	printf("\nLocalized !");
	printf("\nPress enter to continue ..");
	getchar();
	
	printf("[col row]\tEint\tEext\tEtotal\tLambda\n");
	printf("---------\t----\t----\t------\t------\n");
	mysnake.ESnake( 0, 1 );
	printf("\nTotal energy of snake: %f\n",mysnake.getEsnake() );

	/* Manual deformation of snake */	
	mysnake.deform(mag);

	printf("[col row]\tEint\tEext\tEtotal\tLambda\n");
	printf("---------\t----\t----\t------\t------\n");
	mysnake.ESnake( 0, 1 );
	printf("\nTotal energy after deformation : %f\n", 
		mysnake.getEsnake() );
	printf("\nPress enter to continue..");
	getchar(); 

	if (outfile) {
		printf("\nWriting to file %s\n\n",outfile);
		mysnake.CONTOUR::write(outfile);
	}	
}                                                                                                                                                 


void getparam(int ac, char **av, int *Mfactor, int *level, char **outfile)
{   
	register int i;
	char *inputstr;

	for (i=2; i<ac; i++) {
	
		if (*(av[i]) != '-') continue;
			
		inputstr = av[i]+2;

		switch( *(av[i]+1) ) {
				
		   case 'M' :
			*Mfactor=atoi(inputstr);
			break;
	
		   case 'L' :
		   	*level = atoi(inputstr);
		   	break;
		  
		   case 'O' :
			*outfile = inputstr;
			break;

		   default :
			break;
	
		}
	}
}


void printhelp()
{
	printf("\n\nEnergy calculation before and after manual deformation.");
	printf("\n Usage :OOgsn2 <image> [ option ]");
	printf("\n [ option ]");
	printf("\n -M    :Magnification factor, default 1 ");
	printf("\n -L    :Level of pyramid to build to, default 2");
	printf("\n -O	 :Output contour file\n\n");      
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -