///////////////////////////////////////////////////////////////////// // (c) Gatan Inc. ///////////////////////////////////////////////////////////////////// // This script performs data binning of a 3D image using the slice3 command. // Voxel intensities of a [bin x bin x bin] volume are summed into a single voxel. ////////////////////////////////////////////////////////////////////// // last modified 08-August-2014 BS image img if ( !GetFrontImage( img ) ) exit(0) // Exit script if no front-image found if ( 3 != ImageGetNumDimensions( img ) ) exit(0) // Exit script if the image is not 3D // Ask user to provide a interger number for binning. // Refuse entries which are no integers or <=0 // Exit script if user clicks the cancel button number bin=0 while( (0>=bin) || ( 0 != mod(bin,1) ) ) { if ( !GetNumber("Enter binning factor as positive integer number.", round(bin), bin ) ) exit(0) } number width,height,depth Get3DSize( img, width, height, depth ) // Check that binning is smaller than any image dimension and exit script // with an error dialog if not. if ( ( bin > width ) || ( bin > height ) || ( bin > depth ) ) Throw( "Binning bigger than image dimension." ) // Create a Real 4-byte image with dimensions 1/n of the input image // Note that the command expects integer values and will automatically truncate any // number to interger. Hence width/bin will be the smallest suitable number image BinImg := RealImage( "Binned ("+bin+"x)", 4 , width/bin, height/bin, depth/bin ) ShowImage( BinImg ) // Check if the binning will account for all pixels or warn the user otherwise. if ( mod(width,bin) || mod(height,bin) || mod(depth,bin) ) OKDialog( "Warning: The chosen binning will miss out some intensity. (No integer factor of width, height or depth)") // Loop over binning number in X&Y and sum dataset with accordingly extracted subdata. for ( number ix = 0; ix