# Read reference image ReferenceName = args.reference[i] print '================================================================' print 'Processing image : ', ReferenceName # Read NIFTI ReferenceNifti = sitk.ReadImage(ReferenceName) # Get data from NIFTI ReferenceImage = np.swapaxes(sitk.GetArrayFromImage(ReferenceNifti),0,2).astype('float32') # Get resolution to scaling factor UpScale = tuple(itemb/itema for itema,itemb in zip(ReferenceNifti.GetSpacing(),NewResolution)) # Modcrop to scale factor ReferenceImage = modcrop3D(ReferenceImage,UpScale) # ===== Generate input LR image ===== # Blurring BlurReferenceImage = scipy.ndimage.filters.gaussian_filter(ReferenceImage, sigma = SigmaBlur) print 'Generating LR images with the resolution of ', NewResolution # Downsampling 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)
ReferenceImage = np.swapaxes(sitk.GetArrayFromImage(ReferenceNifti), 0, 2).astype('float32') # Normalization ReferenceImage = imadjust3D(ReferenceImage, [0, 1]) # ===== Generate input LR image ===== # Blurring BlurReferenceImage = scipy.ndimage.filters.gaussian_filter( ReferenceImage, sigma=args.sigma) for scale in args.scale: print 'With respect to scale factor x', scale, ' : ' # Modcrop to scale factor 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)