Commit 02265d5231b405117cbe04080582c1dad60026c4

Authored by Paulo Henrique Junqueira Amorim
1 parent 358c45fb

ENH: Fixed problems in the Windows version (watershed).

Showing 1 changed file with 43 additions and 0 deletions   Show diff stats
invesalius/data/watershed_process.py 0 → 100644
... ... @@ -0,0 +1,43 @@
  1 +import numpy as np
  2 +from scipy import ndimage
  3 +from scipy.ndimage import watershed_ift, generate_binary_structure
  4 +from skimage.morphology import watershed
  5 +from skimage import filter
  6 +
  7 +
  8 +def get_LUT_value(data, window, level):
  9 + return np.piecewise(data,
  10 + [data <= (level - 0.5 - (window-1)/2),
  11 + data > (level - 0.5 + (window-1)/2)],
  12 + [0, 255, lambda data: ((data - (level - 0.5))/(window-1) + 0.5)*(255-0)])
  13 +
  14 +
  15 +
  16 +def do_watershed(image, markers, tfile, shape, bstruct, algorithm, mg_size, use_ww_wl, wl, ww, q):
  17 + mask = np.memmap(tfile, shape=shape, dtype='uint8', mode='r+')
  18 +
  19 + if use_ww_wl:
  20 + if algorithm == 'Watershed':
  21 + tmp_image = ndimage.morphological_gradient(
  22 + get_LUT_value(image, ww, wl).astype('uint16'),
  23 + mg_size)
  24 + tmp_mask = watershed(tmp_image, markers.astype('int16'), bstruct)
  25 + else:
  26 + tmp_image = get_LUT_value(image, ww, wl).astype('uint16')
  27 + #tmp_image = ndimage.gaussian_filter(tmp_image, self.config.mg_size)
  28 + #tmp_image = ndimage.morphological_gradient(
  29 + #get_LUT_value(image, ww, wl).astype('uint16'),
  30 + #self.config.mg_size)
  31 + tmp_mask = watershed_ift(tmp_image, markers.astype('int16'), bstruct)
  32 + else:
  33 + if algorithm == 'Watershed':
  34 + tmp_image = ndimage.morphological_gradient((image - image.min()).astype('uint16'), mg_size)
  35 + tmp_mask = watershed(tmp_image, markers.astype('int16'), bstruct)
  36 + else:
  37 + tmp_image = (image - image.min()).astype('uint16')
  38 + #tmp_image = ndimage.gaussian_filter(tmp_image, self.config.mg_size)
  39 + #tmp_image = ndimage.morphological_gradient((image - image.min()).astype('uint16'), self.config.mg_size)
  40 + tmp_mask = watershed_ift(tmp_image, markers.astype('int8'), bstruct)
  41 + mask[:] = tmp_mask
  42 + mask.flush()
  43 + q.put(1)
... ...