Exemplo n.º 1
0
        # Compute scale factor:
        TargetShape = ReferenceImage.shape
        InputShape = InputImage.shape
        scale = (Targetidx / inputidx
                 for Targetidx, inputidx in zip(TargetShape, InputShape))
        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.'
 LowResolutionImage = scipy.ndimage.zoom(BlurReferenceImage,
                           zoom = (1/float(idxScale) for idxScale in UpScale),
                           order = 0)  
 
 # Normalization by the max valeur of LR image
 MaxValue = np.max(LowResolutionImage)
 NormalizedReferenceImage =  ReferenceImage/MaxValue
 NormalizedLowResolutionImage =  LowResolutionImage/MaxValue
 
 # Cubic Interpolation     
 InterpolatedImage = scipy.ndimage.zoom(NormalizedLowResolutionImage, 
                           zoom = UpScale,
                           order = args.order)  
                       
 # Shave border
 LabelImage = shave3D(NormalizedReferenceImage, border)    
 DataImage = shave3D(InterpolatedImage, border)   
 
 # Extract 3D patches
 print 'Generating training patches with the resolution of ', NewResolution, ' : '
 DataPatch = array_to_patches(DataImage, 
                              patch_shape=(PatchSize,PatchSize,PatchSize), 
                              extraction_step = args.stride , 
                              normalization=False)
 print 'for the interpolated 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.'     
                      
Exemplo n.º 3
0
            BlurReferenceImage = modcrop3D(BlurReferenceImage, scale)
            ReferenceImage = modcrop3D(ReferenceImage, scale)

            # Downsampling
            LowResolutionImage = scipy.ndimage.zoom(
                BlurReferenceImage,
                zoom=(1 / float(idxScale) for idxScale in scale),
                order=args.order)

            # Cubic Interpolation
            InterpolatedImage = scipy.ndimage.zoom(LowResolutionImage,
                                                   zoom=scale,
                                                   order=args.order)

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

            # Extract 3D patches
            DataPatch = array_to_patches(DataImage,
                                         patch_shape=(PatchSize, PatchSize,
                                                      PatchSize),
                                         extraction_step=args.stride,
                                         normalization=False)
            print 'for the interpolated 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.'
Exemplo n.º 4
0
    # Loading weights
    UnSynGAN_test = UnSynGAN_test(args.weights,T1toT2)
    
    for i in range(0,len(args.test)):
       
        # Read low-resolution image
        TestFile = args.test[i]
        print 'Processing testing image : ', TestFile 
        TestNifti = sitk.ReadImage(TestFile)
        TestImage = np.swapaxes(sitk.GetArrayFromImage(TestNifti),0,2).astype('float32')
        TestImageMinValue = float(np.min(TestImage))
        TestImageMaxValue = float(np.max(TestImage))
        TestImageNorm = TestImage/TestImageMaxValue 
        
        # Shave border
        ShavedImage = shave3D(TestImage, border)   

        # GAN 
        print "Testing : ",
        EstimatedImage = UnSynGAN_test.test_by_patch(ShavedImage,step=args.step)
        
        # Padding
        pad_border = [(idx,idx) for idx in border]
        PaddedEstimatedImage = np.pad(EstimatedImage,pad_border,'constant')
        
        # Synthetic image 
        EstimatedHRImageInverseNorm = PaddedEstimatedImage*TestImageMaxValue
        EstimatedHRImageInverseNorm[EstimatedHRImageInverseNorm <= TestImageMinValue] = TestImageMinValue    # Clear negative value
        OutputImage = sitk.GetImageFromArray(np.swapaxes(EstimatedHRImageInverseNorm,0,2))
        OutputImage.SetSpacing(TestNifti.GetSpacing())
        OutputImage.SetOrigin(TestNifti.GetOrigin())
Exemplo n.º 5
0
        print 'Processing testing image : ', TestFile 
        TestNifti = sitk.ReadImage(TestFile)
        TestImage = np.swapaxes(sitk.GetArrayFromImage(TestNifti),0,2).astype('float32')
        TestImageMinValue = float(np.min(TestImage))
        TestImageMaxValue = float(np.max(TestImage))
        TestImageNorm = TestImage/TestImageMaxValue 
        
        # Check scale factor type
        UpScale = tuple(itema/itemb for itema,itemb in zip(TestNifti.GetSpacing(),NewResolution)) 
        
        # spline interpolation 
        InterpolatedImage = scipy.ndimage.zoom(TestImageNorm, 
                                               zoom = UpScale,
                                               order = args.order)  
        # Shave border
        ShavedInterpolatedImage = shave3D(InterpolatedImage, border)   
        
        # SRResidualCNN3D
        SRReCNN3D_test = SRReCNN3D_test()

        EstimatedHRImage = SRReCNN3D_test.test(ShavedInterpolatedImage,weights,
                                               NetDepth = args.netdepth, 
                                               NetNumKernel = args.numkernel, 
                                               KernelSize = args.kernelsize,
                                               Residual= residual)
        
        # Padding
        pad_border = [(idx,idx) for idx in border]
        PaddedEstimatedHRImage = np.pad(EstimatedHRImage,pad_border,'constant')