How to interleave two videos through Jython interface?

Tags: #<Tag:0x00007fd69c878d48>


In the GUI there’s a function for this in Stacks > Tools > Interleave

But I can’t find any references for this in the java API documentation.

Does anyone know how to?


Good day,

does this"Interleave", "stack=Untitled stack=Untitled_turned");


Interleave isn’t part of plain ImageJ-1.




Dear @komodovaran,

It is part of Fiji: Stack_Interleaver.



Thanks @stelfrich

…How do I import it though?

If I have two imps called v1 and v2, and I run
interleaved ="Interleave", "stack=v1 stack=v2");
it returns “This plugin requires two stacks that are the same data type”.


The problem on my side is that I don’t use Fiji but plain ImageJ and I don’t know about Jython.

But perhaps it may help to try the following macro example code. In order to make it work with plain ImageJ, I compiled the source code “” and put the resulting plugin-file “Stack_Interleaver.class” in the plugins directoy of ImageJ.

// example macro for ImageJ-1
newImage("v1", "8-bit ramp", 128, 128, 5);
newImage("v2", "8-bit ramp", 128, 128, 5);
run("Rotate 90 Degrees Right");
run("Stack Interleaver", "stack_1=v1 stack_2=v2");

Paste the above macro code to an empty macro window (Plugins >> New >> Macro) and run it.

This macro works as expected and the resulting stack is titled “Combined Stacks”.




import Stack_Interleaver;

foo = Stack_Interleaver(); # works

A more complete example:

import Stack_Interleaver;
from ij import WindowManager, ImagePlus;

interleaver = Stack_Interleaver();
imp1 = WindowManager.getImage("Stack1"); # Get first input image by name
imp2 = WindowManager.getImage("Stack2"); # Get second input image by name
stack = interleaver.interleave(imp1.getStack(), imp2.getStack()); # Interleave

outputImp = ImagePlus("Interleaved", stack); # Create a new ImagePlus from the interleaved stack; # Show the new image


Oh, didn’t know plugins could be imported like that. Thanks again. Works perfectly. :slight_smile: