Beispiel #1
0
def process_block(image_in, ndim, blockreduce, func, blockoffset, blocksize,
                  margin, fullsize, mo, is_labelimage, relabel, neighbourmerge,
                  save_fwmap, maxlabel, mpi):
    """Write a block of data into a hdf5 file."""

    # open data for reading
    im = Image(image_in, permission='r')
    im.load(mpi.comm, load_data=False)

    # get the indices into the input and output datasets
    # TODO: get indices from attributes
    # TODO: get from mpi.get_blocks
    set_slices_in_and_out(im, mo, blocksize, margin, fullsize)

    # simply copy the data from input to output
    """NOTE:
    it is assumed that the inputs are not 4D labelimages
    """
    if ndim == 4:
        mo.write(im.slice_dataset())
        im.close()
        return
    if ((not is_labelimage)
            or ((not relabel) and (not neighbourmerge) and (not blockreduce))):
        data = im.slice_dataset()
        #datatype = 'uint16'
        #from skimage.util.dtype import convert
        #data = convert(data, np.dtype(datatype), force_copy=False)
        mo.write(data)
        im.close()
        return

    # forward map to relabel the blocks in the output
    if relabel:
        # FIXME: make sure to get all data in the block
        fw, maxlabel = relabel_block(im.ds[:], maxlabel, mpi)
        if save_fwmap:
            comps = im.split_path()
            fpath = '{}_{}.npy'.format(comps['base'], comps['int'][1:])
            np.save(fpath, fw)
        if (not neighbourmerge) and (not blockreduce):
            data = im.slice_dataset()
            mo.write(fw[data])
            im.close()
            return
    else:
        ulabels = np.unique(im.ds[:])
        fw = [l for l in range(0, np.amax(ulabels) + 1)]
        fw = np.array(fw)

    # blockwise reduction of input datasets
    if blockreduce is not None:
        pass
    else:
        data = im.slice_dataset()

    # merge overlapping labels
    fw = merge_overlap(fw, im, mo, data, margin)
    mo.write(fw[data])
    im.close()
Beispiel #2
0
def generate_report(image_in, info_dict={}, ioff=True):
    """Generate a QC report of the segmentation process."""

    report_type = 'reseg'

    # Turn interactive plotting on/off.
    if ioff:
        plt.ioff()
    else:
        plt.ion()

    # Get paths from image if info_dict not provided.
    if not info_dict:
        im = Image(image_in)
        info_dict['paths'] = im.split_path()  # FIXME: out_base
        info_dict['paths']['out_base'] = info_dict['paths']['base']
        im.close()
        info_dict['parameters'] = get_parameters(info_dict, report_type)
        # info_dict['centreslices'] = get_centreslices(info_dict, idss=[])
        info_dict['medians'] = {}

    # Create the axes.
    figsize = (18, 9)
    gridsize = (1, 4)
    f = plt.figure(figsize=figsize, constrained_layout=False)
    gs0 = gridspec.GridSpec(gridsize[0], gridsize[1], figure=f)
    # axs = [gen_orthoplot(f, gs0[j, i]) for j in range(0, 2) for i in range(0, 4)]
    axs = [
        gen_orthoplot(f, gs0[j, i]) for j in range(0, gridsize[0])
        for i in range(0, gridsize[1])
    ]

    # Plot the images and graphs. vmaxs = [15000] + [5000] * 7
    info_dict['plotinfo'] = {'vmax': 10000}
    plot_images(axs, info_dict)

    # Add annotations and save as pdf.
    reseg_id = 'axis{:01d}-seam{:02d}-j{:03d}'.format(info_dict['axis'],
                                                      info_dict['seam'],
                                                      info_dict['j'])
    header = 'mLSR-3D Quality Control'
    figtitle = '{}: {} \n {}'.format(
        header,
        report_type,
        reseg_id,
    )
    figpath = '{}_{}_{}-report.pdf'.format(
        info_dict['paths']['out_base'],
        report_type,
        reseg_id,
    )
    print('writing report to {}'.format(figpath))
    f.suptitle(figtitle, fontsize=14, fontweight='bold')
    add_titles(axs, info_dict)
    f.savefig(figpath)
    plt.close(f)
Beispiel #3
0
def generate_report(image_in, info_dict={}, ioff=True):
    """Generate a QC report of the mask creation process."""

    report_type = 'mask'

    # Turn interactive plotting on/off.
    if ioff:
        plt.ioff()
    else:
        plt.ion()

    # Get paths from image if info_dict not provided.
    if not info_dict:
        im = Image(image_in)
        info_dict['paths'] = im.split_path()
        im.close()
        info_dict['parameters'] = get_parameters(info_dict, report_type)
        info_dict['centreslices'] = get_centreslices(info_dict)
        # info_dict['medians'] = get_medians(info_dict)

    # Create the axes.
    figsize = (18, 9)
    gridsize = (1, 4)
    f = plt.figure(figsize=figsize, constrained_layout=False)
    gs0 = gridspec.GridSpec(gridsize[0], gridsize[1], figure=f)
    axs = [gen_orthoplot(f, gs0[0, i]) for i in range(0, 4)]

    # Plot the images and graphs.
    info_dict['plotinfo'] = {'vmax': 10000}
    plot_images(axs, info_dict)

    # Add annotations and save as pdf.
    header = 'mLSR-3D Quality Control'
    figtitle = '{}: {} \n {}'.format(
        header,
        report_type,
        info_dict['paths']['fname']
        )
    figpath = '{}_{}-report.pdf'.format(
        info_dict['paths']['base'],
        report_type
        )
    f.suptitle(figtitle, fontsize=14, fontweight='bold')
    add_titles(axs, info_dict)
    f.savefig(figpath)
Beispiel #4
0
def get_info_dict(image_in, info_dict={}, report_type='bfc', channel=0):

    im = Image(image_in)
    im.load(load_data=False)
    info_dict['elsize'] = {dim: im.elsize[i] for i, dim in enumerate(im.axlab)}
    info_dict['paths'] = im.split_path()  # FIXME: out_base
    info_dict['paths']['out_base'] = info_dict['paths']['base']
    im.close()

    ppath = '{}.pickle'.format(info_dict['paths']['base'])
    with open(ppath, 'rb') as f:
        info_dict['parameters'] = pickle.load(f)
    info_dict['centreslices'] = get_centreslices(info_dict)

    # info_dict['medians'] = get_medians(info_dict)
    info_dict['medians'], info_dict['means'], info_dict['stds'], info_dict[
        'n_samples'] = get_means_and_stds(info_dict, ch=channel, thr=1000)

    return info_dict
Beispiel #5
0
def get_paths(image_in,
              resolution_level=-1,
              channel=0,
              outputstem='',
              step='',
              save_steps=False):
    """Get the parameters for the preprocessing step."""

    # get paths from input file
    if resolution_level != -1:  # we should have an Imaris pyramid
        image_in = '{}/DataSet/ResolutionLevel {}'.format(
            image_in, resolution_level)
    im = Image(image_in, permission='r')
    im.load(load_data=False)
    paths = im.split_path()
    im.close()

    # define output basename
    paths['out_base'] = outputstem

    # define h5 output template
    paths['out_h5'] = '{}.h5/{}'.format(paths['out_base'], '{}')

    # define output for main results and intermediate steps
    if not outputstem:
        paths['main'] = paths['steps'] = ''
    else:
        ### FIXME ????????????? what is this?
        if save_steps:
            paths['main'] = paths['steps'] = paths['out_h5']
        else:
            paths['main'] = paths['out_h5']
            paths['steps'] = paths['out_h5']

    # define output for parameters
    paths['params'] = '{}.pickle'.format(paths['out_base'], step)

    return paths
Beispiel #6
0
def generate_report(image_in, info_dict={}, ioff=True):
    """Generate a QC report of the segmentation process."""

    report_type = 'seg'

    # Turn interactive plotting on/off.
    if ioff:
        plt.ioff()
    else:
        plt.ion()

    # Get paths from image if info_dict not provided.
    if not info_dict:
        im = Image(image_in)
        info_dict['paths'] = im.split_path()  # FIXME: out_base
        info_dict['paths']['out_base'] = info_dict['paths']['base']
        im.close()
        info_dict['parameters'] = load_parameters(
            info_dict['paths']['out_base'])
        info_dict['centreslices'] = get_centreslices(
            info_dict,
            idss=[
                'mean_mask',
                'memb/planarity_mask',
                'memb/mean',
                'memb/mean_smooth',
                'chan/ch00',
                'nucl/dapi_mask',
                'nucl/dapi_preprocess',
                'segm/labels_edt',
                'segm/labels_memb',
                'segm/labels_memb_del',
                'segm/seeds_edt',
                'segm/seeds_mask',
                'segm/seeds_peaks_dil',
            ])
        info_dict['medians'] = {}

    # Create the axes.
    figsize = (18, 9)
    gridsize = (2, 4)
    f = plt.figure(figsize=figsize, constrained_layout=False)
    gs0 = gridspec.GridSpec(gridsize[0], gridsize[1], figure=f)
    axs = [
        gen_orthoplot(f, gs0[j, i]) for j in range(0, 2) for i in range(0, 4)
    ]

    # Plot the images and graphs. vmaxs = [15000] + [5000] * 7
    info_dict['plotinfo'] = {'vmax': 10000}
    plot_images(axs, info_dict)

    # Add annotations and save as pdf.
    header = 'mLSR-3D Quality Control'
    figtitle = '{}: {} \n {}'.format(header, report_type,
                                     info_dict['paths']['fname'])
    figpath = '{}_{}-report.pdf'.format(info_dict['paths']['out_base'],
                                        report_type)
    f.suptitle(figtitle, fontsize=14, fontweight='bold')
    add_titles(axs, info_dict)
    f.savefig(figpath)

    info_dict.clear()