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

📄 gmm_lib.h

📁 高斯混合模型的C语言实现
💻 H
字号:
/*
* All questions regarding the software should be addressed to
* 
*       Prof. Charles A. Bouman
*       Purdue University
*       School of Electrical and Computer Engineering
*       1285 Electrical Engineering Building
*       West Lafayette, IN 47907-1285
*       USA
*       +1 765 494 0340
*       +1 765 494 3358 (fax)
*       email:  bouman@ecn.purdue.edu
*       http://www.ece.purdue.edu/~bouman
* 
* Copyright (c) 1995 The Board of Trustees of Purdue University.
*
* Permission to use, copy, modify, and distribute this software and its
* documentation for any purpose, without fee, and without written agreement is
* hereby granted, provided that the above copyright notice and the following
* two paragraphs appear in all copies of this software.
*
* IN NO EVENT SHALL PURDUE UNIVERSITY BE LIABLE TO ANY PARTY FOR DIRECT,
* INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
* USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF PURDUE UNIVERSITY HAS
* BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* PURDUE UNIVERSITY SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
* PARTICULAR PURPOSE.  THE SOFTWARE PROVIDED HEREUNDER IS ON AN "AS IS" BASIS,
* AND PURDUE UNIVERSITY HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT,
* UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
*/

/************************************************************************
* Modified for the purpose of image and video segmentation
*
*	Dr. Liu Zhi
*	School of Communication and Information Engineering
*	Shanghai University, 200072
*	P.R.China
*
************************************************************************/

// Head file for call by applications

#ifndef GMM_LIB_H
#define GMM_LIB_H

//clust_def.h

/*****************************************************/
/* This constant determines the ratio of the average */
/* covariance to the minimum allowed covariance.     */
/* It is used to insure that the measured covariance */
/* is not singular. It may need to be adjusted for   */
/* different applications.                           */
/*****************************************************/
#define COVAR_DYNAMIC_RANGE 1E5

#define CLUSTER_FULL 1 /* Use full covariance matrix in clustering */
#define CLUSTER_DIAG 0 /* Use diagonal covariance matrix in clustering */

#define PI 3.141592654

#include<stdio.h>
#include<stdlib.h>
#include <string.h>
#include <math.h>
#include <float.h>


/* SigSet (Signature Set) data stucture used throughout package.         */
/*   ClassSig (Class Signature) data stucture holds the parameters       */
/*       of a single Gaussian mixture model. SigSet.nclasses is the      */
/*       number of ClassSig's in a SigSet.                               */
/*     SubSig (Subsignature) data stucture holds each component of a     */
/*         Gaussian mixture model. SigSet.ClassSig[k].nsubclasses is the */
/*         number of SubSig's in a ClassSig.                             */

struct SigSet
{
    int nbands;
    int nclasses;	//No. of GMM models (No. of classes)
    char *title;
    struct ClassSig	//rep. one GMM model
    {
        long classnum;	
        char *title;
        int used;
        int type;
        int nsubclasses;	//No. of Gaussian components in one GMM
        struct SubSig		//rep. one Gaussian component
        {
            double N;       /* expected number of pixels in subcluster */
            double pi;      /* probability of component in GMM */
            double *means;  /* mean of component in GMM */
            double **R;     /* covariance of component in GMM */
            double **Rinv;  /* inverse of R */
            double cnst;    /* normalizing constant for multivariate Gaussian */
            int used;
        } *SubSig;
        struct ClassData
        {
            int npixels;
            double SummedWeights;
            double **x; /* list of pixel vectors:     x[npixels][nbands] */
            double **p; /* prob pixel is in subclass: p[npixels][subclasses] */
            double  *w; /* weight of pixel:           w[npixels] */
			int     *ml_label;				/* subclass_label[npixels] subclass label with ML */
        } ClassData;
    } *ClassSig;
};


#define SIGNATURE_TYPE_MIXED 1

//alloc_util.h
char *G_malloc(int n);
char *G_calloc(int n,int m);
char *G_realloc(char *b,int n);
void G_dealloc(char *b);
double *G_alloc_vector(int n);
double **G_alloc_matrix(int rows,int cols);
void G_free_vector(double *v);
void G_free_matrix(double **m);
int *G_alloc_ivector(int n);
int **G_alloc_imatrix(int rows,int cols);
void G_free_ivector(int *v);
void G_free_imatrix(int **m);

//clust_util.h
int I_SigSetNClasses(struct SigSet *S);
struct ClassData *I_AllocClassData(struct SigSet *S, struct ClassSig *C, int npixels);
void I_InitSigSet(struct SigSet *S);
void I_SigSetNBands(struct SigSet *S, int nbands);
struct ClassSig *I_NewClassSig(struct SigSet *S);
struct SubSig *I_NewSubSig (struct SigSet *S, struct ClassSig *C);
void I_SetSigTitle(struct SigSet *S, char *title);
char *I_GetSigTitle(struct SigSet *S);
void I_SetClassTitle(struct ClassSig *C, char *title);
char *I_GetClassTitle(struct ClassSig *C);
void I_DeallocClassData(struct SigSet *S, struct ClassSig *C);
void I_DeallocSubSig(struct ClassSig *C);
void I_DeallocClassSig(struct SigSet *S);
void I_DeallocSigSet(struct SigSet *S);

//clust_io.h
void I_ReadSigSet(FILE *fd, struct SigSet *S);
void I_WriteSigSet(FILE *fd, struct SigSet *S);

//clust.h
double AverageVariance(struct ClassSig *Sig, int nbands);
int GMM_Estimate(struct SigSet* S, double* sample_vector, int num_of_samples, int vector_dimension, int nclasses, int init_num_of_subclasses, int desired_num_of_subclasses, int is_cov_diag);

//classify_util.h
void GMM_Subclass_Prob(struct SigSet *S);	//get prob. for each subclass

#endif

⌨️ 快捷键说明

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