-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmake_mov.py
More file actions
33 lines (22 loc) · 1.07 KB
/
make_mov.py
File metadata and controls
33 lines (22 loc) · 1.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import os, sys
import numpy as np
import cv2
'''This script creates a composite MOVIE from a directory full of images.
In order to run this, you must pip install opencv-python (cv2):
python make_mov.py INPUT_DIR output_file.avi'''
# input_dir is the directory containing the tif files along the z axis
# output_file is the composite movie (avi format; can convert to .mov by opening in quicktime)
# credit: stackoverflow (https://stackoverflow.com/questions/44947505/how-to-make-a-movie-out-of-images-in-python)
def create_movie(image_folder, video_name):
images = [img for img in os.listdir(image_folder) if img.endswith(".tif")] # originally png
frame = cv2.imread(os.path.join(image_folder, images[0]))
height, width, layers = frame.shape
video = cv2.VideoWriter(video_name, 0, 1, (width,height))
for image in images:
video.write(cv2.imread(os.path.join(image_folder, image)))
cv2.destroyAllWindows()
video.release()
if __name__ == "__main__":
input_dir = sys.argv[1]
output_file = sys.argv[2]
create_movie(input_dir, output_file)