Ejemplo n.º 1
0
img_dict['PIN1'] = SpatialImage(img_dict['PIN1'],
                                voxelsize=voxelsize,
                                origin=ori)
PIN_signal_im = img_dict['PIN1']
PI_signal_im = img_dict['PI']

###############################################################################
# -- PI signal segmentation:
###############################################################################
from os.path import exists
seg_img_fname = image_dirname + path_suffix + splitext_zip(
    im_tif)[0] + '_seg.inr'
if not exists(seg_img_fname):
    print "\n - Performing isometric resampling of the image to segment..."
    from timagetk.algorithms import isometric_resampling
    img2seg = isometric_resampling(PI_signal_im)
    iso_vxs = np.array(img2seg.voxelsize)
    iso_shape = img2seg.shape

    print "\n - Performing adaptative histogram equalization of the image to segment..."
    # from equalization import z_slice_equalize_adapthist
    # img2seg = z_slice_equalize_adapthist(img2seg)
    from equalization import z_slice_contrast_stretch
    img2seg = z_slice_contrast_stretch(img2seg)

    # print "\n - Performing TagBFP signal substraction..."
    # import copy as cp
    # vxs = PI_signal_im.voxelsize
    # img_dict['TagBFP'] = SpatialImage(img_dict['TagBFP'], voxelsize=voxelsize, origin=ori)
    # substract_img = morphology(img_dict['TagBFP'], method='erosion', radius=3., iterations=3)
    # img2seg = cp.deepcopy(PI_signal_im)
Ejemplo n.º 2
0
list_img = []
print "\n# - Loading list of images for which to apply registration process:"
for ind, img_fname in enumerate(list_img_fname):
    print "  - Time-point {}, reading image {}...".format(ind, img_fname)
    im = imread(img_fname)
    if ref_ch_name.find('raw') != -1:
        im = z_slice_contrast_stretch(im)
    else:
        pass
    list_img.append(im)


# - 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)
Ejemplo n.º 3
0
 if exists(topomesh_file) and not force:
     print "Found PLY topomesh: '{}'".format(topomesh_file)
     detected_topomesh = read_ply_property_topomesh(
         topomesh_file)
 else:
     print "No topomesh file detected, running seed detection script..."
     # - Performs masked subtraction of signal:
     try:
         img[mask_img == 0] = 0
     except:
         pass
     else:
         print "Applied mask to membrane signal...",
     if iso_resampling:
         print "\nPerforming 'isometric_resampling'..."
         img = isometric_resampling(img)
     # - Performs NUCLEI image subtraction from membrane image:
     if no_nuc:
         # -- Reading NUCLEI intensity image:
         print " --> Reading nuclei image file {}".format(
             nuc_signal_fname)
         nuc_im = imread(image_dirname + nuc_path_suffix +
                         nuc_signal_fname)
         if iso_resampling:
             print " --> Performing 'isometric_resampling' of nuclei image..."
             nuc_im = isometric_resampling(nuc_im)
         # -- Gaussian Smoothing:
         print " --> Smoothing..."
         nuc_im = linear_filtering(nuc_im,
                                   std_dev=1.0,
                                   method='gaussian_smoothing')
# world["L1_expert_seeds"]["property_name_0"] = 'layer'
# world["L1_expert_seeds_vertices"]["polydata_colormap"] = load_colormaps()['Greens']

# EVALUATION
#---------------------------------------------------
evaluations = {}
L1_evaluations = {}
## Parameters
std_dev = 2.0
morpho_radius = 3
h_min = 230

# - EXPERT evaluation:
topomesh_file = image_dirname + xp_filename[:-4] + "_seed_wat_EXPERT_detection_topomesh.ply"
img = imread(image_dirname + xp_filename)
img = isometric_resampling(img)
# world.add(img,"iso_ref_image"+suffix, colormap="invert_grey", voxelsize=microscope_orientation*voxelsize)
size = np.array(img.shape)
voxelsize = np.array(img.voxelsize)

if exists(topomesh_file):
    detected_topomesh = read_ply_property_topomesh(topomesh_file)
else:
    print "Shape: ", img.shape, "; Size: ", img.voxelsize
    # -- Change following values, as required by watershed algorithm:
    #  - '0': watershed will fill these with other label
    #  - '1': background value (outside the biological object)
    vtx = list(expert_topomesh.wisps(0))
    if 0 in vtx or 1 in vtx:
        # --- Initialise relabelling dictionary:
        relabel = {v: v for v in vtx}
background_threshold = 2000.
smooth_img_bck = linearfilter(membrane_img,
                              param_str_2='-x 0 -y 0 -z 0 -sigma 3.0')
background_img = (smooth_img_bck < background_threshold).astype(np.uint16)
for it in xrange(10):
    background_img = morphology(
        background_img, param_str_2='-operation erosion -iterations 10')
seed_img += background_img
seed_img = SpatialImage(seed_img, voxelsize=membrane_img.voxelsize)
#world.add(seed_img,'seed_image',colormap='glasbey',alphamap='constant',bg_id=0)
segmented_filename = image_dirname + "/" + nomenclature_names[
    filename] + "/" + nomenclature_names[
        filename] + "_corrected_nuclei_seed.inr"
imsave(segmented_filename, seed_img)

seed_img = isometric_resampling(seed_img, option='label')

std_dev = 2.0
membrane_img = isometric_resampling(membrane_img)
vxs = membrane_img.voxelsize

try:
    from equalization import z_slice_contrast_stretch
    from slice_view import slice_view

except:
    import sys
    sys.path.append('/home/marie/SamMaps/scripts/TissueLab/')
    from equalization import z_slice_contrast_stretch
    from slice_view import slice_view
Ejemplo n.º 6
0
    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)
        im_float = imread(image_dirname + float_path_suffix + float_img_fname)
        if float_img_fname.find('iso') == -1:  # if not isometric, resample!
            im_float = isometric_resampling(im_float)
        print '  - t_{}h reference fname: {}'.format(t_ref, ref_img_fname)
        im_ref = imread(image_dirname + ref_path_suffix + ref_img_fname)
        if ref_img_fname.find('iso') == -1:  # if not isometric, resample!
            im_ref = isometric_resampling(im_ref)
        print ""
        res_trsf, res_im = registration(im_float,
                                        im_ref,
                                        method='rigid_registration',
                                        pyramid_highest_level=py_hl,
                                        pyramid_lowest_level=py_ll)
        print ""
        # - Save result image and tranformation:
        print "Writing image file: {}".format(rig_float_img_fname)
        imsave(res_path + rig_float_img_fname, res_im)
        # - Get result trsf filename:
Ejemplo n.º 7
0
        substract_img = imread(image_dirname + path_suffix + substract_img_fname)
        # substract the 'CLV3' signal from the 'PI' since it might have leaked:
        print "\n - Performing images substraction..."
        tmp_im = img2seg - substract_img
        tmp_im[img2seg <= substract_img] = 0
        img2seg = SpatialImage(tmp_im, voxelsize=vxs, origin=ori)
        del tmp_im
    # -- Display the image to segment:
    # world.add(img2seg,'{}_channel'.format(ref_ch_name), colormap='invert_grey', voxelsize=microscope_orientation*vxs)
    # world['{}_channel'.format(ref_ch_name)]['intensity_range'] = (-1, 2**16)
    # -- Adaptative histogram equalization of the image to segment:
    print "\n - Performing adaptative histogram equalization of the image to segment..."
    img2seg = z_slice_equalize_adapthist(img2seg)
    # -- Performs isometric resampling of the image to segment:
    print "\n - Performing isometric resampling of the image to segment..."
    img2seg = isometric_resampling(img2seg)
    iso_vxs = np.array(img2seg.voxelsize)
    iso_shape = img2seg.shape
    # -- Display the isometric version of the "equalized" image to segment:
    # world.add(img2seg,'{}_channel_equalized_isometric'.format(ref_ch_name), colormap='invert_grey', voxelsize=microscope_orientation*iso_vxs)
    # world['{}_channel_equalized_isometric'.format(ref_ch_name)]['intensity_range'] = (-1, 2**16)

    # - Create a seed image from the list of NUCLEI barycenters:
    print "\n - Creating a seed image from the list of NUCLEI barycenters..."
    # -- Read CSV file containing barycenter positions:
    nom_names = get_nomenclature_name(nom_file)
    signal_file = image_dirname + nom_names[raw_czi_fname] + '/' + nom_names[raw_czi_fname] + "_signal_data.csv"
    signal_data = pd.read_csv(signal_file, sep=',')
    center_x, center_y, center_z = signal_data['center_x'], signal_data['center_y'], signal_data['center_z']
    x, y, z = center_x.to_dict(), center_y.to_dict(), center_z.to_dict()
    labels = signal_data['Unnamed: 0'].to_dict()