📄 con2.c
字号:
/****************************************************************************
File Name : con2.c
Purpose : 1. affine transformation of contour
2. learning 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 testmain(char *, int, double ,int ,int, double, double, double, double, char*);
void printhelp();
void getparam(int ac, char** av,double *ang, int *tx,int *ty,
double *sx, double *sy, double *dx,double *dy, int *mag, char **outfile);
main(int argc,char **argv)
{
double Rangle;
int tx,ty;
double dx,dy;
double sx, sy;
int mag =1;
char *outfile = NULL;
Rangle = 0;
tx = ty = 0;
sx = sy = 1;
dx = dy = 0.0;
if (argc==1) printhelp();
else {
getparam(argc,argv,&Rangle, &tx, &ty, &sx, &sy,
&dx, &dy, &mag, &outfile);
testmain(argv[1], mag, Rangle,tx,ty,sx,sy,dx,dy,outfile);
return(0);
}
}
void testmain( char *confile, /* contour file */
int mag, /* magnification factor */
double angle, /* rotation angle */
int tx, int ty, /* translation vector */
double sx, double sy, /* scaling factor */
double dx, double dy, /* dilution vector */
char *outfile) /* output file */
{
CONTOUR mycontour; /* CONTOUR object */
SNAXEL *sptr; /* SNAXEL object */
register short i;
double temp;
/* read a contour file */
if (mycontour.read(confile)) exit(-1);
mycontour.display(mag);
/* Calculate average length and internal energy of snaxel */
temp = mycontour.computeAvgLength();
mycontour.computeShape();
mycontour.print();
for(i=0, sptr=mycontour.getHead(); sptr; sptr=sptr->getNext(), i++)
printf("\nEmodel of snaxel %d = %f",i,mycontour.EInternal(sptr));
printf("\nPress enter to continue");
getchar();
/* affine transformation should be done in contour centered formed */
mycontour.contourCentered();
mycontour.affineTransform( sx, sy, angle, tx, ty, dx, dy );
printf("\nShowing contour after transformations.");
mycontour.imageCentered();
mycontour.computeCG();
mycontour.display(mag);
printf("\nPress enter to continue");
getchar();
/* internal energy should be invariant to affine transforms */
printf("\nPerforming internal energy calculation after transforms.\n");
for(i=0, sptr=mycontour.getHead(); sptr; sptr=sptr->getNext(), i++)
printf("\nEmodel of snaxel %d = %f", i, mycontour.EInternal(sptr));
/* Performing shape learning */
printf("\n\nContour and snaxel co-efficients after learning.\n");
printf("\nAverage distance: %f\n",temp);
mycontour.computeShape();
mycontour.display();
mycontour.print();
printf("\nPress enter to continue");
getchar();
/* write contour to output file */
if (outfile) {
printf("\nWriting contour to file %s", outfile);
mycontour.write(outfile);
}
}
void getparam( int ac, char** av,
double *ang, int *tx, int *ty,
double *sx, double *sy,
double *dx,double *dy,
int *mag, char **outfile)
{
register int i;
char *inputstr;
for (i=1; i<ac; i++) {
if( *av[i] != '-' )
continue; /* illegal input */
inputstr = av[i]+2;
switch( *(av[i]+1) ) {
case 't' :
inputstr=av[i]+3;
switch (*(av[i]+2)) {
case 'x': *tx = atoi(inputstr); break;
case 'y': *ty = atoi(inputstr);break;
}
break;
case 's' :
inputstr=av[i]+3;
switch (*(av[i]+2)) {
case 'x': *sx = atof(inputstr); break;
case 'y': *sy = atof(inputstr);break;
}
break;
case 'd' :
inputstr=av[i]+3;
switch (*(av[i]+2)) {
case 'x': *dx = atof(inputstr); break;
case 'y': *dy = atof(inputstr);break;
}
break;
case 'M' :
*mag=atoi(inputstr);
break;
case 'O' :
*outfile=inputstr;
break;
case 'r' :
*ang = atof(inputstr);
break;
default: break;
}
}
}
void printhelp()
{
printf("\n\nTransformation of arbitrary contour");
printf("\n Usage :OOcon2 <contour> [ option ]");
printf("\n [ option]");
printf("\n -M : Magnification factor, default 1");
printf("\n -r : Rotation. Angle in degrees.");
printf("\n -t : Translation in x or y direction");
printf("\n -s : Scaling in x or y direction");
printf("\n -d : Dilation in x and y direction");
printf("\n -O : Output image file\n\n");
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -