Esempio n. 1
0
def main(args):
    starttime = datetime.now()

    parser = parsefn()
    indir, outdir, maskimg, segment, chann, chanp, down, fwhm, noise, bins, levels, iters, thresh, mulpower, outnii, \
    vx, vz, chan = parse_inputs(parser, args)

    # make downsampled nii
    createnii(indir, down, chann, chanp, chan, outnii, vx, vz)

    # bias corr
    totaliters = ('%dx' % iters) * levels
    totaliters = totaliters[:-1]

    hist = [fwhm, noise, bins]
    conv = [totaliters, thresh]

    niidir = 'niftis'

    niiname = '%s/%s_%02dx_down_%s_chan.nii.gz' % (niidir, outnii, down, chan)

    corname = os.path.basename(niiname).split('.nii')[0]
    niicorr = os.path.join(niidir, '%s_corr.nii.gz' % corname)
    field = os.path.join(niidir, '%s_biasfield.nii.gz' % corname)
    mask = os.path.join(niidir, '%s_mask.nii.gz' % corname)

    with add_paths():
        biascorrnii(niiname, maskimg, segment, hist, conv, niicorr, mask, field)

        # up-sample bias field & mask
        biasnii = nib.load(field)
        bias = biasnii.get_data()
        biasres = scipy.ndimage.interpolation.zoom(bias, [1, 1, down])

        if maskimg == 1:
            masknii = nib.load(mask).get_data()
            maskres = scipy.ndimage.interpolation.zoom(masknii, [1, 1, down], order=1)
        else:
            maskres = None

        # sort files
        if chanp is None:
            file_list = sorted(glob.glob("%s/*.tif" % indir), key=numericalsort)
        else:
            file_list = sorted(glob.glob("%s/*%s%01d*.tif" % (indir, chanp, chann)), key=numericalsort)

        cpuload = 0.95
        cpus = multiprocessing.cpu_count()
        ncpus = int(cpuload * cpus)

        print("\n Correcting TIFF images in parallel using %02d cpus" % ncpus)

        Parallel(n_jobs=ncpus, backend='threading')(
            delayed(applycorr)(i, tif, outdir, biasres, down, mulpower, maskimg, maskres)
            for i, tif in enumerate(file_list))

        # print("\n Intensity correction done in %s ... Have a good day!\n" % (datetime.now() - starttime))

        statement.main(['Intensity correction', '%s' % (datetime.now() - starttime)])
Esempio n. 2
0
def main(args):
    starttime = datetime.now()

    parser = parsefn()
    inlbls, img, metric, outfile, s = parse_inputs(parser, args)

    # load img
    print("Reading Input Labels")
    nii = nib.load(img)
    data = nii.get_data()

    # read graph
    print("Reading ARA ontology structure_graph")
    miracl_home = os.environ['MIRACL_HOME']
    arastrctcsv = "%s/atlases/ara/ara_mouse_structure_graph_hemi_combined.csv" % miracl_home
    aragraph = pd.read_csv(arastrctcsv)

    # get lbls
    imglbls = getalllbls(data)

    # flatten
    dataflat = data.flatten()

    lblvols = []

    print("Computing volumes for input labels...")
    for i, inlbl in enumerate(inlbls):
        vol = computevolumes(aragraph, dataflat, inlbl, imglbls, metric)
        lblvols.append(vol)

    df = pd.DataFrame([inlbls, lblvols])
    if s == 1:
        df = df.T.sort_values(1, ascending=False)
    else:
        df = df.T

    df.columns = ['Labels', 'Volumes (# of voxels)']
    df.to_csv(outfile, index=False)

    # print ("\n Parent labels volume computation done in %s ... Have a good day!\n" % (datetime.now() - starttime))

    endstatement.main(task='Parent labels volume computation',
                      timediff='%s' % (datetime.now() - starttime))
Esempio n. 3
0
def run_endstatmenet(parser, args):
    miracl_utilfn_endstatement.main(args)