Exemplo n.º 1
0
def mesh_contour_with_files(input_mesh,
                            input_labels,
                            output_mesh=None,
                            output_labels=None):
    """ TODO: use nibabel here """
    #from gifti import loadImage, saveImage, GiftiDataArray, GiftiImage
    #from gifti import GiftiImage_fromarray, GiftiImage_fromTriangles
    #from gifti import GiftiIntentCode, GiftiEncoding

    labels = loadImage(input_labels).arrays[0].data.astype(int)
    cor, triangles = loadImage(input_mesh).arrays

    contour_cor, contour_tri = mesh_contour(cor.data,
                                            triangles.data.astype(int), labels)
    k = GiftiImage_fromarray(contour_cor)
    k.arrays[0].intentString = "NIFTI_INTENT_POINTSET"
    k.addDataArray_fromarray(contour_tri,
                             GiftiIntentCode.NIFTI_INTENT_TRIANGLE)
    for a in k.arrays:
        a.encoding = GiftiEncoding.GIFTI_ENCODING_ASCII

    if output_mesh is None:
        output_mesh = non_existent_file(add_suffix(input_mesh, '_contour'))
    logger.info('saving to %s', output_mesh)
    k.save(output_mesh)
Exemplo n.º 2
0
def extract_sub_mesh_with_files(input_mesh, center_node, radius, 
                                output_mesh=None):
    from nibabel import gifti
    from nibabel.gifti import GiftiImage, GiftiDataArray
    from pyhrf.tools.io import read_mesh
    cor, tri, coord_sys = read_mesh(input_mesh)
    sub_cor, sub_tri = extract_sub_mesh(cor, tri, center_node, radius)
    
    #nimg = GiftiImage_fromTriangles(sub_cor, sub_tri)
    nimg = GiftiImage()
    intent = 'NIFTI_INTENT_POINTSET'
    nimg.add_gifti_data_array(GiftiDataArray.from_array(sub_cor,intent))
    intent = 'NIFTI_INTENT_TRIANGLE'
    nimg.add_gifti_data_array(GiftiDataArray.from_array(sub_tri,intent))

    if output_mesh is None:
        output_mesh = non_existent_file(add_suffix(input_mesh, '_sub'))
    pyhrf.verbose(1, 'Saving extracted mesh to %s' %output_mesh)
    gifti.write(nimg, output_mesh)
    return sub_cor, sub_tri, coord_sys
Exemplo n.º 3
0
def mesh_contour_with_files(input_mesh, input_labels, output_mesh=None, output_labels=None):
    """ TODO: use nibabel here """
    # from gifti import loadImage, saveImage, GiftiDataArray, GiftiImage
    # from gifti import GiftiImage_fromarray, GiftiImage_fromTriangles
    # from gifti import GiftiIntentCode, GiftiEncoding

    labels = loadImage(input_labels).arrays[0].data.astype(int)
    cor, triangles = loadImage(input_mesh).arrays

    contour_cor, contour_tri = mesh_contour(cor.data, triangles.data.astype(int), labels)
    k = GiftiImage_fromarray(contour_cor)
    k.arrays[0].intentString = "NIFTI_INTENT_POINTSET"
    k.addDataArray_fromarray(contour_tri, GiftiIntentCode.NIFTI_INTENT_TRIANGLE)
    for a in k.arrays:
        a.encoding = GiftiEncoding.GIFTI_ENCODING_ASCII

    if output_mesh is None:
        output_mesh = non_existent_file(add_suffix(input_mesh, "_contour"))
    logger.info("saving to %s", output_mesh)
    k.save(output_mesh)
Exemplo n.º 4
0
def mesh_contour_with_files(input_mesh, input_labels, output_mesh=None,
                            output_labels=None):
    from gifti import loadImage, saveImage, GiftiDataArray, GiftiImage
    from gifti import GiftiImage_fromarray, GiftiImage_fromTriangles
    from gifti import GiftiIntentCode, GiftiEncoding

    labels = loadImage(input_labels).arrays[0].data.astype(int)
    cor, triangles = loadImage(input_mesh).arrays

    contour_cor, contour_tri = mesh_contour(cor.data, triangles.data.astype(int),
                                            labels)
    k = GiftiImage_fromarray(contour_cor)
    k.arrays[0].intentString = "NIFTI_INTENT_POINTSET"
    k.addDataArray_fromarray(contour_tri, GiftiIntentCode.NIFTI_INTENT_TRIANGLE)
    for a in k.arrays:
        a.encoding = GiftiEncoding.GIFTI_ENCODING_ASCII

    if output_mesh is None:
        output_mesh = non_existent_file(add_suffix(input_mesh, '_contour'))
    pyhrf.verbose(1, 'saving to %s' %output_mesh)
    k.save(output_mesh)
Exemplo n.º 5
0
def extract_sub_mesh_with_files(input_mesh,
                                center_node,
                                radius,
                                output_mesh=None):
    from nibabel import gifti
    from nibabel.gifti import GiftiImage, GiftiDataArray
    from pyhrf.tools._io import read_mesh
    cor, tri, coord_sys = read_mesh(input_mesh)
    sub_cor, sub_tri = extract_sub_mesh(cor, tri, center_node, radius)

    #nimg = GiftiImage_fromTriangles(sub_cor, sub_tri)
    nimg = GiftiImage()
    intent = 'NIFTI_INTENT_POINTSET'
    nimg.add_gifti_data_array(GiftiDataArray.from_array(sub_cor, intent))
    intent = 'NIFTI_INTENT_TRIANGLE'
    nimg.add_gifti_data_array(GiftiDataArray.from_array(sub_tri, intent))

    if output_mesh is None:
        output_mesh = non_existent_file(add_suffix(input_mesh, '_sub'))
    logger.info('Saving extracted mesh to %s', output_mesh)
    gifti.write(nimg, output_mesh)
    return sub_cor, sub_tri, coord_sys