Commit 09be8cfc33996b78173a9872fc769bda60124941

Authored by Paulo Henrique Junqueira Amorim
1 parent 77061d50

ADD: Reduce Matrix the of Image before import

Showing 1 changed file with 44 additions and 7 deletions   Show diff stats
invesalius/reader/dicom_reader.py
... ... @@ -25,6 +25,7 @@ import gdcm
25 25  
26 26 import dicom
27 27 import dicom_grouper
  28 +from data.imagedata_utils import ResampleMatrix
28 29  
29 30 def LoadImages(dir_):
30 31 # TODO!!! SUPER GAMBIARRA!!! DO THIS BETTER
... ... @@ -82,16 +83,52 @@ def LoadImages(dir_):
82 83  
83 84 array = vtk.vtkStringArray()
84 85  
85   - for x in xrange(len(files)):
86   - array.InsertValue(x,files[x])
  86 + #Case Reduce Matrix of the Image
  87 + flag = 1
  88 + reduce_factor = 4
  89 +
  90 + img_app = vtk.vtkImageAppend()
  91 + img_app.SetAppendAxis(2) #Define Stack in Z
87 92  
88   - read = vtkgdcm.vtkGDCMImageReader()
89   - read.SetFileNames(array)
90   - read.Update()
  93 + for x in xrange(len(files)):
  94 + if not(flag):
  95 + array.InsertValue(x,files[x])
  96 + else:
  97 + #SIf the resolution of the
  98 + #matrix is very large
  99 + read = vtkgdcm.vtkGDCMImageReader()
  100 + read.SetFileName(files[x])
  101 + read.Update()
  102 +
  103 + #Stack images in Z axes
  104 + img = ResampleMatrix(read.GetOutput(), reduce_factor)
  105 + img_app.AddInput(img)
91 106  
92 107 img_axial = vtk.vtkImageData()
93   - img_axial.DeepCopy(read.GetOutput())
94   - img_axial.SetSpacing(spacing, spacing, spacing_z)
  108 +
  109 + if (flag):
  110 + img_app.Update()
  111 + img_axial.DeepCopy(img_app.GetOutput())
  112 +
  113 + #TODO: Code challenge (imagedata_utils.ResampleMatrix),
  114 + #it is necessary to know the new spacing.
  115 + #spacing = read.GetOutput().GetSpacing()
  116 + extent = read.GetOutput().GetExtent()
  117 + size = read.GetOutput().GetDimensions()
  118 + height = float(size[1]/reduce_factor)
  119 + resolution = (height/(extent[1]-extent[0])+1)*spacing
  120 + print "\n"
  121 + print spacing
  122 + print spacing_z*resolution
  123 + img_axial.SetSpacing(spacing, spacing, spacing_z * resolution)
  124 + else:
  125 + read = vtkgdcm.vtkGDCMImageReader()
  126 + read.SetFileNames(array)
  127 + read.Update()
  128 +
  129 + img_axial.DeepCopy(read.GetOutput())
  130 + img_axial.SetSpacing(spacing, spacing, spacing_z)
  131 +
95 132 img_axial.Update()
96 133  
97 134 return img_axial, acquisition_modality, tilt
... ...