How to use the mahotas.label function in mahotas

To help you get started, we’ve selected a few mahotas examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Rhoana / dojo / _dojo / scripts / finalizesplit.py View on Github external
label_id = input['id']
i_js = input['line']
bbox = input['bbox']
click = input['click']

s_tile = np.zeros(tile.shape)

s_tile[tile == label_id] = 1

#mh.imsave('/tmp/seg.tif', s_tile.astype(np.uint8))


for c in i_js:
  s_tile[c[1], c[0]] = 0

label_image,n = mh.label(s_tile)

if (n!=3):
  print 'ERROR',n

# check which label was selected
selected_label = label_image[click[1], click[0]]

for c in i_js:
  label_image[c[1], c[0]] = selected_label # the line belongs to the selected label


mh.imsave('/tmp/seg2.tif', 10*label_image.astype(np.uint8))


# update the segmentation data
github luispedro / mahotas / mahotas / demos / nuclear.py View on Github external
plt.subplot(3,2,1)
f = mahotas.demos.load('nuclear')
f = f[:,:,0]
plt.title('input image, first channel')
plt.imshow(f)


plt.subplot(3,2,2)
f = mahotas.gaussian_filter(f, 4)
f = (f> f.mean())
plt.title('gaussian_filter')
plt.imshow(f)


plt.subplot(3,2,3)
labeled, n_nucleus  = mahotas.label(f)
plt.title('Found {} nuclei.'.format(n_nucleus))
plt.imshow(labeled)


plt.subplot(3,2,4)
sizes = mahotas.labeled.labeled_size(labeled)
too_big = np.where(sizes > 10000)
labeled = mahotas.labeled.remove_regions(labeled, too_big)
plt.title('remove_regions')
plt.imshow(labeled)


plt.subplot(3,2,5)
labeled = mahotas.labeled.remove_bordering(labeled)
plt.title('remove_bordering')
plt.imshow(labeled)
github urakubo / UNI-EM / dojo / controller.py View on Github external
first_point,last_point = (i_js[0],i_js[-1])

    bind = lambda x: tuple(min(x[i] - bb[2*i], brush_mask.shape[1-i]-1) for i in range(1,-1,-1))
    first_points, last_points = (bind(x) for x in [first_point, last_point])

    end_points[first_points],end_points[last_points] = (True, True)
    end_points = mh.morph.dilate(end_points, np.ones((2*brush_size, 2*brush_size)))

    # compute seeds
    seed_mask = np.zeros(brush_mask.shape,dtype=bool)
    # seed_mask[outside_brush_mask & brush_mask] = True
    seed_mask[outside_brush_mask] = True
    seed_mask[frame] = True
    # seed_mask[corners] = False
    seed_mask[end_points] = False
    seeds,n = mh.label(seed_mask)

    # remove small regions
    sizes = mh.labeled.labeled_size(seeds)
    min_seed_size = 5
    too_small = np.where(sizes < min_seed_size)
    seeds = mh.labeled.remove_regions(seeds, too_small).astype(np.uint8)

    #
    # run watershed
    #
    ws = mh.cwatershed(brush_image.max() - brush_image, seeds)

    lines_array = np.zeros(ws.shape,dtype=np.uint8)
    lines = []

    for y in range(ws.shape[0]-1):
github urakubo / UNI-EM / dojo / controller_.py View on Github external
first_point,last_point = (i_js[0],i_js[-1])

    bind = lambda x: tuple(min(x[i] - bb[2*i], brush_mask.shape[1-i]-1) for i in range(1,-1,-1))
    first_points, last_points = (bind(x) for x in [first_point, last_point])

    end_points[first_points],end_points[last_points] = (True, True)
    end_points = mh.morph.dilate(end_points, np.ones((2*brush_size, 2*brush_size)))

    # compute seeds
    seed_mask = np.zeros(brush_mask.shape,dtype=bool)
    # seed_mask[outside_brush_mask & brush_mask] = True
    seed_mask[outside_brush_mask] = True
    seed_mask[frame] = True
    # seed_mask[corners] = False
    seed_mask[end_points] = False
    seeds,n = mh.label(seed_mask)

    # remove small regions
    sizes = mh.labeled.labeled_size(seeds)
    min_seed_size = 5
    too_small = np.where(sizes < min_seed_size)
    seeds = mh.labeled.remove_regions(seeds, too_small).astype(np.uint8)

    #
    # run watershed
    #
    ws = mh.cwatershed(brush_image.max() - brush_image, seeds)

    lines_array = np.zeros(ws.shape,dtype=np.uint8)
    lines = []

    for y in range(ws.shape[0]-1):
github luispedro / mahotas / mahotas / demos / nuclear_distance_watershed.py View on Github external
import mahotas as mh
from os import path
import numpy as np
from matplotlib import pyplot as plt

nuclear = mh.demos.load('nuclear')
nuclear = nuclear[:,:,0]
nuclear = mh.gaussian_filter(nuclear, 1.)
threshed  = (nuclear > nuclear.mean())
distances = mh.stretch(mh.distance(threshed))
Bc = np.ones((9,9))

maxima = mh.morph.regmax(distances, Bc=Bc)
spots,n_spots = mh.label(maxima, Bc=Bc)
surface = (distances.max() - distances)
areas = mh.cwatershed(surface, spots)
areas *= threshed



import random
from matplotlib import colors
from matplotlib import cm
cols = [cm.jet(c) for c in range(0, 256, 4)]
random.shuffle(cols)
cols[0] = (0.,0.,0.,1.)
rmap = colors.ListedColormap(cols)
plt.imshow(areas, cmap=rmap)
plt.show()
github zeiss-microscopy / OAD / Interfaces / COM_interface / Sourcecode_COM_Python / ReadAnalyzeImageData.py View on Github external
def CountObjects(img6d):

    obj = np.zeros(img6d.shape[0])

    print('Start Processing ...',)
    steps = img6d.shape[0]/10

    # count cells with individual thresholds per frame
    for i in range(0, img6d.shape[0], 1):

        img = img6d[i, 0, 0, 0, :, :]
        T = mahotas.otsu(img)
        img = (img > T)
        img = mahotas.gaussian_filter(img, 0.5)
        labeled, numobjects = mahotas.label(img)
        obj[i] = numobjects
        if i % steps == 0:
            print('\b.',)
            sys.stdout.flush()

    print('Done!',)

    return obj, labeled
github urakubo / UNI-EM / dojo / controller_.py View on Github external
#
    # Take offset of tile into account
    #
    offset_x = self.x_tiles[0]*512
    offset_y = self.y_tiles[0]*512

    s_tile = np.zeros(row_val.shape)
    s_tile[row_val == self.label_id] = 1

    # mh.imsave('../t_val.jpg', row_val.astype(np.uint8))

    for c in i_js:
      s_tile[c[1]-offset_y, c[0]-offset_x] = 0

    label_image,n = mh.label(s_tile)

    # check which label was selected
    selected_label = label_image[click[1]-offset_y, click[0]-offset_x]

    for c in i_js:
      label_image[c[1]-offset_y, c[0]-offset_x] = selected_label # the line belongs to the selected label

    # update the segmentation data

    self.__largest_id += 1
    new_id = self.__largest_id

    # unselected_label = selected_label==1 ? unselected_label=2 : unselected_label:1

    if selected_label == 1:
      unselected_label = 2
github Rhoana / dojo / _dojo / controller.py View on Github external
# x0 = brush_size/2
    # x1 = brush_boundary_mask.shape[0] - x0
    # y0 = x0
    # y1 = brush_boundary_mask.shape[1] - y0

    # brush_boundary_mask = brush_boundary_mask[x0:x1,y0:y1]
    # brush_image = brush_image[x0:x1,y0:y1]






    # seeds,n = mh.label(brush_boundary_mask)
    seeds,n = mh.label(seed_mask)

    print n

    # remove small regions
    sizes = mh.labeled.labeled_size(seeds)
    min_seed_size = 5
    too_small = np.where(sizes < min_seed_size)
    seeds = mh.labeled.remove_regions(seeds, too_small).astype(np.uint8)


    #
    # run watershed
    #
    ws = mh.cwatershed(brush_image.max() - brush_image, seeds)

    mh.imsave('/tmp/end_points.tif', 50*end_points.astype(np.uint8))