1. 程式人生 > >讀取tif檔案 並且分別儲存

讀取tif檔案 並且分別儲存

import os
import numpy as np
import glob
import cv2
from keras.preprocessing.image import ImageDataGenerator, array_to_img, img_to_array, load_img
from libtiff import TIFF
from scipy import misc


tif = TIFF.open('/media/chenli/F1/cell_data/mitochondria/testing_groundtruth.tif', mode = "r")
idx = 0
for im in list(tif.iter_images()):
    out_folder='mitochondria/testing_groundtruth'
    
    if not os.path.exists(out_folder):
        os.mkdir(out_folder)

    im_name = imgsname[i] + str(idx) + '.tif'
    misc.imsave(out_folder+'/'+im_name, im)
#     print im_name, 'successfully saved!!!'
    idx = idx + 1