Exemple #1
0
class FslAtlasWidget(QpWidget):
    """
    Widget for browsing and loading FSL atlases
    """
    def __init__(self, **kwargs):
        super(FslAtlasWidget,
              self).__init__(name="Atlases",
                             icon="fsl.png",
                             desc="Browse and display FSL atlases",
                             group="FSL",
                             **kwargs)
        self._registry = AtlasRegistry()

    def init_ui(self):
        vbox = QtGui.QVBoxLayout()
        vbox.setSpacing(1)
        self.setLayout(vbox)

        vbox.addWidget(TitleWidget(self))
        vbox.addWidget(Citation(*CITATIONS["fsl"]))

        self.atlas_list = AtlasListWidget(self, self._registry)
        vbox.addWidget(self.atlas_list)
        self.atlas_desc = AtlasDescription(self, self._registry)
        vbox.addWidget(self.atlas_desc)

        self.atlas_list.sig_selected.connect(self.atlas_desc.set_atlas)

        fsldir = FslDirWidget()
        vbox.addWidget(fsldir)

        # This needs to be done after creating the FslDirWidget because otherwise we may not
        # have picked up a previously saved FSLDIR setting and the atlas list will be empty
        self._registry.rescanAtlases()
        self.atlas_list.init_list()
Exemple #2
0
def get_tissrefmask(wsp):
    """
    Calculate a calibration reference mask for a particular known tissue type
    """
    page = wsp.report.page("auto_calib_mask")
    page.heading("Calibration reference region")
    page.text("Reference region was automatically generated for tissue type: %s" % wsp.tissref.upper())
    page.heading("Partial volume map for %s tissue (from structural segmentation)" % wsp.tissref.upper(), level=1)
    wsp.calibration.refpve = getattr(wsp.structural, "%s_pv" % wsp.tissref.lower())
    page.image("refpve", LightboxImage(wsp.calibration.refpve, bgimage=wsp.structural.brain))

    if wsp.tissref == "csf" and not wsp.csfmaskingoff:
        wsp.log.write(" - Doing automatic ventricle selection using standard atlas\n")
        # By deafult now we do FNRIT transformation of ventricle mask
        # FIXME disabled as not being used in ASL_CALIB at present
        #wsp.calibration.struc2stdfnirt = wsp.ifnone("stdmaskfnirt", True)

        # Select ventricles based on standard space atlas
        page.heading("Automatic ventricle selection", level=1)
        page.text("Standard space ventricles mask (from Harvard-Oxford atlas) eroded by 1 pixel")
        atlases = AtlasRegistry()
        atlases.rescanAtlases()
        atlas = atlases.loadAtlas("harvardoxford-subcortical", loadSummary=False, resolution=2)
        ventricles = ((atlas.data[..., 2] + atlas.data[..., 13]) > 0.1).astype(np.int)
        wsp.calibration.ventricles = Image(scipy.ndimage.binary_erosion(ventricles, structure=np.ones([3, 3, 3]), border_value=1).astype(np.int), header=atlas.header)
        std_img = Image(os.path.join(os.environ["FSLDIR"], "data", "standard", 'MNI152_T1_2mm_brain'))
        page.image("ventricles_std", LightboxImage(wsp.calibration.ventricles, bgimage=std_img))

        page.heading("Structural space ventricles mask", level=1)
        # FIXME nearest neighbour interpolation?
        wsp.calibration.ventricles_struc = reg.change_space(wsp, wsp.calibration.ventricles, "struc")
        page.text("This is the above image transformed into structural space. The transformation was obtained by registering the structural image to the standard brain image")
        page.image("ventricles_struc", LightboxImage(wsp.calibration.ventricles_struc, bgimage=wsp.structural.brain))

        wsp.log.write(" - Masking FAST output with standard space derived ventricle mask\n")
        wsp.calibration.refpve_pre_mask = wsp.calibration.refpve
        refpve_data = np.copy(wsp.calibration.refpve.data)
        refpve_data[wsp.calibration.ventricles_struc.data == 0] = 0
        wsp.calibration.refpve = Image(refpve_data, header=wsp.calibration.refpve.header)
        wsp.calibration.refpve_post = wsp.calibration.refpve

        page.heading("Structural space ventricles PVE", level=1)
        page.text("This is the CSF partial volume masked by the ventricles mask. It should select only the ventricles from the original partial volume image.")
        page.image("refpve_post", LightboxImage(wsp.calibration.refpve, bgimage=wsp.structural.brain))

    wsp.log.write(" - Transforming tissue reference mask into ASL space\n")
    # FIXME calibration image may not be in ASL space! Oxford_asl does not handle this currently
    wsp.calibration.refpve_calib = reg.change_space(wsp, wsp.calibration.refpve, "native")
    #wsp.calibration.refpve_calib.data[wsp.calibration.refpve_calib.data < 0.001] = 0 # Better for display
    page.heading("Reference region in ASL space", level=1)
    page.text("Partial volume map")
    page.image("refpve_calib", LightboxImage(wsp.calibration.refpve_calib, bgimage=wsp.calibration.calib_img))

    # Threshold reference mask conservatively to select only reference tissue
    wsp.log.write(" - Thresholding reference mask\n")
    wsp.calibration.refmask = Image((wsp.calibration.refpve_calib.data > 0.9).astype(np.int), header=wsp.calibration.refpve_calib.header)

    page.text("Reference Mask (thresholded at 0.9")
    page.image("refmask", LightboxImage(wsp.calibration.refmask, bgimage=wsp.calibration.calib_img))
Exemple #3
0
 def __init__(self, **kwargs):
     super(FslAtlasWidget,
           self).__init__(name="Atlases",
                          icon="fsl.png",
                          desc="Browse and display FSL atlases",
                          group="FSL",
                          **kwargs)
     self._registry = AtlasRegistry()
 def __init__(self, ivm):
     StructureModel.__init__(self, ivm, "FSL MNI standard data")
     from fsl.data.atlases import AtlasRegistry
     self._registry = AtlasRegistry()
     self._registry.rescanAtlases()
     atlas_names = []
     self._atlases = {}
     for atlas in sorted(self._registry.listAtlases(),
                         key=lambda x: x.name):
         for prefix in self.ATLAS_PREFIXES:
             if atlas.name.startswith(prefix):
                 for pixdim in atlas.pixdims:
                     name = atlas.name + " %.2gx%.2gx%.2g mm" % pixdim
                     self._atlases[name] = (atlas, pixdim)
class FslStdStructureModel(PartialVolumeStructureModel):
    """
    Structural model using standard FSL structural data

    FIXME not functional at present - not clear that FSL supplies relevant
    segmentation data out of the box!
    """
    NAME = "fsl"

    ATLAS_PREFIXES = [
        "MNI",
    ]

    def __init__(self, ivm):
        StructureModel.__init__(self, ivm, "FSL MNI standard data")
        from fsl.data.atlases import AtlasRegistry
        self._registry = AtlasRegistry()
        self._registry.rescanAtlases()
        atlas_names = []
        self._atlases = {}
        for atlas in sorted(self._registry.listAtlases(),
                            key=lambda x: x.name):
            for prefix in self.ATLAS_PREFIXES:
                if atlas.name.startswith(prefix):
                    for pixdim in atlas.pixdims:
                        name = atlas.name + " %.2gx%.2gx%.2g mm" % pixdim
                        self._atlases[name] = (atlas, pixdim)

    @property
    def structures(self):
        atlas, pixdims = self._atlases[self.options["atlas"]]
        structures = []
        for label in atlas.labels:
            structures.append(Parameter(label.name, label.name))
        return structures

    @property
    def structure_maps(self):
        atlas, pixdims = self._atlases[self.options["atlas"]]
        structure_maps = {}
        atlas_map = self._registry.loadAtlas(atlas.atlasID,
                                             loadSummary=False,
                                             resolution=pixdims[0])
        for idx, label in enumerate(atlas.labels):
            structure_maps[label.name] = fslimage_to_qpdata(atlas_map,
                                                            vol=idx,
                                                            name=label.name)
        return structure_maps