Skip to content

Instantly share code, notes, and snippets.

@ximeg
Created January 23, 2024 15:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ximeg/2ba1957653d08d5ccc09d1d4692d54b8 to your computer and use it in GitHub Desktop.
Save ximeg/2ba1957653d08d5ccc09d1d4692d54b8 to your computer and use it in GitHub Desktop.
Create highly compressed MP4 movie from a TIFF stack with scalebar and a timestamp
Dialog.create("pTIRF movie creator");
Dialog.addNumber("Time interval between frames", 500, 0, 6, "ms");
Dialog.addNumber("Brightness/contrast: black level", 400, 0, 6, "counts");
Dialog.addNumber("Brightness/contrast: white level", 1000, 0, 6, "counts");
Dialog.addNumber("Time point of injection", 10, 1, 6, "s");
Dialog.show();
exp_time = Dialog.getNumber() / 1000.0;
low = Dialog.getNumber();
high = Dialog.getNumber();
injection = -Dialog.getNumber();
setMinAndMax(low, high);
run("8-bit");
run("Set Scale...", "distance=1152 known=250 unit=µm");
run("Scale Bar...", "width=50 height=20 thickness=8 font=32 color=White background=Black location=[Lower Right] horizontal bold label");
run("Time Stamper", "starting=injection interval=exp_time x=10 y=10 font=50 decimal=1 anti-aliased or=s");
run("Image Sequence... ", "format=TIFF name=img");
Dialog.create("pTIRF movie creator");
Dialog.addString("Now invoke ffmpeg with these arguments", "./ffmpeg -i frames/img%04d.tif -c:v libx264 -crf 30 <movie name>.mp4", 60)
Dialog.show();
@ximeg
Copy link
Author

ximeg commented Jan 23, 2024

Open a TIFF stack in ImageJ. Figure out what brightness/contrast setting you want to use and remember the lower/upper limits.
Then run this script, plug in the numbers, and it will save individual annotated 8-bit frames in a folder of your choice.

After that, you can run ffmpeg from the command line to create an MP4 file from these exported frames.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment