How to use the mahotas.morph.dilate 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 urakubo / UNI-EM / dojo / controller_.py View on Github external
frame[-1,:] = True
    frame[:,-1] = True

    # dilate non-brush segments
    outside_brush_mask = np.copy(~brush_mask)
    outside_brush_mask = mh.morph.dilate(outside_brush_mask, np.ones((brush_size, brush_size)))

    # compute end points of line
    end_points = np.zeros(brush_mask.shape,dtype=bool)
    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)
github urakubo / UNI-EM / dojo / controller.py View on Github external
# add linear interpolation to brush stroke
      dense_brush += zip(ys,xs)

    width = self.__dojoserver.get_image()._width
    height = self.__dojoserver.get_image()._height

    # add dense brush stroke to mask image
    brush_mask = np.zeros((height, width),dtype=bool)

    # for c in i_js:
    for c in dense_brush:
        brush_mask[c[1],c[0]] = True

    # crop
    brush_mask = brush_mask[bb[2]:bb[3],bb[0]:bb[1]]
    brush_mask = mh.morph.dilate(brush_mask, np.ones((2*brush_size, 2*brush_size)))

    brush_image = np.copy(sub_tile)
    brush_image[~brush_mask] = 0

    # compute frame
    frame = np.zeros(brush_mask.shape,dtype=bool)
    frame[0,:] = True
    frame[:,0] = True
    frame[-1,:] = True
    frame[:,-1] = True

    # dilate non-brush segments
    outside_brush_mask = np.copy(~brush_mask)
    outside_brush_mask = mh.morph.dilate(outside_brush_mask, np.ones((brush_size, brush_size)))

    # compute end points of line
github Rhoana / dojo / _dojo / scripts / splitexp.py View on Github external
sub_tile = tile[bbox[2]:bbox[3],bbox[0]:bbox[1]]
mh.imsave('/tmp/box10.tif', sub_tile)
#
# create mask
#
mask = np.zeros((1024,1024),dtype=np.uint8)

bs = input['brush_size']

i_js = input['i_js']

for d in i_js:
  mask[d[1], d[0]] = 255

for i in range(bs):
  mask = mh.morph.dilate(mask)

mask = np.invert(mask)

mask = mask[bbox[2]:bbox[3],bbox[0]:bbox[1]]

# mh.imsave('/tmp/mask.tif', mask)

grad_x = np.gradient(sub_tile)[0]
grad_y = np.gradient(sub_tile)[1]
grad = np.add(np.square(grad_x), np.square(grad_y))
#grad = np.add(np.abs(grad_x), np.abs(grad_y))
grad -= grad.min()
grad /= grad.max()
grad *= 255
grad = grad.astype(np.uint8)
github Rhoana / dojo / _dojo / controller.py View on Github external
# corners[0:n,-n:-1] = True
    # corners[0:n,-1] = True

    # # lower left
    # corners[-n:-1,0:n] = True
    # corners[-1,0:n] = True

    # # lower right
    # corners[-n:-1,-n:-1] = True
    # corners[-1,-n:-1] = True
    # corners[-n:-1,-1] = True
    # corners[-1,-1] = True

    # dilate non-brush segments
    outside_brush_mask = np.copy(~brush_mask)
    outside_brush_mask = mh.morph.dilate(outside_brush_mask, np.ones((brush_size, brush_size)))

    # # compute brush boundary

    # for y in range(outside_brush_mask.shape[0]-1):
    #   for x in range(outside_brush_mask.shape[1]-1):

    #     if brush_mask[y,x] != brush_mask[y,x+1]: #and seg_sub_tile[y,x] == label_id:  
    #       outside_brush_mask[y,x] = 1
    #       outside_brush_mask[y,x+1] = 1

    #     if brush_mask[y,x] != brush_mask[y+1,x]: #and seg_sub_tile[y,x] == label_id:
    #       outside_brush_mask[y,x] = 1
    #       outside_brush_mask[y+1,x] = 1

    # for y in range(1,outside_brush_mask.shape[0]):
    #   for x in range(1,outside_brush_mask.shape[1]):
github urakubo / UNI-EM / dojo / controller_.py View on Github external
brush_mask = brush_mask[bb[2]:bb[3],bb[0]:bb[1]]
    brush_mask = mh.morph.dilate(brush_mask, np.ones((2*brush_size, 2*brush_size)))

    brush_image = np.copy(sub_tile)
    brush_image[~brush_mask] = 0

    # compute frame
    frame = np.zeros(brush_mask.shape,dtype=bool)
    frame[0,:] = True
    frame[:,0] = True
    frame[-1,:] = True
    frame[:,-1] = True

    # dilate non-brush segments
    outside_brush_mask = np.copy(~brush_mask)
    outside_brush_mask = mh.morph.dilate(outside_brush_mask, np.ones((brush_size, brush_size)))

    # compute end points of line
    end_points = np.zeros(brush_mask.shape,dtype=bool)
    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
github Rhoana / dojo / _dojo / controller.py View on Github external
# add linear interpolation to brush stroke
      dense_brush += zip(ys,xs)

      # dense_brush = list(set(dense_brush))

    # add dense brush stroke to mask image
    brush_mask = np.zeros((1024,1024),dtype=bool)

#    for c in i_js:
    for c in dense_brush:
        brush_mask[c[1],c[0]] = True
        
    # crop
    brush_mask = brush_mask[bbox[2]:bbox[3],bbox[0]:bbox[1]]
    brush_mask = mh.morph.dilate(brush_mask, np.ones((2*brush_size, 2*brush_size)))

    brush_image = np.copy(sub_tile)
    brush_image[~brush_mask] = 0



    # compute frame
    frame = np.zeros(brush_mask.shape,dtype=bool)
    frame[0,:] = True
    frame[:,0] = True
    frame[-1,:] = True
    frame[:,-1] = True

    # # compute corners 
    # corners = np.zeros(brush_mask.shape,dtype=bool)
github urakubo / UNI-EM / dojo / controller.py View on Github external
frame[-1,:] = True
    frame[:,-1] = True

    # dilate non-brush segments
    outside_brush_mask = np.copy(~brush_mask)
    outside_brush_mask = mh.morph.dilate(outside_brush_mask, np.ones((brush_size, brush_size)))

    # compute end points of line
    end_points = np.zeros(brush_mask.shape,dtype=bool)
    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)