| 1 |
#include <volume_io.h> |
| 2 |
|
| 3 |
int main( |
| 4 |
int argc, |
| 5 |
char *argv[] ) |
| 6 |
{ |
| 7 |
VIO_Volume volume; |
| 8 |
VIO_Status status; |
| 9 |
int x, y, z, sizes[VIO_N_DIMENSIONS]; |
| 10 |
char *input_filename, *output_filename, *history; |
| 11 |
double min_value, max_value, value, new_value, new_voxel; |
| 12 |
VIO_BOOL thresholding; |
| 13 |
|
| 14 |
if( argc < 3 ) |
| 15 |
{ |
| 16 |
print( "Usage: %s input_volume output_volume [min max new_value]\n", |
| 17 |
argv[0] ); |
| 18 |
return( 1 ); |
| 19 |
} |
| 20 |
|
| 21 |
input_filename = argv[1]; |
| 22 |
output_filename = argv[2]; |
| 23 |
|
| 24 |
if( argc == 6 ) |
| 25 |
{ |
| 26 |
(void) sscanf( argv[3], "%lf", &min_value ); |
| 27 |
(void) sscanf( argv[4], "%lf", &max_value ); |
| 28 |
(void) sscanf( argv[5], "%lf", &new_value ); |
| 29 |
thresholding = TRUE; |
| 30 |
} |
| 31 |
else |
| 32 |
thresholding = FALSE; |
| 33 |
|
| 34 |
status = input_volume( input_filename, 3, File_order_dimension_names, |
| 35 |
0, FALSE, 0.0, 0.0, |
| 36 |
TRUE, &volume, (minc_input_options *) NULL ) ; |
| 37 |
|
| 38 |
if( status != VIO_OK ) |
| 39 |
return( 1 ); |
| 40 |
|
| 41 |
/* --- convert new_value to voxel */ |
| 42 |
|
| 43 |
new_voxel = CONVERT_VALUE_TO_VOXEL( volume, new_value ); |
| 44 |
|
| 45 |
get_volume_sizes( volume, sizes ); |
| 46 |
|
| 47 |
if( thresholding ) |
| 48 |
{ |
| 49 |
for_less( x, 0, sizes[VIO_X] ) |
| 50 |
{ |
| 51 |
for_less( y, 0, sizes[VIO_Y] ) |
| 52 |
{ |
| 53 |
for_less( z, 0, sizes[VIO_Z] ) |
| 54 |
{ |
| 55 |
GET_VALUE_3D( value, volume, x, y, z ); |
| 56 |
if( value < min_value || value > max_value ) |
| 57 |
{ |
| 58 |
SET_VOXEL_3D( volume, x, y, z, new_voxel ); |
| 59 |
} |
| 60 |
} |
| 61 |
} |
| 62 |
} |
| 63 |
} |
| 64 |
|
| 65 |
history = "Converted volume to byte"; |
| 66 |
|
| 67 |
status = output_volume( output_filename, NC_BYTE, FALSE, 0.0, 255.0, |
| 68 |
volume, history, (minc_output_options *) NULL ); |
| 69 |
|
| 70 |
return( 0 ); |
| 71 |
} |