📄 gsn.h
字号:
/**************************************************************************** File Name : gsnake.h Purpose : Header file for GSNAKE API Release : Version 1.0 Date : Aug 31,1995GSNAKE API is jointly developed by the Information Technology Institute (ITI), Singapore, and the School of Applied Science, Nanyang TechnologicalUniversity (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, enhaucements, 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****************************************************************************/#ifndef GSNAKELIB#define GSNAKELIB#include <string.h>#include <stdio.h>#include <stdlib.h>#include <math.h>#include "dibapi.h"/* error numbers */#define NOERROR 0 #define FILEIOERROR -1#define MEMORYERROR -2#define PARAMERROR -3/* constants */#define GRAYLEVELRANGE 255#define CONTOURMAGICNUMBER 0x1010#define VERY_SMALL 1e-10#define VERY_BIG 1e+10#define MAX_SNAKEPTS 100#define MAXMAG 1.0#define M_PI 3.1415/* macros */#define ROUNDOFF(x) ((int) ( (x > 0) ? (x+0.5) : (x-0.5)))#define LEVEL(ratio) pow( 2.0, (double) ratio ) #define SIGN(x) ( ((int) x) ? ( (x > 0) ? 1 : -1 ) : 0 )#define EDGEDIR(r1,c1,r2,c2) ( SIGN(r1*r2 + c1*c2) )#define MAX(x, y) ( (x > y) ? (x) : (y) ) #define MIN(x, y) ( (x < y) ? (x) : (y) )#define CAP(low, x, upp) ( (x < low) ? low : ( (x > upp) ? upp : x ) )#define SQR(a) ( (a) * (a) )#define RADIAN(angle) ((double) angle/180.0 * M_PI )#define ANGLE(radian) (180.0 * radian / M_PI)#define DEGREE(r) ( r*180.0 / M_PI)#define ATAN2(y, x) ((fabs(x) > VERY_SMALL)? atan2(y,x) : \ (y>0) ? 0.5*M_PI : -0.5*M_PI )/* memory macros */#define _iMemAlloc(x) malloc(x)#define _iMemRealloc(ptr, x) ( (ptr) ? realloc(ptr, x) : malloc(x) )#define _iMemFree(x) if(x) { free(x) ; x = NULL ; } #define _LOCAL_MINMAX -1.0 /* flag at model for LMINMAX */#define _LOCAL_LAMBDA 2.0 /* localize regularization parameter used */#define _DEFINED_LAMBDA -2.0 /* used previously defined lambda */typedef enum _InputImageFormat { _bin, _ras };//typedef enum { _TRUE=1, FALSE=0 } BOOLEAN ;typedef enum { /* type of energy used as image energy */ _EDGE, /* use edges : boundary detection */ _EDGEMAG, /* edge magnitude only : without direction info */ _INTENSITY /* use intensity. e.g. character detection */} EEXTTYPE ;typedef enum { /* methods classification */ _MARGIN_PROB = 0, /* summation of probablity for classification */ _DEFORM_PROB = 1, /* MAP probability */ _DEFORM_MATCH = 2, /* match of deformable template */ _RIGID_MATCH = 3 /* match of rigid template */} CLASSTYPE;typedef enum { /* open/connected snake */ _OPENED = 0, /* two end points are not connected */ _CLOSED = 1 /* end points are connected */} SNAKEMODE ;typedef enum { _DRAGMOUSE, /* manual initialization by dragging the mouse */ _CLICKMOUSE, /* manual initialization by clicking the mouse */ _LOADTEMPLATE, /* load templates from a given learned file */ _INITTEMPLATE /* init line or circle templates from program */} INITMODE ;/* Image object stores Image data in the form of a matrix of size row by col data* points to start address of the matrix. ximg* points to start of xwindow image, with magnifying factor magnify. */ class IMAGE { protected: float *data; /* image data */ int row, col; /* row and col of image */ protected: double innerProd (IMAGE *InputImg, int InpRowIndex, int InpColIndex); public : IMAGE(); ~IMAGE(); void reset(); init(int _row, int _col); void put(int m, int n, float val) { *( data+ (m)*col + (n) ) = val; } float get(int m, int n) { return *( data+(m)*col+(n) ); } int getRow() {return row;} int getCol() {return col;} void print(); read (char *filename); void condition(double low_pct=0.9, double high_pct=0.95, double low_val=0.2, double high_val=0.9, double imm_pow=1.0); void initAsGauss(); IMAGE *correlate (IMAGE *InputImg, int RowStep, int ColStep, char verbose=0); IMAGE *IMAGE::cut(int sx,int sy,int height, int length); int fill(float val, int sx=0,int sy=0, int length=0, int height=0); IMAGE *copy() {return cut(0,0,col,row);} };/* Provide advance matrix manipulation routines for IMAGE object. */ class MATRIX : public IMAGE { public : init(short _row, short _col, char identity=0); swapRow(short i, short j ); void dump(char *header=NULL); MATRIX * transpose (void) ; MATRIX * operator+ (MATRIX& mtx) ; MATRIX * operator- (MATRIX& mtx) ; MATRIX * operator* (MATRIX& mtx) ; MATRIX * inverse (void) ;};/*Edge object stores Magnitude and Angle information of the edge gradient in the form of two image objects. This way of representing the information serves to reduce coding needed for application */ class EDGE { protected : IMAGE *Mag; IMAGE *Ang; protected : init(int _row, int _col); public : EDGE(){Mag=Ang=NULL;} ~EDGE(){reset(); } void reset() ; float getMag(int m,int n) { return Mag->get(m,n); } float getAng(int m,int n) { return Ang->get(m,n); } void putMag(int m, int n, float val) { Mag->put(m,n,val); } void putAng(int m, int n, float val) { Ang->put(m,n,val); } compute(IMAGE *img, int verbose=1, double low_pct=0.9, double high_pct=0.95, double low_val=0.2, double high_val=0.9, double imm_pow=1.0); int getRow(int MagData=1) { return (MagData) ? Mag->getRow():Ang->getRow();} int getCol(int MagData=1) { return (MagData) ? Mag->getCol():Ang->getCol();} void putMagImg( IMAGE *magImg ) { Mag = magImg; } void putAngImg( IMAGE *angImg ) { Mag = angImg; } IMAGE *getMagImg(void) { return Mag ; } IMAGE *getAngImg(void) { return Ang ; } }; class PYRAMID { protected : short numLevel ; /* number of level */ EDGE **edgemap ; /* edge map at each level */ IMAGE **gaussImg ; /* gaussian smoothed image */ protected : int init(short level); public : IMAGE *rawImg; /* raw image */ PYRAMID(); ~PYRAMID(); void reset(); generate(short level, int verbose=0,double low_pct=0.9, double high_pct=0.95, double low_val=0.2, double high_val=0.9, double imm_pow=1.0, EEXTTYPE = _EDGE); int duplicate( PYRAMID *pyramid ); EDGE *getEdge(short level_id) { return ( (level_id>numLevel-1) || (level_id <0) ) ? NULL: edgemap[level_id]; } IMAGE *getGauss(short level_id) { return ( (level_id>numLevel-1) || (level_id <0) ) ? NULL: gaussImg[level_id]; } void putRawImg( IMAGE *img ) { rawImg = img->copy();} int putRawImg( char *filename ); short getLevel(void) { return numLevel; } void print(int level);};class SNAXEL { protected : double row, col ; /* snaxel coordinate */ double alpha, beta ; /* shape coefficients */ double lambda ; /* local regularization parameters */ double Eint, Eext ; /* internal/external energy */ double Esnaxel; /* snaxel energy */ SNAXEL *next; /* next snaxel */ SNAXEL *prev; /* previous snaxel */ public : SNAXEL(); ~SNAXEL() {;} double getNormalAng( SNAKEMODE mode, SNAXEL *head, SNAXEL *tail); void getDirectionVec( SNAKEMODE mode, SNAXEL *head, SNAXEL *tail, double *Uv0_x, double *Uv0_y, double *Uv1_x, double *Uv1_y); void getNormalVec( SNAKEMODE mode, SNAXEL *head, SNAXEL *tail, double *nv_x, double *nv_y ); void meanPosition( SNAKEMODE mode, double cg_row, double cg_col, SNAXEL *head, SNAXEL *tail, double *meanrow, double *meancol); /* interface */ double getRow(void) {return row;} double getCol(void) {return col;} double getAlpha(void) {return alpha;} double getBeta(void) {return beta;} double getLambda(void) {return lambda; } double getEsnaxel(void) {return Esnaxel; } double getEint(void) {return Eint; } double getEext(void) {return Eext; } SNAXEL *getNext(void) { return next; } SNAXEL *getPrev(void) { return prev; } SNAXEL *getNext(SNAKEMODE mode, SNAXEL *head); SNAXEL *getPrev(SNAKEMODE mode, SNAXEL *tail); void putRow( double _row ) {row = _row;} void putCol( double _col ) {col = _col;} void putPrev( SNAXEL *_prev ) {prev = _prev;} void putNext( SNAXEL *_next ) {next = _next;} void putAlpha( double _alpha ) {alpha = _alpha;} void putBeta( double _beta ) {beta = _beta;} void putLambda( double _lambda ) {lambda = _lambda; } void putEsnaxel( double _Esnaxel ) {Esnaxel = _Esnaxel;} void putEint( double _Eint ) {Eint = _Eint; } void putEext( double _Eext ) {Eext = _Eext; }};class CONTOUR { protected : SNAXEL *head; /* head of snake */ SNAXEL *tail; /* tail of snake */ SNAKEMODE mode; /* opened or closed snake */ short numsnaxel; /* number of snaxel */ double cg_row, cg_col; /* center of gravity */ double avglen; /* ave. power (length) of snake */ double sig_nu_sqr ; /* white noise variance on gradient power */ double Z ; /* normalizing constant */ short direction; /* [0/-1/+1] preset gradient direction */ protected : int initSnaxel( short numsnaxel ); void adjust(); protected : int init( short *ydata, short *xdata, short numpts = 16, unsigned char ratio = 1 ); int init( double *ydata, double *xdata, short numpts = 16, unsigned char ratio = 1 ); void copySnaxel( CONTOUR *target ); public : CONTOUR(void); ~CONTOUR(void); void reset(void); /* Internal Energy */ double EInternal( SNAXEL *sxptr ); /* initialize contour routines */ int init( short _cg_row, short _cg_col, double radius, short numpts = 16); int init( short sx, short sy, short ex, short ey, short numpts = 16 ); int read( char *filename );
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -