Exemple #1
0
INT32 Module3(INT16 *speech_samples, const UINT32 file_length, INT32 *hosm_Nparams, 
			  FLOAT *hosm_params, FLOAT SubjectiveMOS)
{		
	typInputParameter InParameter;   
	typChannel	channel;             
	INT32		RetVal=0;              
	FLOAT       *ReferenceData=NULL;
	FLOAT       fHOSM_params[NR_OF_RESULTS];

	SubjectiveMOS = 0;
	ReferenceData = (FLOAT *)calloc(file_length, sizeof(FLOAT));
	if(ReferenceData == 0)
		return -1;

	channel.file[REFER_FILE].Fptr = 0;
	InParameter.MOS = MAX_MOS_VALUE;                                    
	                                                          
	vfloat(speech_samples, 1,ReferenceData, 1, file_length);  
	InParameter.ReferData = ReferenceData;                    
	                                                          
	InParameter.Frequency     = 8;                            
	channel.file[REFER_FILE].filetype = 3;                    
	                                                          
	RetVal = initStructures(&InParameter, &channel);          

	channel.file[REFER_FILE].FileSize = file_length*2;
	channel.file[REFER_FILE].start = 0;
	channel.file[REFER_FILE].stop  = channel.file[REFER_FILE].FileSize;
	
	RetVal = hosm (&InParameter, &channel, fHOSM_params);    

	vmov(fHOSM_params, 1, hosm_params, 1, NR_OF_RESULTS);

	*hosm_Nparams = (INT32) NR_OF_RESULTS;

	free(ReferenceData);
	
	return RetVal;
}
Exemple #2
0
/**********************************    T2Fit     ************************************
*   This is where the work will be done
*************************************************************************************/
OSErr T2Fit( FILE *inFile, FILE *outFile )
{
	OSErr   error = noErr;
	long    theTimePt;
	int     i;
	float   *inData, *outData, *T2, *intercept, *chi2, *Smoother;
	long    VolSize, outVolBytes, inVolBytes;
	float	te[ u.inIm.dim.timePts ];
	unsigned char *theMask;
	short   rules;

	u.NumOutImages   = 0;
	VolSize          = u.inIm.dim.isoX * u.inIm.dim.isoY * u.inIm.dim.n_slices;
	inVolBytes       = VolSize * get_datasize( T_FLOAT );
	outVolBytes      = VolSize * get_datasize( u.outIm.data_type );
	T2               = (float *)ck_malloc( inVolBytes,  "Storage for R2" );
	intercept        = (float *)ck_malloc( inVolBytes,  "Storage for intercept" );
	chi2             = (float *)ck_malloc( inVolBytes,  "Storage for chi2"  );
	outData          = (float *)ck_malloc( outVolBytes, "Storage for output data" );
	inData           = (float *)ck_malloc( inVolBytes * u.inIm.dim.timePts,  "Storage for input data" );
	theMask          = (unsigned char*)ck_malloc( VolSize * sizeof( unsigned char ),  "Storage for theMask" );
	if( u.Smooth ) {
		Smoother = (float *)ck_malloc( inVolBytes * 2, "Storage for smoothing" );
	}

// load up te vector
	if( u.Verbose ) {
		printf( "TE: " );
	}
	for( i=0; i<u.inIm.dim.timePts; i++ ) {
		fscanf(u.TEFile ,"%f", &te[i]);
		if( u.Verbose ) {
			printf( "%0.3f ", te[i] );
		}
	}
	
// We will do everything in float
	SetImDatatype( &u.inIm, T_FLOAT );

//	Load all of the images into a single matrix
	for ( theTimePt = 0; theTimePt < u.inIm.dim.timePts; theTimePt++ ) {
		error = GetSelectedVolume( inFile, &u.inIm, inData+theTimePt*VolSize, theTimePt );
		RETURNONERROR;
		if( u.Smooth ) {
			vmov( inData+theTimePt*VolSize, 1, Smoother, 1, VolSize, T_FLOAT );
			error = gaussSmooth( &u.inIm, Smoother, inData+theTimePt*VolSize, &u.xSmooth, &u.ySmooth, &u.zSmooth );
			RETURNONERROR;

		}
		RETURNONERROR;
	}
	

// threshold on first images
	if( u.autoThresh ) {
		error = autoMask( inData, theMask, VolSize, &u.threshold, &u.nonNoise, T_FLOAT );
		RETURNONERROR;
	} else if( u.threshold != 0 ) {
		u.nonNoise = ThreshMask( inData,  theMask, VolSize, &u.threshold, T_FLOAT );
	} else {
		u.nonNoise = VolSize;
	}

	error = CalcT2( &u.inIm, inData, theMask, te, T2, intercept, chi2 ); RETURNONERROR;

	free( inData );

	error = type_convert( T2, T_FLOAT,
						  outData, u.outIm.data_type,
						  VolSize, &u.outIm.theMinf, &u.outIm.theMaxf, &rules );
	if( error && error != CONVERSION_ERROR ) return error;
	error = ck_fwrite( outData, 1, outVolBytes, outFile );
	u.NumOutImages++;
	RETURNONERROR;

	error = type_convert( intercept, T_FLOAT,
						  outData, u.outIm.data_type,
						  VolSize, &u.outIm.theMinf, &u.outIm.theMaxf, &rules );
	if( error && error != CONVERSION_ERROR ) return error;
	error = ck_fwrite( outData, 1, outVolBytes, outFile );
	u.NumOutImages++;
	RETURNONERROR;

	if( u.Smooth ) {
		free( Smoother );
	}

// Make R2 image
	for( i=0; i<VolSize; i++ ) {
		if( T2[i] !=0 ) {
			T2[i] = 1/T2[i];
		}
	}
	error = type_convert( T2, T_FLOAT,
						  outData, u.outIm.data_type,
						  VolSize, &u.outIm.theMinf, &u.outIm.theMaxf, &rules );
	if( error && error != CONVERSION_ERROR ) return error;
	error = ck_fwrite( outData, 1, outVolBytes, outFile );
	u.NumOutImages++;
	RETURNONERROR;
	error = type_convert( chi2, T_FLOAT,
						  outData, u.outIm.data_type,
						  VolSize, &u.outIm.theMinf, &u.outIm.theMaxf, &rules );
	if( error && error != CONVERSION_ERROR ) return error;
	error = ck_fwrite( outData, 1, outVolBytes, outFile );
	u.NumOutImages++;
	RETURNONERROR;

	fprintf( u.ProcFile, "Output file contains maps of T2, M0, R2 and chi2\n" );
	fprintf( u.ProcFile, "TE's used: " );
	for( i=0; i<u.inIm.dim.timePts; i++ ) {
		fprintf( u.ProcFile,  "%0.3f ", te[i] );
	}
	fprintf( u.ProcFile, "\n" );
	fprintf( u.ProcFile, "Input data were intensity thresholded at %0.3f\n", u.threshold ); 
	fprintf( u.ProcFile, "Non-Noise Points:\t%ld\n", u.nonNoise );
	if( u.Smooth ) {
		fprintf( u.ProcFile, "Input images were smoothed with a width of %0.3f mm in x, %0.3f mm in y and %0.3f mm in z\n", 
			u.xSmooth, u.ySmooth, u.zSmooth );
	}
	fprintf( stderr, "Output file contains maps of T2, M0, R2 and chi2\n" );
	fprintf( stderr, "TE's used: " );
	for( i=0; i<u.inIm.dim.timePts; i++ ) {
		fprintf( stderr,  "%0.3f ", te[i] );
	}
	fprintf( stderr, "\n" );
	fprintf( stderr, "Input data were intensity thresholded at %0.3f\n", u.threshold ); 
	fprintf( stderr, "Non-Noise Points:\t%ld\n\n", u.nonNoise );
	if( u.Smooth ) {
		fprintf( stderr, "Input images were smoothed with a width of %0.3f mm in x, %0.3f mm in y and %0.3f mm in z\n", 
			u.xSmooth, u.ySmooth, u.zSmooth );
	}
	free( theMask );
	free( outData );
	free( chi2 );
	free( intercept );
	free( T2 );

	return error;
}