Commit 0472084d41b97b131211bd725a65cd3df8818e1d

Authored by Thiago Franco de Moraes
1 parent b1a7a665
Exists in smoothing_bin_pll

User can use the whitaker smoothing

invesalius/data/surface.py
... ... @@ -24,6 +24,7 @@ import random
24 24 import tempfile
25 25 import weakref
26 26  
  27 +import numpy as np
27 28 import vtk
28 29 import wx
29 30 from wx.lib.pubsub import pub as Publisher
... ... @@ -37,6 +38,8 @@ import surface_process
37 38 import utils as utl
38 39 import vtk_utils as vu
39 40  
  41 +from data import smooth_cy
  42 +
40 43 try:
41 44 import ca_smoothing
42 45 except ImportError:
... ... @@ -465,13 +468,27 @@ class SurfaceManager():
465 468 q_in = multiprocessing.Queue()
466 469 q_out = multiprocessing.Queue()
467 470  
  471 + if algorithm == 'Whitaker':
  472 + iteractions = 10
  473 + bsize = 4
  474 + mask_tfile = tempfile.mktemp()
  475 + mmask = np.memmap(mask_tfile, shape=mask.matrix.shape, dtype='float64', mode='w+')
  476 + smooth_cy.smooth(mask.matrix, iteractions, bsize, mmask)
  477 + mmask[0, :, :] = -1
  478 + mmask[:, 0, :] = -1
  479 + mmask[:, :, 0] = -1
  480 +
  481 + else:
  482 + mask_tfile = mask.temp_file
  483 + mmask = mask.matrix
  484 +
468 485 p = []
469 486 for i in xrange(n_processors):
470 487 sp = surface_process.SurfaceProcess(pipe_in, filename_img,
471 488 matrix.shape, matrix.dtype,
472   - mask.temp_file,
473   - mask.matrix.shape,
474   - mask.matrix.dtype,
  489 + mask_tfile,
  490 + mmask.shape,
  491 + mmask.dtype,
475 492 spacing,
476 493 mode, min_value, max_value,
477 494 decimate_reduction,
... ...
invesalius/data/surface_process.py
... ... @@ -151,7 +151,10 @@ class SurfaceProcess(multiprocessing.Process):
151 151 contour.SetInputData(image)
152 152 #contour.SetInput(flip.GetOutput())
153 153 if self.from_binary:
154   - contour.SetValue(0, 127) # initial threshold
  154 + if self.algorithm == 'Whitaker':
  155 + contour.SetValue(0, 0.0) # initial threshold
  156 + else:
  157 + contour.SetValue(0, 127) # initial threshold
155 158 else:
156 159 contour.SetValue(0, self.min_value) # initial threshold
157 160 contour.SetValue(1, self.max_value) # final threshold
... ...
invesalius/gui/dialogs.py
... ... @@ -1307,7 +1307,8 @@ class SurfaceMethodPanel(wx.Panel):
1307 1307 self.mask_edited = mask_edited
1308 1308 self.alg_types = {_(u'Default'): 'Default',
1309 1309 _(u'Context aware smoothing'): 'ca_smoothing',
1310   - _(u'Binary'): 'Binary'}
  1310 + _(u'Binary'): 'Binary',
  1311 + _(u'Reducing Aliasing'): 'Whitaker'}
1311 1312 self.edited_imp = [_(u'Default'), ]
1312 1313  
1313 1314 self._build_widgets()
... ...