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

📄 contour.tex

📁 图像中非刚性曲线的蛇形检测算法
💻 TEX
📖 第 1 页 / 共 2 页
字号:
% 
\subsection{Computing the centre of gravity of contour}

\subsubsection*{Synopsis}
\begin{verbatim}
	void computeCG()
\end{verbatim}

\subsubsection*{Description}	
{\tt computeCG} calculates the centre of gravity of a contour, $CG(U)$, as below :
\eq
	CG(U) = \frac{1}{n}\sum_{i=1}^{n}v_{i}
\en

%
\subsection{Duplicating a contour}

\subsubsection*{Synopsis}
\begin{verbatim}
	CONTOUR *duplicate(CONTOUR *target=NULL, short snx=0)
\end{verbatim}

\subsubsection*{Arguments}
\tb
	target & Targeted contour. \\
	snx & Flag (0:off, 1:on) to indicate copying of snaxels only.
\te

\subsubsection*{Returns}
Pointer to a new created contour if {\tt target} is NULL or pointer to the {\tt target} contour if otherwise. Returns NULL if memory allocation error

\subsubsection*{Description}
{\tt duplicate} creates an exact duplication of its contour if {\tt target} is NULL. Otherwise, it will copy its content or snaxels information only to the {\tt target} contour, depending on the {\tt snx} flag. Copying of snaxels will not be allowed if both contours have different number of snaxels.

%
\subsection{Retrieving and accessing of a contour content}

\subsubsection*{Synopsis}
\begin{verbatim}
	SNAXEL *getHead(void)
	SNAXEL *getTail(void) 
	SNAKEMODE getMode(void)
	void putMode(SNAKEMODE _mode)
	short getNumSnaxel(void)
	double getCgRow(void)
	double getCgCol(void)
	double getZ(void)
	void putCgRow(double _row)
	void putCgCol(double _col)
	double getSigNuSqr(void) 
	void putSigNuSqr(double _sig_nu_sqr)
	void putDirection(short _direction)
	void putZ(double _Z)
\end{verbatim}

\subsubsection*{Arguments}
\tb
	{\tt \_mode} & Snake mode of a contour. \\
	{\tt \_row, \_col} & Center of gravity. \\
	{\tt \_sig\_nu\_sqr} & White noise variance. \\
	{\tt \_direction} & Snake direction.
\te

\subsubsection*{Returns}
Head or tail of contour, snake mode, center of gravity, white noise variance ($\sigma_{\eta}^{2}$), snake direction, or normalizing constant.

\subsubsection*{Description}
These methods facilitate the retrieval and accessing of contour details.


%
\subsection{Displaying contour shape}

\subsubsection*{Synopsis}
\begin{verbatim}
void display(short mag = 1);	
\end{verbatim}

\subsubsection*{Arguments}
\tb
	{\tt mag} & Image magnification factor.
\te

\subsubsection*{Description}
{\tt display} shows the shape of a contour, which will always be in the center of an X window.

%
\subsection{Showing a contour on another image}

\subsubsection*{Synopsis}
\begin{verbatim}
void show(IMAGE *backgnd, unsigned char blowup=1,
          int pt_Xoffset=0, int pt_Yoffset=0, short expand=1);
\end{verbatim}

\subsubsection*{Arguments}
\tb
	{\tt backgnd} & Background image. \\
	{\tt blowup} & Image magnification factor. \\
	{\tt pt\_Xoffset, pt\_Yoffset} & Offset of a contour against
			 a window origin. \\
	{\tt expand} & Expanding factor.
\te

\subsubsection*{Description}
{\tt show} display an expanded contour on top of the background image by an offset of (pt\_Xoffset, pt\_Yoffset).


%
\subsection{Example : Initialization of contours }

This program performs the initialization of an opened and closed contour.

\begin{verbatim}
void testmain( SNAKEMODE smode,         /* snake mode */
               int Sx, int Sy,          /* starting point of a line */
               int Ex, int Ey,          /* ending point of a line */
               double Radius,           /* radius of circle */
               short num_points,        /* number of snaxels */
               int mag )                /* magnification factor */
{
        CONTOUR mycontour;              /* CONTOUR object */
        SNAXEL *sptr;                   /* SNAXEL objcet */
        register short i = 0;
         
        /* Initialize an arbitrary close snake */
        if (smode == _CLOSED)
                mycontour.init(Sy, Sx, Radius, num_points);
        else
                mycontour.init(Sx, Sy, Ex, Ey, num_points);
         
        /* The average length of snaxel must be calculated first. */
        mycontour.computeAvgLength(); 
        printf("\nContour information : \n"); 
        mycontour.print();
        printf("\nPress enter to display contour.");
        getchar();
        mycontour.display(mag); 
         
        /* Internal energy of snake without deformation should be 0 */
        printf("\nInternal energy.");
        for(sptr=mycontour.getHead(); sptr; sptr=sptr->getNext(), i++)
                printf("\nEmodel of snaxel %d = %f",
                                i, mycontour.EInternal(sptr));   
 
        printf("\nPress enter to continue");
        getchar();

        printf("\nEnd of test.\n");    
}
\end{verbatim}

{\tt getAvgLength} must be called  before the internal energy calculation so as to compute the average distant of snaxels. A contour should have internal energy of zero if no deformation happens.


%
\subsection{Example : Affine transformations of contour}

This program demonstrates the affine invariance of shape matrix. The internal energy before and after the transformation should be of the same. 

\begin{verbatim}
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);
        }
}
\end{verbatim}

 
%
\subsection{Example : Coordinate conversion of contour}
This program shows the manual initialization of a contour with mouse. Besides, {\tt imageCentered} and {\tt contourCentered} convert snaxels coordinates from contour centered form  to image centered form and vice versa.

\begin{verbatim}
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");
}
\end{verbatim}	



%
\subsection{Example : Duplication of contour}
This program shows the different modes of contour duplication.

\begin{verbatim}
void testmain(char *file1, char *file2)
{
 
        CONTOUR con1;
        CONTOUR *con3 = NULL;
        CONTOUR con2;
 
        printf("\nReading contour 1 from %s", file1);
        printf("\nReading contour 2 from %s",file2);
        if ( (con1.read(file1)) ||  (con2.read(file2)) ) exit(-1);
        
        
        printf("\n\n**** Contour 1 co-ordinates ****\n");
        con1.print();
        printf("\n\n**** Contour 2 co-ordinates ****\n");
        con2.print();
        printf("\nPress enter to continue");
        getchar();
        
        printf("\nCreating new contour from contour 1.");
        con3 = con1.duplicate(con3);
        con3->print();
        
        printf("\nCopying snaxel information only from contour 2");
        con3 = con2.duplicate(con3, 1);
        printf("\nPrinting contour information\n");
        con1.print();
        con3->print();
        getchar();
}
\end{verbatim}

The output of the program should show that {\tt con3} have properties such as {\tt sigma\_x} and {\tt avglen} that of {\tt con1} and have snaxel information that of {\tt con2}.

⌨️ 快捷键说明

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