import cv2
from PIL import Image
import os
import numpy as np
def load_tiff_images(folder_path):
images = []
for filename in sorted(os.listdir(folder_path)):
if filename.endswith(".tiff") or filename.endswith(".tif"):
img_path = os.path.join(folder_path, filename)
img = Image.open(img_path)
img = img.convert("RGB") # Convert to RGB
img = cv2.cvtColor(np.array(img), cv2.COLOR_RGB2BGR) # Convert to BGR for OpenCV
images.append(img)
return images
def create_video(images, output_path, fps=30):
if len(images) == 0:
raise ValueError("No images to create a video.")
height, width, layers = images[0].shape
video = cv2.VideoWriter(output_path, cv2.VideoWriter_fourcc(*'mp4v'), fps, (width, height))
for img in images:
video.write(img)
video.release()
fps = 20 # 设置帧率
images = load_tiff_images(folder_path)
create_video(images, output_path, fps)
读取tiff图像并且转换为视频
最新推荐文章于 2024-08-29 15:54:17 发布