TurboReg Macro RGB Stack

Dear all,

I want to align a template to several images in a batch mode using a macro (which will involve several other steps in image processing). When I use the Plugin>TurboReg and do all of the settings manually, it works like a charm. However, when I want to do a macro for it, it asks me to transform my source image into a greyscale image, while it works perfectly as a RGB Stack for the manual Plugin. Has anyone had this problem before and could tell me how to solve it? I need the image to stay RGB since I want to extract the different channels to get them as ROIs in my target image!


selectWindow("SpinalCord_C5_Mask_RGB.tif");
run("RGB Stack");
imgName_source=getTitle();
var S_x1 = 1044;        // upper middle
var S_y1 = 10;
var S_x2 = 1044;            // Central Canal
var S_y2 = 708;
var S_x3 = 90;            // left GM
var S_y3 = 1096;
selectWindow("MG4_01_s1z1.tif");
imgName_target=getTitle();
setTool("point");
waitForUser("Set 1 Point at upper point of midline (end of tissue)");
run("Measure");
T_x1 = round(getResult("X"));
T_y1 = round(getResult("Y"));
waitForUser("Set 1 Point at central canal");
run("Measure");
T_x2 = T_x1;
T_y2 = round(getResult("Y"));
waitForUser("Set 1 Point at outer boundary of GM (ventral part)");
run("Measure");
T_x3 = round(getResult("X"));
T_y3 = round(getResult("Y"));
run("Clear Results");


selectWindow(imgName_target);
width = getWidth();
height = getHeight();

TurboReg(imgName_source, imgName_target);

// ------ function definitions -------

function TurboReg(imgName_source, imgName_target)
{    setBatchMode(true);

run("TurboReg ",
    "-align " // Register the two images that we have just prepared.
    + "-window " + imgName_source + " "// Source (window reference).
    + "0 0 " + (width - 1) + " " + (height - 1) + " " // No cropping.
    + "-window " + imgName_target + " "// Target (window reference).
    + "0 0 " + (width - 1) + " " + (height - 1) + " " // No cropping.
    + "-affine " // 
    + S_x1 + " " + S_y1 + " " // Source translation landmark.        // landmark by getselectioncoordinate
    + T_x1 + " " + T_y1 + " " // Target translation landmark.
    + S_x2 + " " + S_y2 + " " // Source translation landmark.        // landmark by getselectioncoordinate
    + T_x2 + " " + T_y2 + " " // Target translation landmark.
    + S_x3 + " " + S_y3 + " " // Source translation landmark.        // landmark by getselectioncoordinate
    + T_x3 + " " + T_y3 + " " // Target translation landmark.
    + "-showOutput"); // In case -hideOutput is selected, the only way to
    // retrieve the registration results is by the way of another plugin.

setBatchMode(false);
}