Ejemplo n.º 1
0
def oxasl_preproc(wsp):
    """
    Run standard processing on ASL data

    This method requires wsp to be a Workspace containing certain standard information.
    As a minimum, the attribute ``asldata`` must contain an AslImage object.
    """
    if wsp.calib_first_vol and wsp.calib is None:
        wsp.input.calib = wsp.asldata.calib

    report_asl(wsp)

    struc.init(wsp)
    corrections.apply_corrections(wsp)

    corrections.get_motion_correction(wsp)
    corrections.apply_corrections(wsp)

    reg.reg_asl2calib(wsp)
    reg.reg_asl2struc(wsp, True, False)
    reg.reg_asl2custom(wsp)

    corrections.get_fieldmap_correction(wsp)
    corrections.get_cblip_correction(wsp)
    corrections.get_sensitivity_correction(wsp)
    corrections.apply_corrections(wsp)

    mask.generate_mask(wsp)

    if oxasl_enable and wsp.use_enable:
        wsp.sub("enable")
        oxasl_enable.enable(wsp.enable)
        wsp.corrected.asldata = wsp.enable.asldata_enable
Ejemplo n.º 2
0
def redo_reg(wsp, pwi):
    """
    Re-do ASL->structural registration using BBR and perfusion image
    """
    wsp.reg.regfrom_orig = wsp.reg.regfrom
    wsp.reg.regto_orig = wsp.reg.regto
    new_regfrom = np.copy(pwi.data)
    new_regfrom[new_regfrom < 0] = 0
    wsp.reg.regfrom = Image(new_regfrom, header=pwi.header)
    wsp.reg.asl2struc_initial = wsp.reg.asl2struc
    wsp.reg.struc2asl_initial = wsp.reg.struc2asl
    reg.reg_asl2struc(wsp, False, True, name="final")
Ejemplo n.º 3
0
def get_rois(wsp):
    """
    Generate ROIs for GM and noise
    
    Existing ROIs may be provided. If provided in structural space, the ASL data is registered
    to the structural image and the ROIS will be transformed to ASL space

    If (either) of the noise or GM ROIs are not provided they are automatically generated as follows

     - Grey matter: From segmentation of structural image (via FAST or FSL_ANAT output if provided)
     - Noise: By inverting brain mask from brain-extracted structural image

    A structural image is therefore required if either ROI needs to be generated, or if either ROI
    is supplied in structural space. 

    Optional workspace attributes
    -----------------------------

     - ``regfrom`` : Reference image for registration of ASL to structural data
     - ``asldata`` : Single TI ASL data. Middle volume will be used as reference if ``regfrom`` is required and not set
     - ``gm_roi`` : Grey matter ROI in ASL or structural space
     - ``noise_roi`` : Noise ROI in ASL or structural space
     - ``noise_from_struc`` : If True, existing ``noise_roi`` image is in structural space
     - ``gm_from_struc`` : If True, existing ``gm_roi`` image is in structural space
     - ``struc`` : Structural image
     
    Workspace attributes set
    ------------------------

     - ``gm_roi`` : Grey matter ROI in ASL space
     - ``noise_roi`` : Noise ROI in ASL space
    """
    wsp.log.write("Generating ROIs...\n")

    if wsp.regfrom is None:
        wsp.log.write(" - Reference image for registration not provided - using ASL data middle volume\n")
        middle = int(wsp.asldata.shape[3]/2)
        wsp.regfrom = Image(wsp.asldata.data[:, :, :, middle], header=wsp.asldata.header)
        
    struc.init(wsp)
    if (wsp.gm_roi is None or wsp.noise_roi is None or wsp.noise_from_struc or wsp.gm_from_struc) and wsp.structural.struc is None:
        raise RuntimeError("Need to specify a structural image unless you provide both noise and GM ROIs in ASL space")

    if wsp.gm_roi is None:
        struc.segment(wsp)
        wsp.log.write("Taking GM ROI from segmentation of structural image\n")
        wsp.gm_roi = Image((wsp.structural.gm_pv.data > 0).astype(np.int), header=wsp.structural.struc.header)
        wsp.gm_from_struc = True

    if wsp.noise_roi is None:
        wsp.log.write("Generating noise ROI by inverting T1 brain mask\n")
        wsp.noise_roi = Image(1-wsp.structural.brain_mask.data, header=wsp.structural.struc.header)
        wsp.noise_from_struc = True

    if wsp.noise_from_struc or wsp.gm_from_struc:
        # Need struc->ASL registration space so we can apply to noise and/or GM ROIs
        wsp.do_flirt = True
        wsp.do_bbr = False
        reg.reg_asl2struc(wsp)

    if wsp.noise_from_struc:
        wsp.log.write(" - Registering noise ROI to ASL space since it was defined in structural space\n\n")
        wsp.noise_roi_struc = wsp.noise_roi
        wsp.noise_roi = reg.struc2asl(wsp, wsp.noise_roi_struc, interp="nn")

    if wsp.gm_from_struc:
        wsp.log.write(" - Registering GM ROI to ASL space since it was defined in structural space\n\n")
        wsp.gm_roi_struc = wsp.gm_roi
        wsp.gm_roi = reg.struc2asl(wsp, wsp.gm_roi_struc, interp="nn")

    wsp.log.write("DONE\n\n")