Execution efficiency: run("Next Slice [>]")

Dear forum,

I recently changed a macro of mine so it would work on win 32bit machines as well. Due to the smaller available memory I decided to use virtual stack.

In my macro I implemented a function in which the user can move to the next slice on two opened (virtual) stacks (before and after images).
I key binded it to the keys [n] and [b] : next slice and previous slice.

Using a normal stack both stacks move to the next (or previous) slice even if you hold the key for several seconds.
Using virtual stacks the stacks get misaligned after a few seconds. I tried to use a wait function but even if I set the value pretty high (100ms) they got misaligned.

Do you have any suggestions how I could tackle that problem?

The stacks I need to browse through for manual registration are about 250 to 500 slices big.

Here is my code:

	selectImage(stack1);
		wait(50);
		run("Next Slice [>]");
	selectImage(stack2);
		wait(50);
		run("Next Slice [>]");		
}

macro "previous slice [b]" {
	selectImage(stack1);
		wait(50);
		run("Previous Slice [<]");
	selectImage(stack2);
		wait(50);
		run("Previous Slice [<]");
		
		
}

I guess it is correlated to image size (which is about 2-5 mb per slice).

Best Tobias

I have no idea what that may be, but here is some shot in the dark: how long does it take to load an image from disk in your setup?
I would also put a waiting after the next/previous command to see if you can let the process complete.

Without looking into the VirtualStack code I can only guess that this occurs because the virtual stack image is loaded in an extra thread which causes the misalignment with two stacks.

However, why not introduce a counter variable and then select the slice (counter) of both stacks:

setSlice(counter);

1 Like

I’m not sure how to measure the time between loading, but on my machine it is loaded within ms.

I tried to put an wait after the command, but then the misalignment is just switching the stack… so stack two is ahead of stack one.

But thanks anyways for your suggestion :slight_smile:

I’ll give this a try!! A counter wouldn’t get confused I hope :slight_smile:

Just for completeness (which I’ve forgotten).

You can also synchronize two or more stacks with the ImageJ command “Analyze->Tools->Synchronize Windows” and then use the arrow keys to navigate through the slices, see:

That is just marvelous :slight_smile: Thank you @Bio7