コード例 #1
0
        print 'With respect to scale factor x', scale

        # Cubic Interpolation
        if TargetShape != InputShape:
            InputImage = scipy.ndimage.zoom(InputImage,
                                            zoom=scale,
                                            order=args.order)

        # Shave border
        LabelImage = shave3D(ReferenceImage, border)
        DataImage = shave3D(InputImage, border)

        # Extract 3D patches
        DataPatch = array_to_patches(DataImage,
                                     patch_shape=(PatchSize, PatchSize,
                                                  PatchSize),
                                     extraction_step=args.stride,
                                     normalization=False)
        print 'for the (interpolated or not) low-resolution patches of training phase.'
        LabelPatch = array_to_patches(LabelImage,
                                      patch_shape=(PatchSize, PatchSize,
                                                   PatchSize),
                                      extraction_step=args.stride,
                                      normalization=False)
        print 'for the reference high-resolution patches of training phase.'
        # Append array
        HDF5Datas.append(DataPatch)
        HDF5Labels.append(LabelPatch)

        # List type to array numpy
        HDF5Datas = np.asarray(HDF5Datas).reshape(-1, PatchSize, PatchSize,
コード例 #2
0
        NormalizedT1wImage = T1wImage/MaxValue

        # Shave region outside
        print 'Remove the region outside the brain with the value of ', args.thresholdvalue
        darkRegionValue = args.thresholdvalue
        darkRegionBox = np.where(NormalizedT1wImage>darkRegionValue)   
        border = ((np.min(darkRegionBox[0]),np.max(darkRegionBox[0])),
                  (np.min(darkRegionBox[1]),np.max(darkRegionBox[1])),
                  (np.min(darkRegionBox[2]),np.max(darkRegionBox[2])))     
        DatasT1wImage = NormalizedT1wImage[border[0][0]:border[0][1],
                                           border[1][0]:border[1][1],
                                           border[2][0]:border[2][1]]    
        
        # Extract 3D patches                              
        DatasT1wPatch = array_to_patches(DatasT1wImage, 
                                         patch_shape=(PatchSize,PatchSize,PatchSize), 
                                         extraction_step = args.stride , 
                                         normalization=False)
        print 'for patches of training phase.'        
                          
        # n-dimensional Caffe supports data's form : [numberOfBatches,channels,heigh,width,depth]         
        # Add channel axis !  
        DatasT1wPatch = DatasT1wPatch[:,np.newaxis,:,:,:]
                
        # Rearrange
        RandomOrder = np.random.permutation(DatasT1wPatch.shape[0])
        DatasT1wPatch = DatasT1wPatch[RandomOrder,:,:,:,:]
        
        # Crop data to desired number of samples
        if args.samples :
            DatasT1wPatch = DatasT1wPatch[:args.samples ,...]