unet图片数据增强_数据增强代码

这段代码主要展示了如何利用UNET进行图片数据增强。通过提取随机或有序的图像块,进行训练和测试数据的预处理,包括检查数据一致性、边界填充以适应补丁尺寸,并实现重叠区域的数据提取。此外,还提供了将预测结果重组回完整图像的方法。
摘要由CSDN通过智能技术生成

#extract_patches.py 主要参考的原代码

importnumpy as npimportrandomimportconfigparser as ConfigParserfrom help_functions importload_hdf5from help_functions importvisualizefrom help_functions importgroup_imagesfrom pre_processing importmy_PreProc#To select the same images#random.seed(10)

#Load the original data and return the extracted patches for training/testing

defget_data_training(DRIVE_train_imgs_original,

DRIVE_train_groudTruth,

patch_height,

patch_width,

N_subimgs,

inside_FOV):

train_imgs_original=load_hdf5(DRIVE_train_imgs_original)

train_masks= load_hdf5(DRIVE_train_groudTruth) #masks always the same

#visualize(group_images(train_imgs_original[0:20,:,:,:],5),'imgs_train')#.show() #check original imgs train

train_imgs=my_PreProc(train_imgs_original)

train_masks= train_masks/255.

train_imgs= train_imgs[:,:,9:574,:] #cut bottom and top so now it is 565*565

train_masks = train_masks[:,:,9:574,:] #cut bottom and top so now it is 565*565

data_consistency_check(train_imgs,train_masks)#check masks are within 0-1

assert(np.min(train_masks)==0 and np.max(train_masks)==1)print ("\ntrain images/masks shape:")print(train_imgs.shape)print ("train images range (min-max):" +str(np.min(train_imgs)) +'-'+str(np.max(train_imgs)))print ("train masks are within 0-1\n")#extract the TRAINING patches from the full images

patches_imgs_train, patches_masks_train =extract_random(train_imgs,train_masks,patch_height,patch_width,N_subimgs,inside_FOV)

data_consistency_check(patches_imgs_train, patches_masks_train)print ("\ntrain PATCHES images/masks shape:")print(patches_imgs_train.shape)print ("train PATCHES images range (min-max):" +str(np.min(patches_imgs_train)) +'-'+str(np.max(patches_imgs_train)))return patches_imgs_train, patches_masks_train#, patches_imgs_test, patches_masks_test

#Load the original data and return the extracted patches for training/testing

defget_data_testing(DRIVE_test_imgs_original, DRIVE_test_groudTruth, Imgs_to_test, patch_height, patch_width):### test

test_imgs_original =load_hdf5(DRIVE_test_imgs_original)

test_masks=load_hdf5(DRIVE_test_groudTruth)

test_imgs=my_PreProc(test_imgs_original)

test_masks= test_masks/255.#extend both images and masks so they can be divided exactly by the patches dimensions

test_imgs =test_imgs[0:Imgs_to_test,:,:,:]

test_masks=test_masks[0:Imgs_to_test,:,:,:]

test_imgs=paint_border(test_imgs,patch_height,patch_width)

test_masks=paint_border(test_masks,patch_height,patch_width)

data_consistency_check(test_imgs, test_masks)#check masks are within 0-1

assert(np.max(test_masks)==1 and np.min(test_masks)==0)print ("\ntest images/masks shape:")print(test_imgs.shape)print ("test images range (min-max):" +str(np.min(test_imgs)) +'-'+str(np.max(test_imgs)))print ("test masks are within 0-1\n")#extract the TEST patches from the full images

patches_imgs_test =extract_ordered(test_imgs,patch_height,patch_width)

patches_masks_test=extract_ordered(test_masks,patch_height,patch_width)

data_consistency_check(patches_imgs_test, patches_masks_test)print ("\ntest PATCHES images/masks shape:")print(patches_imgs_test.shape)print ("test PATCHES images range (min-max):" +str(np.min(patches_imgs_test)) +'-'+str(np.max(patches_imgs_test)))returnpatches_imgs_test, patches_masks_test#Load the original data and return the extracted patches for testing#return the ground truth in its original shape

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值