Example #1
0
def add_channel_regitration(czi_base_fname,
                            nomenclature_file,
                            ch_name,
                            trsf_type,
                            temp_reg,
                            image_dirname,
                            colormap='invert_grey'):
    """
    Add the registered image to tissuelab world.
    """
    for n, (t_ref, t_float) in enumerate(temp_reg):
        # -- Get the reference CZI file names:
        ref_czi_fname = czi_base_fname.format(t_ref)
        # -- Get the reference INR file names:
        ref_path_suffix, ref_img_fname = get_nomenclature_channel_fname(
            ref_czi_fname, nomenclature_file, ch_name)

        if n == 0:
            print "Reading last time-point (t{}) image filename: {}".format(
                t_ref, ref_img_fname)
            ref_im = imread(image_dirname + ref_path_suffix + ref_img_fname)
            if ch_name.find('raw') != -1:
                ref_im = z_slice_equalize_adapthist(ref_im)
            world.add(ref_im, ref_img_fname, colormap='Reds')

        # -- Get the float CZI file names:
        float_czi_fname = czi_base_fname.format(t_float)
        # -- Get the float INR file names:
        float_path_suffix, float_img_fname = get_nomenclature_channel_fname(
            float_czi_fname, nomenclature_file, ch_name)
        # --- Get RESULT rigid transformation image filename:
        res_path_suffix = float_path_suffix + trsf_type + "_registrations/"
        res_img_fname = get_res_img_fname(float_img_fname, t_ref, t_float,
                                          trsf_type)

        # -- Read RESULT image file:
        res_im = imread(image_dirname + res_path_suffix + res_img_fname)
        print "Reading result floating (t{}) image filename: {}".format(
            t_float, res_img_fname)
        world.add(res_im, res_img_fname, colormap='Greens')
    return "Done."
        raise ValueError("Unknown custom path to 'SamMaps' for this system...")
    sys.path.append(SamMaps_dir+'/scripts/lib/')

    from nomenclature import splitext_zip
    from nomenclature import get_res_img_fname
    from nomenclature import get_nomenclature_channel_fname

    image_dirname = dirname + "nuclei_images/"
    nomenclature_file = SamMaps_dir + "nomenclature.csv"
    base_fname = "qDII-CLV3-PIN1-PI-{}-LD-SAM{}".format(XP, SAM)
    czi_fname = base_fname + "-T{}.czi"
    time_steps = [0, 5, 10, 14]

    ext = '.inr.gz'
    cmd = "convert -delay 100"
    suffix = '{}-D_{}-{}scaled_arrowheads'.format(PIN_func_fname[3:], sampling_distance2wall, "PIN_signal-" if PIN_channel else "")
    for tp in time_steps:
        ref_czi_fname = czi_fname.format(tp)
        signal_path, signal_fname = get_nomenclature_channel_fname(ref_czi_fname, nomenclature_file, "PIN1")
        if tp != time_steps[-1]:
            # Get RIDIG registered on last time-point filename:
            signal_fname = get_res_img_fname(signal_fname, time_steps[-1], tp, 'rigid')
        png_name = image_dirname + splitext_zip(signal_fname)[0] + suffix + '.png'
        cmd += " {}".format(png_name)

    cmd += " {}.gif".format(image_dirname + base_fname + suffix)
    print cmd

    os.system(cmd)

Example #3
0
# - Resample to isometric voxelsize to be able to apply it to isometric segmented image:
print "\nResample to isometric voxelsize to be able to apply it to isometric segmented image:"
list_iso_img = [isometric_resampling(im) for im in list_img]


from timagetk.algorithms import blockmatching
trsf_type = 'iso-deformable'
list_res_trsf, list_res_img = [], []
for ind, sp_img in enumerate(list_iso_img):
    if ind < len(list_iso_img) - 1:
        # --- filenames to save:
        img_path, img_fname = split(list_img_fname[ind])
        img_path += "/"
        # -- get the result image file name & path (output path), and create it if necessary:
        res_img_fname = get_res_img_fname(img_fname, index2time[ind+1], index2time[ind], trsf_type)
        res_path = img_path + '{}_registrations/'.format(trsf_type)
        # -- get DEFORMABLE registration result trsf filename and write trsf:
        res_trsf_fname = get_res_trsf_fname(img_fname, index2time[ind+1], index2time[ind], trsf_type)
        if exists(res_path + res_trsf_fname) and not force:
            print "Found saved {} registered image and transformation!".format(trsf_type)
            print "Loading BalTransformation:\n  {}".format(res_path + res_img_fname)
            res_trsf = bal_trsf.BalTransformation()
            res_trsf.read(res_path + res_trsf_fname)
            list_res_trsf.append(res_trsf)
        else:
            if not exists(res_path):
                print "Creating folder: {}".format(res_path)
                mkdir(res_path)
            # --- rigid registration
            print "\nPerforming rigid registration of t{} on t{}:".format(ind,
Example #4
0
time_reg_list = [(t_ref, t) for t in t_float_list]
time2index = {t: n for n, t in enumerate(time_steps)}

# Test if we really have a sequence to register:
# not_sequence = True if time2index[t_ref] - time2index[t_float_list[0]] > 1 else False
not_sequence = True if len(time_steps) == 2 else False

# - Build the list of result transformation filenames to check if they exist (if, not they will be computed):
# res_trsf_list = []
seq_res_trsf_list = []
for t_ref, t_float in time_reg_list:  # 't' here refer to 't_float'
    float_img_path, float_img_fname = split(
        list_img_fname[time2index[t_float]])
    float_img_path += "/"
    # - Get the result image file name & path (output path), and create it if necessary:
    res_img_fname = get_res_img_fname(float_img_fname, t_ref, t_float,
                                      trsf_type)
    res_path = float_img_path + '{}_registrations/'.format(trsf_type)
    # - Get sequence registration result trsf filename and write trsf:
    # res_trsf_list.append(res_path + get_res_trsf_fname(float_img_fname, t_ref, t_float, trsf_type))
    seq_res_trsf_list.append(res_path + get_res_trsf_fname(
        float_img_fname, t_ref, t_float, "sequence_" + trsf_type))

print ""
for f in seq_res_trsf_list:
    print "Existing tranformation file {}: {}\n".format(f, exists(f))

list_img = []
print "\n# - Loading list of images for which to apply registration process:"
for n, img_fname in enumerate(list_img_fname):
    print "  - Time-point {}, reading image {}...".format(n, img_fname)
    im = imread(img_fname)
extra_channels = list(set(channel_names) - set([membrane_ch_name]))
# By default do not recompute deformation when an associated file exist:
force = True

# 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")

if tp != time_steps[-1]:
    path_suffix += 'rigid_registrations/'
    # Get RIDIG registered on last time-point filename:
    PI_signal_fname = get_res_img_fname(PI_signal_fname, time_steps[-1], tp,
                                        'rigid')
    PIN_signal_fname = get_res_img_fname(PIN_signal_fname, time_steps[-1], tp,
                                         'rigid')
    seg_img_fname = get_res_img_fname(seg_img_fname, time_steps[-1], tp,
                                      'rigid')

back_id = 1

# - 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)
Example #6
0
     # - Blockmatching registration:
     out_trsf, _ = registration(float_img, ref_img, method=trsf_type, pyramid_lowest_level=py_ll)
     # -- Save the transformation matrix:
     print "--> Saving {} transformation file: '{}'".format(trsf_type.upper(), out_trsf_fname)
     save_trsf(out_trsf, out_folder + out_trsf_fname)
 elif write_cons_img or extra_im is not None or seg_im is not None:
     print "\nFound existing tranformation t{}->t{}!".format(i_float, i_ref)
     print "--> Reading {} transformation file: '{}'".format(trsf_type.upper(), out_trsf_fname)
     out_trsf = read_trsf(out_folder + out_trsf_fname)
 else:
     print "\nFound existing tranformation t{}->t{}!".format(i_float, i_ref)
     print "--> Nothing left to do here..."
 if write_cons_img:
     print "\n{} registration of the float intensity image:".format(trsf_type.upper())
     # - Defines the registered image filename (output):
     out_img_fname = get_res_img_fname(float_img_fname, t_ref, t_float, trsf_type)
     if not exists(join(out_folder, out_img_fname)) or force:
         # -- Apply the transformation to the intensity image:
         print "--> Apply tranformation to the float intensity image..."
         out_img = apply_trsf(float_img, trsf=out_trsf, template_img=ref_img)
         # -- Save the registered image:
         print "--> Saving t{} registered intensity image: '{}'".format(i_float, out_img_fname)
         imsave(out_folder + out_img_fname, out_img)
         del out_img
     else:
         print "--> Found existing t{} registered intensity image: '{}'".format(i_float, out_img_fname)
 if extra_im is not None:
     print "\n{} registration of the EXTRA intensity image:".format(trsf_type.upper())
     # -- Defines the registered extra intensity image filename (output):
     ximg_path, ximg_fname = split(indexed_ximg_fnames[i_float])
     out_ximg_fname = get_res_img_fname(ximg_fname, t_ref, t_float, trsf_type)
Example #7
0
time_reg_list = [(t, time_steps[n + 1]) for n, t in enumerate(time_steps[:-1])]
time_reg_list.reverse()
time2index = {t: n for n, t in enumerate(time_steps)}
index2time = {t: n for n, t in time2index.items()}

for t_float, t_ref in time_reg_list:
    # - Load intensity images filenames:
    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:
Example #8
0
list_comp_tsrf, list_res_img = sequence_registration(
    list_img, method='sequence_{}_registration'.format(trsf_type))

force = True
ref_im = list_img[-1]  # reference image is the last time-point
time2index = {t: n for n, t in enumerate(time_steps)}
composed_trsf = zip(list_comp_tsrf, time_steps[:-1])
for trsf, t in composed_trsf:  # 't' here refer to 't_float'
    # - Get the reference file name & path:
    ref_img_path, ref_img_fname = split(list_img_fname[-1])
    # - Get the float file name & path:
    float_im = list_img[time2index[t]]
    float_img_path, float_img_fname = split(list_img_fname[time2index[t]])
    float_img_path += "/"
    # - Get the result image file name & path (output path), and create it if necessary:
    res_img_fname = get_res_img_fname(float_img_fname, time_steps[-1], t,
                                      trsf_type)
    res_path = float_img_path + '{}_registrations/'.format(trsf_type)
    if not exists(res_path):
        mkdir(res_path)
    # - Get result trsf filename and write trsf:
    res_trsf_fname = get_res_trsf_fname(float_img_fname, time_steps[-1], t,
                                        trsf_type)

    if not exists(res_path + res_trsf_fname) or force:
        if t == time_steps[-2]:
            # -- No need to "adjust" for time_steps[-2]/time_steps[-1] registration since it is NOT a composition:
            print "\n# - Saving {} t{}/t{} registration:".format(
                trsf_type.upper(), time2index[t], time2index[time_steps[-1]])
            res_trsf = trsf
            res_im = list_res_img[-1]
        else: