Commit 0ea23c28d333b28d587bf2a553de953f69e690c6

Authored by Thiago Franco de Moraes
1 parent 0c04cf8c
Exists in master

Moved pad_image to surface_process

invesalius/data/imagedata_utils.py
... ... @@ -751,22 +751,3 @@ def imgnormalize(data, srange=(0, 255)):
751 751 datan = datan.astype(numpy.int16)
752 752  
753 753 return datan
754   -
755   -
756   -def pad_image(image, pad_value, pad_bottom, pad_top):
757   - dz, dy, dx = image.shape
758   - z_iadd = 0
759   - z_eadd = 0
760   - if pad_bottom:
761   - z_iadd = 1
762   - dz += 1
763   - if pad_top:
764   - z_eadd = 1
765   - dz += 1
766   - new_shape = dz, dy + 2, dx + 2
767   -
768   - paded_image = numpy.empty(shape=new_shape, dtype=image.dtype)
769   - paded_image[:] = pad_value
770   - paded_image[z_iadd: z_iadd + image.shape[0], 1:-1, 1:-1] = image
771   -
772   - return paded_image
... ...
invesalius/data/surface_process.py
... ... @@ -14,7 +14,6 @@ import vtk
14 14 import invesalius.i18n as i18n
15 15 import invesalius.data.converters as converters
16 16 from invesalius.data import cy_mesh
17   -import invesalius.data.imagedata_utils as iu
18 17  
19 18 import weakref
20 19 from scipy import ndimage
... ... @@ -41,6 +40,25 @@ def ResampleImage3D(imagedata, value):
41 40 return resample.GetOutput()
42 41  
43 42  
  43 +def pad_image(image, pad_value, pad_bottom, pad_top):
  44 + dz, dy, dx = image.shape
  45 + z_iadd = 0
  46 + z_eadd = 0
  47 + if pad_bottom:
  48 + z_iadd = 1
  49 + dz += 1
  50 + if pad_top:
  51 + z_eadd = 1
  52 + dz += 1
  53 + new_shape = dz, dy + 2, dx + 2
  54 +
  55 + paded_image = numpy.empty(shape=new_shape, dtype=image.dtype)
  56 + paded_image[:] = pad_value
  57 + paded_image[z_iadd: z_iadd + image.shape[0], 1:-1, 1:-1] = image
  58 +
  59 + return paded_image
  60 +
  61 +
44 62 def create_surface_piece(filename, shape, dtype, mask_filename, mask_shape,
45 63 mask_dtype, roi, spacing, mode, min_value, max_value,
46 64 decimate_reduction, smooth_relaxation_factor,
... ... @@ -60,7 +78,7 @@ def create_surface_piece(filename, shape, dtype, mask_filename, mask_shape,
60 78 dtype=mask_dtype,
61 79 shape=mask_shape)
62 80 if fill_border_holes:
63   - a_mask = iu.pad_image(mask[roi.start + 1: roi.stop + 1, 1:, 1:], 0, pad_bottom, pad_top)
  81 + a_mask = pad_image(mask[roi.start + 1: roi.stop + 1, 1:, 1:], 0, pad_bottom, pad_top)
64 82 else:
65 83 a_mask = numpy.array(mask[roi.start + 1: roi.stop + 1, 1:, 1:])
66 84 image = converters.to_vtk(a_mask, spacing, roi.start, "AXIAL", padding=padding)
... ... @@ -72,7 +90,7 @@ def create_surface_piece(filename, shape, dtype, mask_filename, mask_shape,
72 90 dtype=mask_dtype,
73 91 shape=mask_shape)
74 92 if fill_border_holes:
75   - a_image = iu.pad_image(image[roi], numpy.iinfo(image.dtype).min, pad_bottom, pad_top)
  93 + a_image = pad_image(image[roi], numpy.iinfo(image.dtype).min, pad_bottom, pad_top)
76 94 else:
77 95 a_image = numpy.array(image[roi])
78 96 # if z_iadd:
... ...