TrakEM2; making a zoom in Video

Hi,

I want to make a zoom in video of a single (2D) EM-dataset, I found this script:
http://imagej.1557.x6.nabble.com/Plugin-for-a-zooming-movie-td5001825.html

I changed line “44” as described by Stephan Saalfeld, changed the language to BeanShell and made a rectange ROI, then pressed “run”.
But I get the following error message:

Sourced file: null : Attempt to resolve method: preConcatenate() on undefined variable or class name: test : at Line: 71 : in file: <unknown file> : test .preConcatenate ( ats )

Perhaps someone knows how to fix this problem?

Here, the script that I used (modified version):

import java.awt.geom.*;
import ij.*;
import ini.trakem2.display.*;

roi = IJ.getImage().getRoi();
box = roi.getBounds();
tx = box.x + box.width / 2;
ty = box.y + box.height / 2;
scale = Math.min( 1.0, 1280.0 / box.width );

int l = 372 * 3;

/* Backup affine transforms */
layer = Display.getFrontLayer();
layer.getParent().addTransformStep( layer );

/* Block user GUI input */
layer.getProject().setReceivesInput( false );

double barSize( imp, int maxPixelLength )
{
	c = imp.getCalibration();
	double pixelWidth = c.pixelWidth;
	for ( int pt = 2; ; --pt )
	{
		double pe = Math.pow( 10, pt );
		for ( int b = 10; b > 1; b -= 1 )
		{
			double l = b * pe;
			if ( l / pixelWidth < maxPixelLength )
				return l;
		}
	}
}

try {

	stack = null;
	impStack = null;
	li = 0;
	lid = 1;
	double pixelScale = 1.0;

	layer = layer.getParent().getLayer( 0 );

	for ( var i = 0; i < l; ++i )
	{
//		layer = layer.getParent().getLayer( li / 3 );
		layer = Display.getFront().getLayer();
		if ( li == 0 )
			lid = 1;
		if ( li == layer.getParent().getLayers().size() * 3 - 1 )
			lid = -1;
		li += lid;
		
		double a = 0.5 - Math.cos( 2 * Math.PI * i / l ) / 2;
		
		ats = new AffineTransform();
		atr = new AffineTransform();
		att = new AffineTransform();

		double s = 1.0 + a * 0.009;
		pixelScale *= s;

		ats.scale( s, s );
		atr.rotate( a * 0.0025 );
		att.translate( tx, ty );
		atti = att.clone();
		atti.invert();

		test.preConcatenate(ats);
		
//		d = Display.getFront().getLayerSet().getDisplayables( Patch.class );
		d = layer.getDisplayables( Patch.class );
//		d = new ArrayList();
		for ( var j = 0; j < d.size(); ++j )
		{
			var atd = d.get( j ).getAffineTransform();
			
			atd.preConcatenate( atti );
			atd.preConcatenate( ats );
			atd.preConcatenate( atr );
			atd.preConcatenate( att );
			
			d.get( j ).setAffineTransform( atd );
//			IJ.log( atd.toString() );
		}
		IJ.log( i + " " + scale * test.getScaleX() + " " + scale * test.getScaleY() );
		IJ.log( i + "");

 		Display.repaint();
		Thread.sleep( 100 );
		
		imp = layer.getProject().getLoader().getFlatImage(
				layer,
				roi.getBounds(),
				scale,
				-1,
				ImagePlus.GRAY8,
				Patch.class,
				layer.getDisplayables( Patch.class ),
				true,
				new Color(209, 209, 209) );
		c = imp.getCalibration();
		c.pixelWidth = c.pixelHeight = c.pixelWidth / pixelScale;
		imp.setCalibration( c );
		double b = barSize( imp, 200 );		
		IJ.run( imp, "Scale Bar...", "width=" + b + " height=8 font=19 color=Black background=White location=[Lower Right]" );
		if ( impStack == null )
		{
			stack = new ImageStack( imp.getWidth(), imp.getHeight() );
			stack.addSlice( "", imp.getProcessor() );
			impStack = new ImagePlus( "movie", stack );
			impStack.show();
		}
		else
		{
			stack.addSlice( "", imp.getProcessor() );
			impStack.setStack( impStack.getTitle(), stack );
			impStack.setSlice( stack.getSize() );
			impStack.updateAndDraw();
		}
		layer.getParent().addTransformStep( layer );
	
	}
} catch (error) {
	IJ.log(error.toString());
}

/* Restore affine transforms */
layer.getParent().undoOneStep();

/* Enable user GUI input */
layer.getProject().setReceivesInput( true );

Display.repaint();

Unfortunately

Please undo the change to line 44, this is a different version of that script than what the forum thread pointed to. I should have added the commit hash.

1 Like

Hi Stephan,

thank you, it works perfect now. I’ll try a bit using the parameters to adjust
ROI etc.