日期:2014-05-20  浏览次数:20924 次

菜鸟求助!很奇怪的一段代码!
public void run( String args )
{
if ( IJ.versionLessThan( "1.37i" ) ) return;

final ImagePlus imp = WindowManager.getCurrentImage();
if ( imp == null ) { System.err.println( "There are no images open" ); return; }

GenericDialog gd = new GenericDialog( "Align stack" );
gd.addNumericField( "steps_per_scale_octave :", steps, 0 );
gd.addNumericField( "initial_gaussian_blur :", initial_sigma, 2 );
gd.addNumericField( "feature_descriptor_size :", fdsize, 0 );
gd.addNumericField( "feature_descriptor_orientation_bins :", fdbins, 0 );
gd.addNumericField( "minimum_image_size :", min_size, 0 );
gd.addNumericField( "maximum_image_size :", max_size, 0 );
gd.addNumericField( "minimal_alignment_error :", min_epsilon, 2 );
gd.addNumericField( "maximal_alignment_error :", max_epsilon, 2 );
gd.addNumericField( "inlier_ratio :", min_inlier_ratio, 2 );
gd.addNumericField( "background_color :", bg, 2 );
gd.addChoice( "interpolation_scheme :", schemes, schemes[ scheme ] );
gd.addCheckbox( "upscale_image_first", upscale );
gd.addCheckbox( "display_correspondences", show_info );
gd.showDialog();
if (gd.wasCanceled()) return;

steps = ( int )gd.getNextNumber();
initial_sigma = ( float )gd.getNextNumber();
fdsize = ( int )gd.getNextNumber();
fdbins = ( int )gd.getNextNumber();
min_size = ( int )gd.getNextNumber();
max_size = ( int )gd.getNextNumber();
min_epsilon = ( float )gd.getNextNumber();
max_epsilon = ( float )gd.getNextNumber();
min_inlier_ratio = ( float )gd.getNextNumber();
bg = ( double )gd.getNextNumber();
scheme = gd.getNextChoiceIndex();
upscale = gd.getNextBoolean();
if ( upscale ) scale = 2.0f;
else scale = 1.0f;
show_info = gd.getNextBoolean();

Affine a = new Affine();

int ischeme = Affine.NEAREST;
switch ( scheme )
{
case 0:
ischeme = Affine.NEAREST;
break;
case 1:
ischeme = Affine.LINEAR;
break;
case 2:
ischeme = Affine.CUBIC;
break;
case 3:
ischeme = Affine.BSPLINE3;
break;
case 4:
ischeme = Affine.OMOMS3;
break;
case 5:
ischeme = Affine.BSPLINE5;
break;
}

ImageStack stack = imp.getStack();
ImageStack stackAligned = new ImageStack( stack.getWidth(), stack.getHeight() );

float vis_scale = 256.0f / imp.getWidth();
// float vis_scale = 1024.0f / imp.getWidth();
ImageStack stackInfo = null;
ImagePlus impInfo = null;

if ( show_info )
stackInfo = new ImageStack(
Math.round( vis_scale * stack.getWidth() ),
Math.round( vis_scale * stack.getHeight() ) );

stackAligned.addSlice( null, stack.getProcessor( 1 ) );
ImagePlus impAligned = new ImagePlus( "Aligned 1 of " + stack.getSize(), stackAligned );
impAligned.show();

ImageProcessor ip1;
ImageProcessor ip2;
ImageProcessor ip3 = null;

Vector< Feature > fs1;
Vector< Feature > fs2;

ip2 = stack.getProcessor( 1 ).convertToFloat();

AffineTransform at = new AffineTransform();

FloatArray2DSIFT sift = new FloatArray2DSIFT( fdsize, fdbins );

FloatArray2D fa = ImageArrayConverter.ImageToFloatArray2D( ip2 );
Filter.enhance( fa, 1.0f );

if ( upscale )
{
FloatArray2D fat = new FloatArray2D( fa.width * 2 - 1, fa.height * 2 - 1 ); 
FloatArray2DScaleOctave.upsample( fa, fat );
fa = fat;
fa = Filter.computeGaussianFastMirror( fa, ( float )Math.sqrt( initial_sigma * initial_sigma - 1.0 ) );