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

📄 con3.c

📁 图像中非刚性曲线的蛇形检测算法
💻 C
字号:
/****************************************************************************
 File Name  : con3.c
 Purpose    : 1. contour initialization with mouse
 	      2. coordinate conversion between image and contour centered 
	         form
 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 testmain(char *,INITMODE, SNAKEMODE,int, int);
void printhelp();
void getparam(int , char** ,int *,int *, INITMODE *, SNAKEMODE *);


main(int argc,char **argv)
{
	int magnify;
	INITMODE init_mode=_CLICKMOUSE;
	SNAKEMODE sna_mode= _CLOSED;
	int numpts = 8;

	magnify =1;

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


void testmain( char *imgfile,		/* image file */
	       INITMODE imode,		/* manual initialization mode */
	       SNAKEMODE smode,		/* snake mode */
	       int numpts,		/* number of snaxels */
	       int mag )		/* image magnification factor */
{
	CONTOUR mycontour;		/* CONTOUR object */
	SNAXEL *sptr;			/* SNAXEL object */
	IMAGE myimage;			/* IMAGE object */
	register short i;

	/* Read and show image */		
	if (myimage.read(imgfile)) exit(-1);
	myimage.show(mag);
	
	/* Generating line or circle based on image automatically */
	if (imode == _LOADTEMPLATE) {

	    int row, col;

	    row = myimage.getRow();
	    col = myimage.getCol();

	    if ( smode == _CLOSED ) 
		mycontour.init( row/2, col/2, (double)MIN(row,col)/4.0,numpts );
	    else
		mycontour.init( (short)(col/4), (short)(row/4),(short)(3*col/4), (short)(row/2), numpts );
	}

	else {
		/* Initialise contour with mouse*/ 
		mycontour.init(&myimage, mag, imode, smode);  
	}

	mycontour.display(mag);
	printf("\nPress enter to continue.");
	getchar();
	 
	/* first calculate Cg of contour */
	mycontour.computeAvgLength();
	mycontour.computeShape();
	mycontour.computeCG();
	printf("\nCG Row= %f CG col = %f", mycontour.getCgRow(),mycontour.getCgCol());
		
	/* Converting co-ordinate form */	
	printf("\n **** Getting contour centered co-ordinates ****\n\n");	
	mycontour.contourCentered();
	mycontour.print();	
	for(sptr=mycontour.getHead(), i=0; sptr; sptr=sptr->getNext(), i++)
		printf("\nInternal energy of snaxel %d = %f",
		i,mycontour.EInternal(sptr));

	printf("\nPress enter to continue.");
	getchar();
	
	printf("\nConverting back to image centered\n\n");	
	mycontour.imageCentered();
	mycontour.print();
	for(sptr=mycontour.getHead(), i=0; sptr; sptr=sptr->getNext(), i++)
		printf("\nInternal energy of snaxel %d = %f",
		i, mycontour.EInternal(sptr));
	printf("\nEnd of test.\n");
}


void getparam( int ac, char** av,
	       int *Mfactor,
	       int *Numpts,
	       INITMODE *mode, 
 	       SNAKEMODE *smode)
{   
	register int i;
	char *inputstr;

	for (i=2; i<ac; i++) {

		if( *av[i] != '-' )
			continue;	/* illegal input */

		inputstr = av[i]+2;

		switch( *(av[i]+1) ) {

		   case 'I' :

			switch (*(av[i]+2)) {
			   case 'c': *mode = _CLICKMOUSE; break;
			   case 'd': *mode = _DRAGMOUSE;break;	
			   case 'a': *mode = _LOADTEMPLATE;break;
	
			}
			break;

		   case 'm' :
			switch (*(av[i]+2)) {
			   case 'c': *smode = _CLOSED; break;
			   case 'o': *smode = _OPENED;break;			
			}
			break;

		   case 'M' :
			*Mfactor=atoi(inputstr);	
			break;
		
		   case 'N' :
		   	*Numpts = atoi(inputstr);
		   	break;		
		  
		    default: break;
		}
	}
}


void printhelp()
{
	printf("\n\nInitialization of contour and coordinate conversion");
	printf("\n Usage :OOcon3 <image> [ option ]");
	printf("\n [ option ]");
	printf("\n -M        :Magnification factor, default 1");
	printf("\n -N        :Number of snaxels, default 8");
	printf("\n -I/c/d/a  :Contour initialisation, default c");
	printf("\n           :c - click  d - drag D  a - Auto Default");
	printf("\n -m/o/c    :Snake mode, default c");
	printf("\n           :o - opened  c - closed\n\n");
}

⌨️ 快捷键说明

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