How to interleave two videos through Jython interface?

fiji
imagej

#1

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?


#2

Good day,

does this

IJ.run("Interleave", "stack=Untitled stack=Untitled_turned");

help?

Interleave isn’t part of plain ImageJ-1.

Regards

Herbie


#3

Dear @komodovaran,

It is part of Fiji: Stack_Interleaver.

Best,
Stefan


#4

Thanks @stelfrich

…How do I import it though?

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


#5

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 “Stack_Interleaver.java” 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”.

HTH

Regards

Herbie


#6
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
outputImp.show(); # Show the new image

#7

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