turboreg stack transformation
Posted by Tony Lien on
URL: http://imagej.273.s1.nabble.com/turboreg-stack-transformation-tp3697915.html
Hello ImageJ scientists,
I need to do image registration on a series of reasonably static movies.
There is very little movement within each movie, but the registration drifts
slightly when comparing movies to each other. I found the TurboReg plugin
to work well for restoring the proper registration, but I am having some
problems. What I am trying to do is write a macro that will:
1. Take average z-projection of each movie, set one as the "target", and
compute affine transforms of each z-projection to the target. Thus each
movie gets one transform.
2. For each movie, apply the computed transform to every frame of the
movie.
#1 is easy enough to do with TurboReg and the parameters of the transforms
are saved by TurboReg in the form of landmark coordinates.
To implement #2, I call turboReg in the "transform" mode and load the source
and target landmark coordinates from the registration performed in #1. This
does not work on a stack however, so I am doing it frame by frame.
Unfortunately the whole process is quite slow and I suspect it might be due
to the constant redrawing of windows and all the "duplicate" calls. Is
there a way I can improve the speed? I don't have much experience with
macro programming in ImageJ so any help is appreciated. The code for my
function is at the end of the message.
-Tony Lien
function registerStack(originalStackID, width, height, sourceX1, sourceY1,
sourceX2, sourceY2, sourceX3, sourceY3, targetX1, targetY1, targetX2,
targetY2, targetX3, targetY3) {
run("Conversions...", " "); //don't re-scale when converting to 16bit
numSlices = nSlices;
for(i=1; i <=numSlices; i++) { //for each slice
selectImage(originalStackID);
setSlice(i);
run("Duplicate...", "title=currentFrame"); //get the current slice
run("TurboReg ", "-transform -window currentFrame " + width + " " +
height + " " + "-affine " + sourceX1 + " " + sourceY1 + " " + targetX1 + " "
+ targetY1 + " " + sourceX2 + " " + sourceY2 + " " + targetX2 + " " +
targetY2 + " " + sourceX3 + " " + sourceY3 + " " + targetX3 + " " +
targetY3 + " -showOutput"); //run turboReg transform
rename("turboRegOutput");
run("Duplicate...", "title=registered"); //get the result
run("16-bit");
if(i == 1) { //if this is the first slice, start the "registeredStack"
run("Duplicate...", "title=registeredStack");
selectWindow("registered");
close();
} else { //otherwise, concatenate the result with the growing
"registeredStack"
run("Concatenator ", "stack1=registeredStack stack2=registered
title=registeredStack");
}
selectWindow("currentFrame"); //close unneeded windows
close();
selectWindow("turboRegOutput");
close();
}
selectWindow("registeredStack");
}