完成U-net细胞分割的一些准备

#使用本地上传文件
from google.colab import files
uploaded = files.upload()
for fn in uploaded.keys():
    print('User uploaded file "{name}" with length {length} bytes'.format(name=fn, length=len(uploaded[fn])))
#删除文件以及文件夹
import os
import shutil

path='../source_file_clxiao/'

#os.remove(path)   #删除文件
#os.removedirs(path)   #删除空文件夹

#shutil.rmtree(path)    #递归删除文件夹
#CV2图像显示
from google.colab.patches import cv2_imshow
!curl -o logo.png https://colab.research.google.com/img/colab_favicon_256px.png
import cv2
img = cv2.imread('logo.png', cv2.IMREAD_UNCHANGED)
cv2_imshow(img)
#文件上传加文件读取
from google.colab import files
import cv2
uploaded = files.upload()
ii=0
for fn in uploaded.keys():
  input=cv2.imread(fn)
  ii=ii+1
    #图片读取加图像扩增
    from keras.preprocessing.image import ImageDataGenerator, array_to_img, img_to_array, load_img
    
    datagen = ImageDataGenerator(
            rotation_range=1,
            width_shift_range=0.2,
            height_shift_range=0.2,
            shear_range=0.6,
            zoom_range=0.6,
            horizontal_flip=True,
            fill_mode='nearest')
    
    img = load_img('test_1.tif')  # this is a PIL image
    x = img_to_array(img)  # this is a Numpy array with shape (3, 150, 150)
    x = x.reshape((1,) + x.shape)  # this is a Numpy array with shape (1, 3, 150, 150)
    
    # the .flow() command below generates batches of randomly transformed images
    # and saves the results to the `preview/` directory
    i = 0
    
    import matplotlib.pyplot as plt
    
    from PIL import Image
    list=datagen.flow(x, batch_size=4,save_to_dir='test_1/', save_prefix='test_1_', save_format='tif')
    #print(list.size)
    for batch in list:
        i += 1
        if i > 5:
            break  # otherwise the generator would loop indefinitely
        print(batch.size)
        #plt.imshow(batch)
        #cv2.WaitKey(20)

 

你可能感兴趣的:(算法,图像)