在做UNET的眼球血管分割的时候,眼球的标注使用的gif格式存储的,习惯了使用jpg或者png了,先转一下。直接用opencv读进来以后重写一下就可以。gif读取的时候要使用VideoCapture,因为GIF是动图。
# !/usr/bin/python3
# -*- coding:utf-8 -*-
# Author:WeiFeng Liu
# @Time: 2021/12/9 下午6:54
import numpy as np
import cv2
import os
def gif_to_png(image_path,save_path):
gif = cv2.VideoCapture(image_path)
ret,frame = gif.read()
filename = image_path.split('/')[-1].split('_')[0]
save_path = save_path + filename + '.png'
cv2.imwrite(save_path,frame)
if __name__ == '__main__':
root_path = r'视网膜血管数据集/training/label/'
save_path = r'Dataset/train/label/'
image_files = os.listdir(root_path)
for image_file in image_files:
gif_to_png(root_path + image_file,save_path)