📄 lea1.c
字号:
/****************************************************************************
File Name : lea1.c
Purpose : to show invariance of shape matrix
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, unsigned char *mag, short *level,
int *magpos, int *levelPos );
void testmain( char **av, unsigned char mag, short level,
int magPos, int levelPos );
void printhelp();
main( int argc, char **argv )
{
short level = 2; /* pyramid level */
unsigned char mag = 1; /* blowup ratio */
int magPos = -1;
int levelPos = -1;
if (argc < 2)
printhelp();
else {
getparam( argc, argv, &mag, &level, &magPos, &levelPos );
testmain( argv, mag, level, magPos, levelPos );
return( 0 );
}
}
void testmain( char **argv,
unsigned char mag,
short level,
int magPos,
int levelPos )
{
MODEL model; /* to store results of learning */
GSNAKE sample(_EDGE); /* sample will use _EDGE as external energy */
char **imgsamples; /* image samples */
register short i;
imgsamples = &argv[1] ;
for( i=1; *imgsamples ; i++, imgsamples++) {
if ( ( i == magPos ) || ( i == levelPos) )
break;
printf("Using Sample %s to Learn SHAPE\n\n", *imgsamples);
sample.putRawImg(*imgsamples);
if( i==1 ) {
/* use manually selected feature points to
estimate the shape matrix */
sample.CONTOUR::init( sample.rawImg, mag );
model.LearnShape( &sample );
}
/* Using the initial shape matrix and minimiax regularization,
the total energy of gsnake is minimize and then the shape
matrix is updated */
model.duplicate(&sample);
sample.generate(level, 1); /* generate pyramid */
sample.localize(5, 5, 1, 0.25, 3); /* localize the contour */
sample.minimize(5, 5, 0, mag); /* minimize energy */
sample.deform( mag ); /* manually adjust */
model.LearnShape( &sample ); /* average out the shape coef*/
/* Using the shape matrix and the last two snaxels,
a contour is regenerated to show invariance of shape matrix */
if( i != 1 ) {
printf("Regenerate the shape...\n");
model.regenerate(); /* regenerate the shape based on mtx */
model.CONTOUR::display( mag );
printf("Press Enter to continue...\n");
getchar();
}
}
printf("\nResulting contour :\n");
model.CONTOUR::print() ;
}
void getparam( int ac, char **av,
unsigned char *Mfactor,
short *level,
int *magPos,
int *levelPos )
{
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);
if ( *magPos == -1 )
*magPos = i;
break;
case 'L' :
*level = atoi(inputstr);
if ( *levelPos == -1 )
*levelPos = i;
break;
default :
break;
}
}
}
void printhelp()
{
printf("\n (1) To show the invariance of shape matrix to affine transform");
printf("\n (2) To learn the shape matrix");
printf("\n Usage : OOlea1 <image samples> [ option ]");
printf("\n [option]");
printf("\n -M :Magnification factor, default 1");
printf("\n -L :Level of pyramid, default 2\n\n");
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -