VIOAPI VIO_Status input_volume( VIO_STR filename, int n_dimensions, VIO_STR dim_names[], nc_type volume_nc_data_type, VIO_BOOL volume_signed_flag, VIO_Real volume_voxel_min, VIO_Real volume_voxel_max, VIO_BOOL create_volume_flag, VIO_Volume *volume, minc_input_options *options ) { VIO_Status status; VIO_Real amount_done; volume_input_struct input_info; VIO_progress_struct progress; static const int FACTOR = 1000; VIO_Real volume_min=0.0,volume_max=0.0; status = start_volume_input( filename, n_dimensions, dim_names, volume_nc_data_type, volume_signed_flag, volume_voxel_min, volume_voxel_max, create_volume_flag, volume, options, &input_info ); if( status == VIO_OK ) { initialize_progress_report( &progress, FALSE, FACTOR, "Reading Volume"); while( input_more_of_volume( *volume, &input_info, &amount_done ) ) { update_progress_report( &progress, VIO_ROUND( (VIO_Real) FACTOR * amount_done)); } if (amount_done < 1.0) { status = VIO_ERROR; } terminate_progress_report( &progress ); delete_volume_input( &input_info ); if( !volume_is_alloced( *volume ) ) { delete_volume( *volume ); *volume = NULL; status = VIO_ERROR; } } if (status == VIO_OK) { get_volume_voxel_range( *volume, &volume_min, &volume_max ); } return( status ); }
int main(int argc, char *argv[]) { int count, i,j,k, p,r,s, flag, sizes1[3],sizes2[3], sizes3[3]; VIO_Real thresh; VIO_Real mean1, std1, mean2, std2, corr, v1, v2, v3, s1, s2, s12, u,v,w, x,y,z; VIO_Status status; VIO_Volume data1, data2, mask; char *f1, *f2, *mf; if (argc<4) { print ("usage: xcorr_vol.c vol1.mnc vol2.mnc threshold [mask.mnc]\n"); exit(EXIT_FAILURE); } prog_name = argv[0]; f1 = argv[1]; f2 = argv[2]; thresh = atof(argv[3]); if (argc==5) mf = argv[4]; status = input_volume(f1, 3, default_dim_names, NC_UNSPECIFIED, FALSE, 0.0,0.0, TRUE, &data1, (minc_input_options *)NULL); if (status!=VIO_OK) { print ("Error reading %s.\n",f1); exit(EXIT_FAILURE); } status = input_volume(f2, 3, default_dim_names, NC_UNSPECIFIED, FALSE, 0.0,0.0, TRUE, &data2, (minc_input_options *)NULL); if (status!=VIO_OK) { print ("Error reading %s.\n",f2); exit(EXIT_FAILURE); } if (argc==5) { status = input_volume(mf, 3, default_dim_names, NC_UNSPECIFIED, FALSE, 0.0,0.0, TRUE, &mask, (minc_input_options *)NULL); if (status!=VIO_OK) { print ("Error reading %s.\n",mf); exit(EXIT_FAILURE); } get_volume_sizes(mask,sizes3); } else mask = (VIO_Volume)NULL; get_volume_sizes(data1,sizes1); get_volume_sizes(data2,sizes2); if (sizes1[0] != sizes2[0] || sizes1[1] != sizes2[1] || sizes1[2] != sizes2[2]) { print ("Size mismatch between %s and %s.\n",f1,f2); print ("%d,%d,%d != %d,%d,%d\n", sizes1[0],sizes1[1],sizes1[2], sizes2[0],sizes2[1],sizes2[2]); exit(EXIT_FAILURE); } get_zscore_values(data1, mask, thresh, &mean1, &std1); get_zscore_values(data2, mask, thresh, &mean2, &std2); if (std1==0.0 || std2==0.0) { print ("No standard deviation in one of %s and %s.\n",f1,f2); exit(EXIT_FAILURE); } count = 0; s1 = s2 = s12 = 0.0; for(i=0; i<sizes1[0]; i++) { for(j=0; j<sizes1[1]; j++) { for(k=0; k<sizes1[2]; k++) { flag = TRUE; if (mask != NULL) { convert_3D_voxel_to_world(data1, i,j,k, &x, &y, &z); convert_3D_world_to_voxel(mask, x,y,z, &u, &v, &w); p = VIO_ROUND(u); r = VIO_ROUND(v); s = VIO_ROUND(w); if (p>=0 && p<sizes3[0] && r>=0 && r<sizes3[1] && s>=0 && s<sizes3[2]) { GET_VALUE_3D( v3 , mask, p, r, s); if (v3 < 0.5) flag = FALSE; } else flag = FALSE; } if (flag ) { GET_VALUE_3D( v1 , data1, i, j, k); GET_VALUE_3D( v2 , data2, i, j, k); v1 = (v1 - mean1) / std1; v2 = (v2 - mean2) / std2; v1 = v1 - v2; s12 += fabs(v1); count++; } } } } if (count==0) { exit(EXIT_FAILURE); print ("No masked voxels\n"); } else { corr = s12 / count; print ("%15.12f\n",corr); exit(EXIT_SUCCESS); } }