📄 gsnake.tex
字号:
{\tt showLine} draws lines between snaxels so as to form a complete contour. The offset values help in showing a contour at various image position.
%
\subsection{Displaying gsnake and image}
\subsubsection*{Synopsis}
\begin{verbatim}
void show( unsigned char blowup =1,short expand = 1,
int showImg = 1,
int img_Xoffset = 0, int img_Yoffset = 0,
int pt_Xoffset = 0, int pt_Yoffset = 0 );
\end{verbatim}
\subsubsection*{Arguments}
\tb
{\tt blowup} & Image magnification factor. \\
{\tt expand} & Contour expansion factor. \\
{\tt showImg} & Flag tp indicate whether the raw image is
to be shown. \\
{\tt img\_Xoffset, img\_Yoffset} & X and Y offset of image position. \\
{\tt pt\_Xoffset, py\_Yoffset} & X and Y offset of snaxel position.
\te
\subsubsection*{Description}
{\tt show} displays snaxel coordinate on the raw image. If {\tt showImg} and {\tt img\_offset} are not specified, the raw image and snaxel coordinate will be shown on an X window. Otherwise, they will be shown on top of an existing image with offset ({\tt img\_Xoffset}, {\tt img\_Yoffset}). The {\tt pt\_Xoffset} and {\tt pt\_Yoffset} are necessary when showing an expanded contour.
%
\subsection{Manual deformation of a contour}
\subsubsection*{Synopsis}
\begin{verbatim}
void deform(short blowup = 1, short expand = 1)
\end{verbatim}
\subsubsection*{Arguments}
\tb
{\tt blowup} & Image magnification factor. \\
{\tt expand} & Contour expansion factor.
\te
\subsubsection*{Description}
{\tt deform} allows manual deformation of a contour shape. By using a mouse, the user can adjust and move individual snaxel around. The expansion factor is necessary when dealing with an expanded contour.
%
\subsection{Duplicating a GSNAKE}
\subsubsection*{Synopsis}
\begin{verbatim}
GSNAKE *duplicate(GSNAKE *target= NULL)
\end{verbatim}
\subsubsection*{Returns}
\begin{itemize}
\item Pointer to new {\tt GSNAKE} if {\tt target} is NULL. Otherwise,
{\tt target} will be returned.
\item NULL if memory allocation fails.
\end{itemize}
\subsubsection*{Description}
{\tt duplicate} creates an exact duplication of itself including {\tt CONTOUR} and {\tt PYRAMID} if {\tt target} is NULL. Otherwise, only {\tt GSNAKE} parameters and {\tt CONTOUR} but not {\tt PYRAMID} are copied. The rationale for this is that the external energy input should be that of the target {\tt GSNAKE}.
%
\subsection{Getting external energy input type}
\subsubsection*{Synopsis}
\begin{verbatim}
EextTYPE getEextType( void )
\end{verbatim}
\subsubsection*{Returns}
External energy type.
\subsubsection* {Description}
{\tt getEextType} returns the external energy input type. The current state of {\tt EextType} will determine the input type in any function requiring external energy input.
%
\subsection{Getting and writing the regularization parameter}
\subsubsection*{Synopsis}
\begin{verbatim}
double getGLambda( void )
void putGLambda(double _lambda)
\end{verbatim}
\subsubsection* {Description}
These methods facilitate the reading and writing of the regularization parameter. The regularization parameter can also be set at {\tt GSNAKE} constructor.
%
\subsection{Retrieving internal and external energy}
\subsubsection*{Synopsis}
\begin{verbatim}
double getEsnake(void)
double getEint(void)
double getEext(void)
\end{verbatim}
\subsubsection*{Returns}
Internal or external energy value.
\subsubsection* {Description}
These methods provide facility for accessing the energy values of GSNAKE. Since these values are stored during energy calculation routines, they may not be the most updated values.
%
\subsection{Example : Localization and minimization of GSNAKE }
A previous example in the section on {\tt GHOUGH} demonstrated the localization of a contour on an image. However, with {\tt GSNAKE}, all these are performed simply by invoking the class methods.
\begin{verbatim}
void testmain( char *imgfile, /* image file */
char *confile, /* contour file */
int level, /* pyramid level */
short mag, /* image magnifiaction factor */
int sspacing, /* snaxel spacing */
int ispacing, /* search segment spacing */
int nhood, /* number segment */
double lambda, /* regularization parameter */
EEXTTYPE Etype) /* external energy type */
{
GSNAKE mysnake(Etype);
/* If no image file or contour file, cannot continue */
if ( (mysnake.putRawImg(imgfile)) || (mysnake.CONTOUR::read(confile)) )
exit(-1);
/* Displaying the operating parameters */
printf("\n******** Operating Parameters ************\n");
printf("\nImage : %s Contour : %s ", imgfile, confile);
printf("\nSearch Spacing : %d Insertion spacing : %d",
sspacing, ispacing);
printf("\nSearch Nhood : %d, Lambda : %f",nhood, lambda);
printf("\nExternal Energy input : ");
switch (Etype) {
case _INTENSITY :
printf("Intensity");
break;
case _EDGE :
printf("Edge energy");
break;
case _EDGEMAG :
printf("Edge magnitude only");
break;
}
if (verbose) printf("\nVerbose mode on");
printf("\n\n************************************************\n\n");
mysnake.generate( level, 1 );
mysnake.PYRAMID::show( mag, level );
printf("\nPress enter to continue");
getchar();
printf("\nPerforming localization and minimisation");
mysnake.GSNAKE::localize();
mysnake.GSNAKE::minimize(sspacing, nhood, ispacing, mag, verbose,
lambda, 1);
printf("\nEnd of test. Press enter. ");
getchar();
}
\end{verbatim}
This program first reads a contour file and filters an image file as its {\tt rawImg}. Based on the operating parameters, a pyramid is generated and {\tt localize} and {\tt minimize} methods are invoked. The contour used for localization and minimization should preferably be generated from the image itself. This is due to the problem of mismatching coordinates. For example, two contours with the same shape but with coordinates differing by 100 points might not be localized on the same features, depending on the localization parameters. If the localization parameter is too large, the program may take extremely long time. Besides, if the contour is larger than the image, it will probably result in an error.
%
\subsection{Example : Energy calculation I}
This program performs internal, external and total energy calculation of a gsnake before and after manual deformation.
\begin{verbatim}
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);
}
}
\end{verbatim}
The program reads in an image file and automatically generates a {\tt \_CLOSED} contour. {\tt deform} allows the user to adjust manually the contour shape. {\tt ESnake} will calculate and compare energy values before and after deformation.
Manual deformation is useful in cases where the contour is more or less standard and it is only necessary to slightly modify the template to fit the image better. It is also useful for shape learning purposes.
%
\subsection{Example : Energy calculation II}
This program performs internal, external and total energy calculation of a gsnake before and after fine localization.
\begin{verbatim}
void testmain( char *imgfile, /* image file */
int level, /* pyramid level */
int mag, /* magnification factor */
int correlateX, /* X resolution for correlation */
int correlateY, /* Y resolution for correlation */
char *outfile) /* output file */
{
int row, col, i;
GSNAKE mysnake;
SNAXEL *sptr;
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();
mysnake.computeCG();
mysnake.computeAvgLength();
printf("\nEnergy values before fine localisation ");
printf("\n Snake energy calculation");
printf("\n********************************");
printf("\n[col row]\tEint\tEext\tEtotal\tLambda\n");
printf("---------\t----\t----\t------\t------\n");
mysnake.ESnake( 0, 1 );
printf("\nTotal energy : %f\n",
mysnake.getEsnake() );
mysnake.show(mag);
printf("\nPress enter to continue ..");
getchar();
mysnake.fineLocalize( correlateX, correlateY );
printf("\nTotal energy after fine localisation ");
printf("\n Snake energy calculation");
printf("\n********************************");
printf("\n[col row]\tEint\tEext\tEtotal\tLambda\n");
printf("---------\t----\t----\t------\t------\n");
mysnake.computeCG();
mysnake.computeAvgLength();
mysnake.ESnake( 0, 1 );
printf("\nTotal energy : %f\n", mysnake.getEsnake() );
mysnake.show(mag);
printf("\nPress enter to continue ..");
getchar();
}
\end{verbatim}
In this program, {\tt fineLocalize} reallocates the contour at a finer resolution. {\tt ESnake} will calculate and compare energy values before and after fine localization.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -