MultiStackreg plugin don´t work

Hi, I have downloaded the plugin MultiStackreg, but when I push done the plugin it does not work. Anyone know what is problem or know another way to get it? Thank you!

1 Like

Ji @biologa,

would mind sharing some details? What images were you trying to process and what was the error message? We can then easier guess what might have gone wrong :wink:

Thanks!

Cheers,
Robert

Hi Robert, I have attached example images:

I have a file with time lapse DIC images, and other file with Z-stack and time lapse GFP images. I have adquire time lapse DIC image as a reference image at same time that I adquire GFP images. When I analyze DIC image I can see they are moving!. I would like align DIC images and do the same with Zstack GFP image. I need analyze movement (average velocity) of GFP spots, but I can not if my images are not align.
I have try to open my images and run plugin. I select my time-lapse DIC image in Stack1, and select use as reference in Action1 , after my time-lapse GFP Z-stack image and align to first stack action 2, Transformation Rigidy Body and press OK, and then it say “stack sizes must match”, but if I do GFP max proyection of GFP image the result is awful. How can you align these images?
Thank you!

1 Like

Hi @biologa,

some time ago I wrote a quick and dirty script for a task like that, which uses StackReg (BIG-EPFL update site) instead of MulitStackReg. The translations are empirically determined from the aligned brightfield series and applied to the fluorescent image. It handles multichannel data and z-stacks, although it does not account for possible drifts in the stack. No claim that it is an elegant solution, but on your test sample it seems to work fine.

I hope it helps.

// determine drift in a brightfield time series and
// apply shift parameters to corresponding fluorescent time series

// Dependencies: StackReg plugin (BIG-EPFL update site)

// version 2:  generalize the input images and handle any number of fluorescent channels
// version 3:  handle z-stacks

n = nImages;

if (n!=2) {
	exit("Two images required!");
}

listImages = newArray(n);
for (i=1; i<=n; i++) {
	selectImage(i);
	listImages[i-1] = getTitle();
}

Dialog.create("Reference image");
Dialog.addChoice("Reference image for alignment", listImages);
Dialog.show();

refTitle = Dialog.getChoice();

for (i=1; i<=n; i++) {
	if (listImages[i-1] != refTitle) {
		fluoTitle = listImages[i-1];
	}
}
selectImage(refTitle);
bfID = getImageID();
selectImage(fluoTitle);
fluoID = getImageID();

selectImage(bfID);
oldTitle = getTitle();
idx = lastIndexOf(oldTitle, ".");
if (idx>0){
	newTitle = substring(oldTitle, 0, idx)+"_aligned"+substring(oldTitle, idx);
} else {
	newTitle = oldTitle+"_aligned";	
}

ns = nSlices;

// align brightfield image
cs = ns/2;
setSlice(cs);
run("StackReg", "transformation=Translation");

// determine alignment parameters on brightfield image
h = getHeight();
w = getWidth();
dxArray = newArray(ns);
dyArray = newArray(ns);
for (n=1; n<=ns; n++) {
	setSlice(n);
	dx = 0;
	dy = 0;
	//positive x
	stop = false;
	for (x=0; (x<w) && (!stop); x++ ){
		if (getPixel(x,0)==0 && getPixel(x,h-1)==0) {
			dx=dx+1;
		} else {
			stop = true;
		}
	}
	//negative x
	stop = false;
	if (dx==0) {
		for (x=w-1; x>=0 && !stop; x-- ){
			if (getPixel(x,0)==0 && getPixel(x,h-1)==0) {
				dx=dx-1;
			} else {
				stop = true;
			}
		}
	}
	//positive y
	stop = false;
	for (y=0; (y<h) && (!stop); y++ ){
		if (getPixel(0,y)==0 && getPixel(w-1,y)==0) {
			dy=dy+1;
		} else {
			stop = true;
		}
	}
	//negative y
	stop = false;
	if (dy==0) {
		for (y=h-1; y>=0 && !stop; y-- ){
			if (getPixel(0,y)==0 && getPixel(w-1,y)==0) {
				dy=dy-1;
			} else {
				stop = true;
			}
		}
	}
	dxArray[n-1] = dx;
	dyArray[n-1] = dy;
}
rename(newTitle);



// apply translations to fluorescence images
selectImage(fluoID);
oldTitle = getTitle();
idx = lastIndexOf(oldTitle, ".");
if (idx>0){
	newTitle = substring(oldTitle, 0, idx)+"_aligned"+substring(oldTitle, idx);
} else {
	newTitle = oldTitle+"_aligned";	
}

Stack.getDimensions(width, height, channels, slices, frames);
for (f=1; f<=frames; f++) {
    dx = dxArray[f-1];
    dy = dyArray[f-1];
	for (c=1; c<=channels; c++) {
		for (s=1; s<=slices; s++) {
			Stack.setFrame(f);
			Stack.setChannel(c);
			Stack.setSlice(s);
			run("Translate...", "x="+dx+" y="+dy+" interpolation=None slice");
		}
	}
}
rename(newTitle);
if (channels>1) {
	run("Make Composite");	
}
1 Like

Hi gcardone,
Thank you for your help!. I’m trying to follow the scrip you sent me, but I don’t have any programming experience and I find it difficult to understand it. I open my 2 images (DIC time lapse and fluorescence time lapse + zstack), and open ImageJ/Plugins / Macro / Record, copy your instructions and create macro. Run. And then following message appears: “Two images required!”.
I can see in your scrip:
if (n!=2) {
exit(“Two images required!”);
}

What does that mean? What images do I have to open?What do I have to do to continue the alignment?

Thank you for all!!

1 Like

Hi @biologa,

your procedure seems correct, however the message should appear only if there are more (or less) than two images currently open. When I open your two images, I get the following dialog window, where I can select the brightfield image to use for determining the alignment and to apply it to the fluorescent stack.

image

Please make sure you only have those two images open.

Giovanni

1 Like

Hi gcardone,
You were right. I had not realized that I had another image open! I apologize for any inconvenience. Thank you for your script, it work fine!! Now I trust more in my images analysis.Thank you again.

1 Like

Hi gcardone, I am writing a description of the processing of my images in which I used the script that you gave me. What would be the most appropriate way to describe it? is it necessary to put more information about you? (do you continue working in Max Planck of Biochemistry?)

“To correct for possible small displacements of the microscope stage during the time lapse, GFP images were aligned using DIC images as reference (script of Giovanni Cardone, available upon request)”

1 Like

Hi @biologa
I only read now your message…
Yes, I still work at the Max Planck Institute of Biochemistry. And just a mention in the acknowledgements would be more than fine.

1 Like