这次分割的颅内血管数据是nii格式的三维数据,由于只有20套,所以打算切片再用简单的unet分割。途中遇到很多问题,简单记录一下~
数据处理
nii格式的文件读取专用库之一:
import nibabel as nib
img = nib.load(filename).get_fdata()
这样就能获取nii文件的三维数据内容了。但是获取到的三维数组内容是0-3000多的CT值,如果保存为png图片则要转换成0-255的uint8格式的数据则需要进行加窗。当选取窗位900,窗宽1200时比较适合。因此所有数据全转换成uint8的png切片。在训练之前将数据归一化,0-255的数据归一化到0-1。
Unet网络
用最简单的unet网络先分割一下:
def get_unet_2(height,width,n_chanel):
inputs = Input((height, width, n_chanel))
conv1 = Conv2D(16, 3, activation='relu', padding='same', kernel_initializer='he_normal')(inputs)
conv1 = Conv2D(16, 3, activation='relu', padding='same', kernel_initializer='he_normal')(conv1)
pool1 = MaxPooling2D(pool_size=(2, 2))(conv1)
conv2 = Conv2D(32, 3, activation='relu', padding='same', kernel_initializer='he_normal')(pool1)
conv2 = Conv2D(32, 3, activation='relu', padding='same', kernel_initializer='he_normal')(conv2)
pool2 = MaxPooling2D(pool_size=(2, 2))(conv2)
conv3 = Conv2D(64, 3, activation='relu', padding='same', kernel_initializer='he_normal')(pool2)
conv3 = Conv2D(64, 3, activation='relu', padding='same', kernel_initializer='he_normal')(conv3)
pool3 = MaxPooling2D(pool_size=(2, 2))(conv3)
conv4 = Conv2D(128, 3, activation='relu', padding='same', kernel_initializer='he_normal')(pool3)
conv4 = Conv2D(128, 3, activation='relu', padding='same', kernel_initializer='he_normal')(conv4)
drop4 = Dropout(0.5)(conv4)
pool4 = MaxPooling2D(pool_size=(2, 2))(drop4)
conv5 = Conv2D(256, 3, activation='relu', padding='same', kernel_initializer='he_normal')(pool4)
conv5 = Conv2D(