예제 #1
0
        else:
            print "Loading SpatialImage:\n  {}".format(res_path + res_trsf_fname)
            res_img = imread(res_path + res_img_fname)
            list_res_img.append(res_img)
            continue

# add last reference image
list_res_img.append(list_iso_img[-1])  # add last reference image


# - Apply DEFORMABLE consecutive_registration on segmented images:
list_res_seg_img_fname = []
for ind, img in enumerate(list_iso_img[:-1]):
    # Apply DEFORMABLE consecutive registration to segmented image:
    print "\nApplying estimated {} transformation on '{}' to segmented image:".format('deformable', ref_ch_name)
    seg_path_suffix, seg_img_fname = get_nomenclature_segmentation_name(czi_base_fname.format(index2time[ind]), nom_file, ref_ch_name)
    trsf = list_res_trsf[ind]
    res_seg_img = apply_trsf(imread(image_dirname + seg_path_suffix + seg_img_fname), trsf, param_str_2='-nearest', template_img=list_iso_img[ind+1])
    res_seg_img[res_seg_img == 0] = back_id
    res_seg_img_fname = get_res_img_fname(seg_img_fname, index2time[ind+1], index2time[ind], 'iso-deformable')
    print "  - {}\n  --> {}".format(seg_img_fname, res_seg_img_fname)
    res_path = image_dirname + seg_path_suffix + '{}_registrations/'.format(trsf_type)
    if not exists(res_path + res_seg_img_fname) or force:
        imsave(res_path + res_seg_img_fname, res_seg_img)
    list_res_seg_img_fname.append(res_path + res_seg_img_fname)


# - Create reference segmented image list:
list_ref_seg_img_fname = []
for ind, img_fname in enumerate(list_img_fname[:-1]):
    seg_path_suffix, seg_img_fname = get_nomenclature_segmentation_name(czi_base_fname.format(index2time[ind+1]), nom_file, ref_ch_name)
예제 #2
0
    raise ValueError("Negative minimal area!")
force = args.force
if force:
    print "WARNING: any existing CSV files will be overwritten!"
else:
    print "Existing files will be kept."

# - Define variables AFTER argument parsing:
czi_fname = base_fname + "-T{}.czi".format(tp)

# Get unregistered image filename:
path_suffix, PI_signal_fname = get_nomenclature_channel_fname(
    czi_fname, nomenclature_file, membrane_ch_name)
path_suffix, PIN_signal_fname = get_nomenclature_channel_fname(
    czi_fname, nomenclature_file, 'PIN1')
path_suffix, seg_img_fname = get_nomenclature_segmentation_name(
    czi_fname, nomenclature_file, membrane_ch_name + "_raw")

# - To create a mask, edit a MaxIntensityProj with an image editor (GIMP) by adding 'black' (0 value):
# mask = image_dirname+'PIN1-GFP-CLV3-CH-MS-E1-LD-SAM4-MIP_PI-mask.png'
mask = ''

print "\n\n# - Reading PIN1 intensity image file {}...".format(
    PIN_signal_fname)
PIN_signal_im = imread(image_dirname + path_suffix + PIN_signal_fname)
# PIN_signal_im = isometric_resampling(PIN_signal_im)
# world.add(PIN_signal_im, 'PIN1 intensity image', colormap='viridis', voxelsize=PIN_signal_im.voxelsize)

print "\n\n# - Reading PI intensity image file {}...".format(PI_signal_fname)
PI_signal_im = imread(image_dirname + path_suffix + PI_signal_fname)
# PI_signal_im = isometric_resampling(PI_signal_im)
# world.add(PI_signal_im, 'PI intensity image', colormap='invert_grey', voxelsize=PI_signal_im.voxelsize)
예제 #3
0
            if not exists(res_path + res_x_ch_fname) or True:
                print "  - {}\n  --> {}".format(x_ch_fname, res_x_ch_fname)
                # --- Read the extra channel image file:
                x_ch_img = imread(image_dirname + x_ch_path_suffix +
                                  x_ch_fname)
                # --- Apply and save registered image:
                res_x_ch_img = apply_trsf(x_ch_img, res_trsf)
                imsave(res_path + res_x_ch_fname, res_x_ch_img)
            else:
                print "  - existing file: {}".format(res_x_ch_fname)
    else:
        print "No supplementary channels to register."

    # -- Apply estimated transformation to segmented image:
    if trsf_type == 'rigid':
        seg_path_suffix, seg_img_fname = get_nomenclature_segmentation_name(
            czi_base_fname.format(t), nomenclature_file, membrane_ch_name)
        if exists(image_dirname + seg_path_suffix + seg_img_fname):
            print "\nApplying estimated {} transformation on '{}' to segmented image:".format(
                trsf_type.upper(), membrane_ch_name)
            res_seg_img_fname = get_res_img_fname(seg_img_fname, t_ref,
                                                  t_float, trsf_type)
            if not exists(res_path + seg_img_fname) or force:
                print "  - {}\n  --> {}".format(seg_img_fname,
                                                res_seg_img_fname)
                # --- Read the segmented image file:
                seg_im = imread(image_dirname + seg_path_suffix +
                                seg_img_fname)
                res_seg_im = apply_trsf(seg_im,
                                        res_trsf,
                                        param_str_2=' -nearest')
                # --- Apply and save registered segmented image:
예제 #4
0
    float_path_suffix, float_img_fname = get_nomenclature_channel_fname(
        czi_base_fname.format(t_float), nom_file, ref_ch_name)
    ref_path_suffix, ref_img_fname = get_nomenclature_channel_fname(
        czi_base_fname.format(t_ref), nom_file, ref_ch_name)

    # - Get RIGID registered images filenames:
    rig_float_path_suffix = float_path_suffix + 'rigid_registrations/'
    rig_float_img_fname = get_res_img_fname(float_img_fname, t_ref, t_float,
                                            'iso-rigid')
    if t_ref != time_steps[-1]:
        ref_path_suffix += 'rigid_registrations/'
        ref_img_fname = get_res_img_fname(ref_img_fname,
                                          index2time[time2index[t_ref] + 1],
                                          t_ref, 'iso-rigid')

    seg_path_suffix, seg_img_fname = get_nomenclature_segmentation_name(
        czi_base_fname.format(t_float), nom_file, ref_ch_name)
    rig_seg_img_fname = get_res_img_fname(seg_img_fname, t_ref, t_float,
                                          'iso-rigid')
    res_path = image_dirname + rig_float_path_suffix

    try:
        assert exists(res_path + rig_seg_img_fname)
    except:
        # - Get the result image file name & path (output path), and create it if necessary:
        if not exists(res_path):
            mkdir(res_path)
        print "\n# - RIGID registration for t{}/t{}:".format(
            time2index[t_float], time2index[t_ref])
        py_hl = 3  # defines highest level of the blockmatching-pyramid
        py_ll = 1  # defines lowest level of the blockmatching-pyramid
        print '  - t_{}h floating fname: {}'.format(t_float, float_img_fname)
예제 #5
0
# -3- OUTPUT directory:
image_dirname = dirname + "nuclei_images/"

# -4- Define CZI channel names, the microscope orientation, nuclei and membrane channel names and extra channels that should also be registered:
channel_names = ['DIIV', 'PIN1', 'PI', 'TagBFP', 'CLV3']
microscope_orientation = -1  # inverted microscope!
back_id = 1

for tp, t in enumerate(time_steps):
    raw_czi_fname = czi_base_fname.format(t)
    print "\n\n# - Entering segmentation process for {}".format(raw_czi_fname)
    start = time.time()

    # - Defines segmented file name and path:
    seg_path_suffix, seg_img_fname = get_nomenclature_segmentation_name(raw_czi_fname, nom_file, ref_ch_name)
    if os.path.exists(image_dirname + seg_path_suffix + seg_img_fname) and not force:
        print "A segmentation file '{}' already exists, aborting now.".format(seg_img_fname)
        sys.exit(0)

    # - Get the image to segment:
    # -- Get the file name and path of the image to segment:
    path_suffix, img2seg_fname = get_nomenclature_channel_fname(raw_czi_fname, nom_file, ref_ch_name)
    print "\n - Loading image to segment: {}".format(img2seg_fname)
    img2seg = imread(image_dirname + path_suffix + img2seg_fname)
    vxs = np.array(img2seg.voxelsize)
    ori = np.array(img2seg.origin)
    # -- Get the file name and path of the channel to substract to the image to segment:
    # used to clear-out the cells for better segmentation
    if clearing_ch_name:
        path_suffix, substract_img_fname = get_nomenclature_channel_fname(raw_czi_fname, nom_file, clearing_ch_name)