next up previous contents
Next: cvip_pgmtexture.c Up: HeLa Data Previous: HeLa Data

mb_texture.c

 /*/////////////////////////////////////////////////////////////////////////
//
//
//                            mb_texture.c 
//
//
//                           Michael Boland
//                            23 Nov 1998
//
//  Revisions:
//
/////////////////////////////////////////////////////////////////////////*/


#include "mex.h"
#include "matrix.h"
#include "Include/ppgm.h"
#include "Include/CVIPtexture.h"
#include 

#define row 0
#define col 1

extern TEXTURE * Extract_Texture_Features();

void mexFunction(int nlhs, mxArray* plhs[], int nrhs, const mxArray* prhs[])
{

  int         distance;            /*parameter for texture calculations*/
  u_int8_t*   p_img;               /*The image from Matlab*/
  u_int8_t**  p_gray;              /*Image converted for texture calcs*/
  int         mrows;               /*Image height*/
  int         ncols;               /*Image width*/
  TEXTURE_FEATURE_MAP* features_used ;  /*Which features to calc.*/
  TEXTURE*    features ;           /*Returned struct of features*/
  int         i ;
  int         imgsize[2] ;              
  int         imgindex[2] ;
  long        offset ;                  
  int         outputsize[2] ;      /*Dimensions of TEXTURE struct*/
  int         outputindex[2] ;
  float*      output ;             /*Features to return*/
  u_int8_t*   outtest ;

  if (nrhs != 1) {
    mexErrMsgTxt("mb_texture requires a single input argument.\n") ;
  } else if (nlhs != 1) {
    mexErrMsgTxt("mb_texture returns a single output.\n") ;
  }

  if (!mxIsNumeric(prhs[0])) {
    mexErrMsgTxt("mb_texture requires a single numeric input.\n") ;
  }

  if (!mxIsUint8(prhs[0])) {
    mexErrMsgTxt("mb_texture requires a single unsigned 8-bit int.\n") ;
  }

  mrows = mxGetM(prhs[0]) ;
  ncols = mxGetN(prhs[0]) ;

  if(!(mrows > 1) || !(ncols > 1)) {
    mexErrMsgTxt("mb_texture requires an input image, not a scalar.\n") ;
  }

  p_img = (u_int8_t*)mxGetData(prhs[0]) ;

  distance = 1 ;

  features_used = mxCalloc(1, sizeof(TEXTURE_FEATURE_MAP)) ;
  if(!features_used) 
    mexErrMsgTxt("mb_texture: error allocating features_used.") ;

  features_used->ASM = 1 ;
  features_used->contrast = 1 ;
  features_used->correlation = 1 ;
  features_used->variance = 1 ;
  features_used->IDM = 1 ;
  features_used->sum_avg = 1 ;
  features_used->sum_var = 1 ;
  features_used->sum_entropy = 1 ;
  features_used->entropy = 1 ;
  features_used->diff_var = 1 ;
  features_used->diff_entropy = 1 ;
  features_used->meas_corr1 = 1 ;
  features_used->meas_corr2 = 1 ;
  features_used->max_corr_coef = 0 ;

  imgsize[col] = ncols ;
  imgsize[row] = mrows ;
  
  p_gray = mxCalloc(mrows, sizeof(u_int8_t*)) ;
  if(p_gray) {
    for(i=0; iASM[outputindex[col]] ;

    outputindex[row]++ ;
    offset =  mxCalcSingleSubscript(plhs[0], 2, outputindex) ;
    output[offset] = features->contrast[outputindex[col]] ;

    outputindex[row]++ ;
    offset =  mxCalcSingleSubscript(plhs[0], 2, outputindex) ;
    output[offset] = features->correlation[outputindex[col]] ;

    outputindex[row]++ ;
    offset =  mxCalcSingleSubscript(plhs[0], 2, outputindex) ;
    output[offset] = features->variance[outputindex[col]] ;

    outputindex[row]++ ;
    offset =  mxCalcSingleSubscript(plhs[0], 2, outputindex) ;
    output[offset] = features->IDM[outputindex[col]] ;

    outputindex[row]++ ;
    offset =  mxCalcSingleSubscript(plhs[0], 2, outputindex) ;
    output[offset] = features->sum_avg[outputindex[col]] ;

    outputindex[row]++ ;
    offset =  mxCalcSingleSubscript(plhs[0], 2, outputindex) ;
    output[offset] = features->sum_var[outputindex[col]] ;

    outputindex[row]++ ;
    offset =  mxCalcSingleSubscript(plhs[0], 2, outputindex) ;
    output[offset] = features->sum_entropy[outputindex[col]] ;

    outputindex[row]++ ;
    offset =  mxCalcSingleSubscript(plhs[0], 2, outputindex) ;
    output[offset] = features->entropy[outputindex[col]] ;

    outputindex[row]++ ;
    offset =  mxCalcSingleSubscript(plhs[0], 2, outputindex) ;
    output[offset] = features->diff_var[outputindex[col]] ;

    outputindex[row]++ ;
    offset =  mxCalcSingleSubscript(plhs[0], 2, outputindex) ;
    output[offset] = features->diff_entropy[outputindex[col]] ;

    outputindex[row]++ ;
    offset =  mxCalcSingleSubscript(plhs[0], 2, outputindex) ;
    output[offset] = features->meas_corr1[outputindex[col]] ;

    outputindex[row]++ ;
    offset =  mxCalcSingleSubscript(plhs[0], 2, outputindex) ;
    output[offset] = features->meas_corr2[outputindex[col]] ;

    outputindex[row]++ ;
    offset =  mxCalcSingleSubscript(plhs[0], 2, outputindex) ;
    output[offset] = features->max_corr_coef[outputindex[col]] ;
  }

    

  /*
    Memory clean-up.
  */
  for(i=0; i



Copyright ©1999 Michael V. Boland
1999-09-18