Objective
I’m trying to apply synthstrip directly in on a numpy array instead of a nifti file, so it’s part of a 100% python workflow, without disk operations nor nifti header available.
Current result
When I use a nifti file, which is the standard procedure, I have an expected result:
But when I use the numpy array from the exact same loaded nifti:
Method
The python script loads a nifti file here :
sf.system.fatal('FREESURFER_HOME env variable must be set! Make sure FreeSurfer is properly sourced.')
if args.no_csf:
print('Excluding CSF from brain boundary')
modelfile = os.path.join(fshome, 'models', f'synthstrip.nocsf.{version}.pt')
else:
modelfile = os.path.join(fshome, 'models', f'synthstrip.{version}.pt')
checkpoint = torch.load(modelfile, map_location=device)
model.load_state_dict(checkpoint['model_state_dict'])
# load input volume
image = sf.load_volume(args.image)
print(f'Input image read from: {args.image}')
# loop over frames (try not to keep too much data in memory)
print(f'Processing frame (of {image.nframes}):', end=' ', flush=True)
dist = []
mask = []
for f in range(image.nframes):
print(f + 1, end=' ', flush=True)
frame = image.new(image.framed_data[..., f])
Here is the modification for testing purpose, which instead of feeding the nifti file, gives the array directly :
image_from_nifti = sf.load_volume(args.image)
image = sf.Volume(image_from_nifti.data) # feed the numpy array directly