def _multiframe_to_nifti(dicom_input, output_file):
    """
    This function will convert philips 4D or anatomical multiframe series to a nifti
    """

    # Read the multiframe dicom file
    logger.info('Read dicom file')
    multiframe_dicom = dicom_input[0]

    # Create mosaic block
    logger.info('Creating data block')
    full_block = _multiframe_to_block(multiframe_dicom)

    logger.info('Creating affine')

    # Create the nifti header info
    affine = _create_affine_multiframe(multiframe_dicom)
    logger.info('Creating nifti')

    # Convert to nifti
    nii_image = nibabel.Nifti1Image(full_block, affine)
    timing_parameters = multiframe_dicom.SharedFunctionalGroupsSequence[0].MRTimingAndRelatedParametersSequence[0]
    first_frame = multiframe_dicom[Tag(0x5200, 0x9230)][0]
    common.set_tr_te(nii_image, float(timing_parameters.RepetitionTime),
                     float(first_frame[0x2005, 0x140f][0].EchoTime))

    # Save to disk
    if output_file is not None:
        logger.info('Saving nifti to disk %s' % output_file)
        nii_image.to_filename(output_file)

    if _is_multiframe_diffusion_imaging(dicom_input):
        bval_file = None
        bvec_file = None
        if output_file is not None:
            # Create the bval en bvec files
            base_path = os.path.dirname(output_file)
            base_name = os.path.splitext(os.path.splitext(os.path.basename(output_file))[0])[0]
            logger.info('Creating bval en bvec files')
            bval_file = '%s/%s.bval' % (base_path, base_name)
            bvec_file = '%s/%s.bvec' % (base_path, base_name)
        bval, bvec, bval_file, bvec_file = _create_bvals_bvecs(multiframe_dicom, bval_file, bvec_file, nii_image,
                                                               output_file)

        return {'NII_FILE': output_file,
                'BVAL_FILE': bval_file,
                'BVEC_FILE': bvec_file,
                'NII': nii_image,
                'BVAL': bval,
                'BVEC': bvec}

    return {'NII_FILE': output_file,
            'NII': nii_image}
def _multiframe_to_nifti ( dicom_input , output_file ) : logger . info ( 'Read dicom file' ) multiframe_dicom = dicom_input [ 0 ] logger . info ( 'Creating data block' ) full_block = _multiframe_to_block ( multiframe_dicom ) logger . info ( 'Creating affine' ) affine = _create_affine_multiframe ( multiframe_dicom ) logger . info ( 'Creating nifti' ) nii_image = nibabel . Nifti1Image ( full_block , affine ) timing_parameters = multiframe_dicom . SharedFunctionalGroupsSequence [ 0 ] . MRTimingAndRelatedParametersSequence [ 0 ] first_frame = multiframe_dicom [ Tag ( 0x5200 , 0x9230 ) ] [ 0 ] common . set_tr_te ( nii_image , float ( timing_parameters . RepetitionTime ) , float ( first_frame [ 0x2005 , 0x140f ] [ 0 ] . EchoTime ) ) if output_file is not None : logger . info ( 'Saving nifti to disk %s' % output_file ) nii_image . to_filename ( output_file ) if _is_multiframe_diffusion_imaging ( dicom_input ) : bval_file = None bvec_file = None if output_file is not None : base_path = os . path . dirname ( output_file ) base_name = os . path . splitext ( os . path . splitext ( os . path . basename ( output_file ) ) [ 0 ] ) [ 0 ] logger . info ( 'Creating bval en bvec files' ) bval_file = '%s/%s.bval' % ( base_path , base_name ) bvec_file = '%s/%s.bvec' % ( base_path , base_name ) bval , bvec , bval_file , bvec_file = _create_bvals_bvecs ( multiframe_dicom , bval_file , bvec_file , nii_image , output_file ) return { 'NII_FILE' : output_file , 'BVAL_FILE' : bval_file , 'BVEC_FILE' : bvec_file , 'NII' : nii_image , 'BVAL' : bval , 'BVEC' : bvec } return { 'NII_FILE' : output_file , 'NII' : nii_image }
This function will convert philips 4D or anatomical multiframe series to a nifti