@@ -293,6 +293,7 @@ def _run_interface(self, runtime):
293
293
294
294
class ValidateImageInputSpec (BaseInterfaceInputSpec ):
295
295
in_file = File (exists = True , mandatory = True , desc = 'input image' )
296
+ deoblique = traits .Bool (False , usedefault = True )
296
297
297
298
298
299
class ValidateImageOutputSpec (TraitedSpec ):
@@ -342,6 +343,15 @@ class ValidateImage(SimpleInterface):
342
343
output_spec = ValidateImageOutputSpec
343
344
344
345
def _run_interface (self , runtime ):
346
+
347
+ def deoblique (img ):
348
+ import os
349
+ import nibabel as nb
350
+ import numpy as np
351
+ affine = img .affine
352
+ affine [:3 , :3 ] = np .diag (np .diag (affine [:3 , :3 ]))
353
+ return nb .Nifti1Image (np .asanyarray (img .dataobj ), affine , img .header )
354
+
345
355
img = nb .load (self .inputs .in_file )
346
356
out_report = os .path .join (runtime .cwd , 'report.html' )
347
357
@@ -370,7 +380,13 @@ def _run_interface(self, runtime):
370
380
371
381
# Both match, qform valid (implicit with match), codes okay -> do nothing, empty report
372
382
if matching_affines and qform_code > 0 and sform_code > 0 :
373
- self ._results ['out_file' ] = self .inputs .in_file
383
+ if self .inputs .deoblique :
384
+ out_fname = fname_presuffix (self .inputs .in_file , suffix = '_valid' , newpath = runtime .cwd )
385
+ img = deoblique (img )
386
+ img .to_filename (out_fname )
387
+ self ._results ['out_file' ] = out_fname
388
+ else :
389
+ self ._results ['out_file' ] = self .inputs .in_file
374
390
open (out_report , 'w' ).close ()
375
391
self ._results ['out_report' ] = out_report
376
392
return runtime
@@ -418,6 +434,9 @@ def _run_interface(self, runtime):
418
434
</p>
419
435
"""
420
436
snippet = '<h3 class="elem-title">%s</h3>\n %s\n ' % (warning_txt , description )
437
+
438
+ if self .inputs .deoblique :
439
+ img = deoblique (img )
421
440
# Store new file and report
422
441
img .to_filename (out_fname )
423
442
with open (out_report , 'w' ) as fobj :
0 commit comments