print "\n# - Creating seed image from EXPERT seed positions..."
    xp_seed_pos = expert_topomesh.wisp_property('barycenter', 0)
    xp_seed_pos = {
        k: v * microscope_orientation
        for k, v in xp_seed_pos.items()
    }
    # --- Create the seed image:
    seed_img = seed_image_from_points(size, voxelsize, xp_seed_pos, 2., 0)
    # --- Add background position:
    background_threshold = 2000.
    smooth_img_bck = linear_filtering(img,
                                      std_dev=3.0,
                                      method='gaussian_smoothing')
    background_img = (smooth_img_bck < background_threshold).astype(np.uint16)
    for it in xrange(15):
        background_img = morphology(
            background_img, param_str_2='-operation erosion -iterations 10')
    # ---- Detect small regions defined as background and remove them:
    connected_background_components, n_components = nd.label(background_img)
    components_area = nd.sum(np.ones_like(connected_background_components),
                             connected_background_components,
                             index=np.arange(n_components) + 1)
    largest_component = (np.arange(n_components) +
                         1)[np.argmax(components_area)]
    background_img = (
        connected_background_components == largest_component).astype(np.uint16)
    # ---- Finaly add the background and make a SpatialImage:
    seed_img[background_img == 1] = 1
    del smooth_img_bck, background_img
    seed_img = SpatialImage(seed_img, voxelsize=voxelsize)
    # world.add(seed_img,"seed_image", colormap="glasbey", alphamap="constant",voxelsize=microscope_orientation*voxelsize, bg_id=0)
Example #2
0
                        print " --> Adaptative Histogram Equalization..."
                        img = z_slice_equalize_adapthist(img)
                    if rescaling == 'ContrastStretch':
                        print " --> Contrast Stretching..."
                        img = z_slice_contrast_stretch(img)
                    if std_dev != 0:
                        print " --> 'gaussian_smoothing' with std_dev={}...".format(
                            std_dev)
                        img = linear_filtering(img,
                                               'gaussian_smoothing',
                                               std_dev=std_dev)

                    # - Performs seed detection:
                    print " --> Closing-Opening Alternate Sequencial Filter..."
                    asf_img = morphology(
                        img,
                        max_radius=morpho_radius,
                        method='co_alternate_sequential_filter')
                    print " --> H-transform: local minima detection..."
                    ext_img = h_transform(asf_img,
                                          h=h_min,
                                          method='h_transform_min')
                    print " --> Components labelling..."
                    con_img = region_labeling(ext_img,
                                              low_threshold=1,
                                              high_threshold=h_min,
                                              method='connected_components')
                    nb_connectec_comp = len(np.unique(con_img.get_array()))
                    print nb_connectec_comp, "seeds detected!"
                    if nb_connectec_comp <= 3:
                        print "Not enough seeds, aborting!"
                        continue
positions = array_dict(microscope_orientation * positions.values(),
                       positions.keys())

# Create a seed image fro the nuclei barycenters:
seed_img = seed_image_from_points(membrane_img.shape,
                                  membrane_img.voxelsize,
                                  positions,
                                  background_label=0)

# Add the "background seed":
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:
Example #4
0
base_fname, ext = splitext(fname)
image = imread(base_dir + fname)
image.voxelsize

iso_image = isometric_resampling(image, method='min', option='cspline')
iso_image.shape

iso_image = global_contrast_stretch(iso_image)
# iso_image = z_slice_contrast_stretch(iso_image, pc_min=1.5)
smooth_image = linear_filtering(iso_image,
                                method="gaussian_smoothing",
                                sigma=1.,
                                real=True)

asf_image = morphology(iso_image,
                       method="oc_alternate_sequential_filter",
                       max_radius=1)

xsh, ysh, zsh = iso_image.shape
mid_x, mid_y, mid_z = int(xsh / 2.), int(ysh / 2.), int(zsh / 2.)

from timagetk.visu.mplt import grayscale_imshow
from timagetk.visu.stack import stack_browser
grayscale_imshow([iso_image, smooth_image, asf_image], slice_id=mid_z)

stack_browser(asf_image)

selected_hmin = profile_hmin(smooth_image,
                             x=mid_x,
                             z=mid_z,
                             plane='x',
Example #5
0
iso_image = isometric_resampling(image, method='min', option='cspline')
iso_image.shape

st_img1 = global_contrast_stretch(iso_image)
st_img2 = z_slice_equalize_adapthist(iso_image)

from timagetk.visu.mplt import grayscale_imshow
grayscale_imshow([iso_image, st_img1, st_img2],
                 100,
                 title=[
                     "Original", "global_contrast_stretch",
                     "z_slice_equalize_adapthist"
                 ])

seed_detect_img = morphology(st_img2, "erosion", radius=1)

seed_detect_img = morphology(seed_detect_img,
                             "coc_alternate_sequential_filter",
                             max_radius=1,
                             iterations=2)
seed_detect_img = linear_filtering(seed_detect_img,
                                   method="gaussian_smoothing",
                                   sigma=1.,
                                   real=True)

xsh, ysh, zsh = iso_image.shape
mid_x, mid_y, mid_z = int(xsh / 2.), int(ysh / 2.), int(zsh / 2.)
selected_hmin = profile_hmin(seed_detect_img,
                             x=mid_x,
                             z=mid_z,
Example #6
0
    from timagetk.plugins import linear_filtering, morphology
    from timagetk.plugins import h_transform
    from timagetk.plugins import region_labeling, segmentation
    from timagetk.plugins import labels_post_processing
except ImportError:
    raise ImportError('Import Error')

out_path = './results/' # to save results
# we consider an input image
# SpatialImage instance
input_img = imread(data_path('input.tif'))

# optional denoising block
smooth_img = linear_filtering(input_img, std_dev=2.0,
                              method='gaussian_smoothing')
asf_img = morphology(smooth_img, max_radius=3,
                     method='co_alternate_sequential_filter')

ext_img = h_transform(asf_img, h=150,
                      method='h_transform_min')
con_img = region_labeling(ext_img, low_threshold=1,
                          high_threshold=150,
                          method='connected_components')
seg_img = segmentation(smooth_img, con_img, control='first',
                       method='seeded_watershed')

# optional post processig block
pp_img = labels_post_processing(seg_img, radius=1,
                                iterations=1,
                                method='labels_erosion')

res_name = 'example_segmentation.tif'
Example #7
0
def test_plugin_2():
    im = imread(data_path('filtering_src.inr'))
    im_ref = imread(data_path('morpho_erosion_default.inr'))
    output = morphology(im, method='erosion')
    np.testing.assert_array_equal(output, im_ref)