Java: convert set of tiff images to video

imagej

#1

Hello,
I need to write some peace of code that converts set of tiff images to video (avi, mp4 etc). Where can I find the example or could you help me with the issue?

Regards,
Dima


#2

Good day Dima,

first try to achieve what you want via the GUI of ImageJ (the ImageJ user guide may help) and if you are happy with the processing, do the same steps and use the macro recorder with option “Java” to record all the processing steps.

Regards

Herbie


#3

Thank you for the answer. I Converted the images to the video, and opened the recorder. There is the java code that I received:

IJ.run(“Image Sequence…”, “open=C:\Users\dima\Desktop\tifs\20171031_204102_A7_F55_FHD_Test13[1]_0000.tif sort use”);
IJ.run(imp, "AVI… ", “compression=JPEG frame=17 save=C:\Users\dima\Desktop\tifs\tifs-17.avi”);

In the second line i got compilation error because imp object wasn’t initialized.
Could you help me with it?


#4

Dima

I assume you want a plugin (Java) not a macro, although the latter would do.

In both cases you have to push the button “Create” which gives you the code.

In case of plugins, you have to save the code as file with the class name to the plugins folder of ImageJ and then compile it.

If you are happy with a macro, then you can run the macro code directly after the “Create”.

Please study the ImageJ user guide.

Regards

Herbie


#5

I will try to explain: I have to write some server API that converts tiffs to AVI. I converted the macro to Java and got following code:

ImagePlus imp = IJ.getImage();
	IJ.run("Image Sequence...", "open=C:\\Users\\dima\\Desktop\\tifs\\20171031_204102_A7_F55_FHD_Test13[1]_0000.tif sort use");
	IJ.run(imp, "AVI... ", "compression=JPEG frame=17 save=C:\\Users\\dima\\Desktop\\tifs\\tifs-17.avi");
	IJ.run("Close");
	IJ.run("Close");

After import necessary maven artifacts to my project I tried to run following code and got the message:
There are no images open.


#6

Please understand that I can’t debug your code.

If the message says “There are no images open.” then this is just what is happening, i.e. most probable you encountered a path problem.

Regards

Herbie


#7

Herbie,
I found the problem. The macro did some error in code generation. If I swap the line of sequence initialization and “IJ.getImage()” the code works.

Thank you for your time!