Commit b8a2a2a83ef43b8dd1ad9026f5f3d2f5d78d03fa
1 parent
8a446404
Exists in
smoothing_bin
User can use the whitaker smoothing
Showing
3 changed files
with
26 additions
and
5 deletions
Show diff stats
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
| ... | ... | @@ -1255,7 +1255,8 @@ class SurfaceMethodPanel(wx.Panel): |
| 1255 | 1255 | self.mask_edited = mask_edited |
| 1256 | 1256 | self.alg_types = {_(u'Default'): 'Default', |
| 1257 | 1257 | _(u'Context aware smoothing'): 'ca_smoothing', |
| 1258 | - _(u'Binary'): 'Binary'} | |
| 1258 | + _(u'Binary'): 'Binary', | |
| 1259 | + _(u'Reducing Aliasing'): 'Whitaker'} | |
| 1259 | 1260 | self.edited_imp = [_(u'Default'), ] |
| 1260 | 1261 | |
| 1261 | 1262 | self._build_widgets() | ... | ... |