Commit 85caf5c624b13202222f4e7f7590b937844b0970

Authored by Paulo Henrique Junqueira Amorim
1 parent a06516c0

ENH: Rule for reducing imagedata quality under win32 FIX #76

invesalius/control.py
@@ -367,7 +367,10 @@ class Controller(): @@ -367,7 +367,10 @@ class Controller():
367 print ">Not used the IPPSorter" 367 print ">Not used the IPPSorter"
368 filelist = [i.image.file for i in dicom_group.GetHandSortedList()] 368 filelist = [i.image.file for i in dicom_group.GetHandSortedList()]
369 zspacing = dicom_group.zspacing 369 zspacing = dicom_group.zspacing
370 - imagedata = utils.CreateImageData(filelist, zspacing) 370 + size = dicom.image.size
  371 + bits = dicom.image.bits_allocad
  372 +
  373 + imagedata = utils.CreateImageData(filelist, zspacing, size, bits)
371 374
372 # 1(a): Fix gantry tilt, if any 375 # 1(a): Fix gantry tilt, if any
373 tilt_value = dicom.acquisition.tilt 376 tilt_value = dicom.acquisition.tilt
invesalius/data/imagedata_utils.py
@@ -24,7 +24,7 @@ import wx.lib.pubsub as ps @@ -24,7 +24,7 @@ import wx.lib.pubsub as ps
24 24
25 import constants as const 25 import constants as const
26 from data import vtk_utils 26 from data import vtk_utils
27 - 27 +import utils
28 28
29 # TODO: Test cases which are originally in sagittal/coronal orientation 29 # TODO: Test cases which are originally in sagittal/coronal orientation
30 # and have gantry 30 # and have gantry
@@ -217,7 +217,7 @@ def ExtractVOI(imagedata,xi,xf,yi,yf,zi,zf): @@ -217,7 +217,7 @@ def ExtractVOI(imagedata,xi,xf,yi,yf,zi,zf):
217 voi.Update() 217 voi.Update()
218 return voi.GetOutput() 218 return voi.GetOutput()
219 219
220 -def CreateImageData(filelist, zspacing): 220 +def CreateImageData(filelist, zspacing, size, bits):
221 message = "Generating multiplanar visualization..." 221 message = "Generating multiplanar visualization..."
222 222
223 if not const.VTK_WARNING: 223 if not const.VTK_WARNING:
@@ -245,12 +245,16 @@ def CreateImageData(filelist, zspacing): @@ -245,12 +245,16 @@ def CreateImageData(filelist, zspacing):
245 spacing = imagedata.GetSpacing() 245 spacing = imagedata.GetSpacing()
246 imagedata.SetSpacing(spacing[0], spacing[1], zspacing) 246 imagedata.SetSpacing(spacing[0], spacing[1], zspacing)
247 else: 247 else:
  248 +
248 update_progress= vtk_utils.ShowProgress(2*len(filelist), 249 update_progress= vtk_utils.ShowProgress(2*len(filelist),
249 dialog_type = "ProgressDialog") 250 dialog_type = "ProgressDialog")
250 251
251 # Reformat each slice and future append them 252 # Reformat each slice and future append them
252 appender = vtk.vtkImageAppend() 253 appender = vtk.vtkImageAppend()
253 appender.SetAppendAxis(2) #Define Stack in Z 254 appender.SetAppendAxis(2) #Define Stack in Z
  255 +
  256 + x,y = size
  257 + p = utils.PredictingMemory(len(filelist), x, y, bits)
254 258
255 # Reformat each slice 259 # Reformat each slice
256 for x in xrange(len(filelist)): 260 for x in xrange(len(filelist)):
@@ -262,10 +266,9 @@ def CreateImageData(filelist, zspacing): @@ -262,10 +266,9 @@ def CreateImageData(filelist, zspacing):
262 reader.AddObserver("ProgressEvent", lambda obj,evt: 266 reader.AddObserver("ProgressEvent", lambda obj,evt:
263 update_progress(reader,message)) 267 update_progress(reader,message))
264 reader.Update() 268 reader.Update()
265 - 269 +
266 #Resample image in x,y dimension 270 #Resample image in x,y dimension
267 - slice_imagedata = ResampleImage2D(reader.GetOutput(), 256, update_progress)  
268 - 271 + slice_imagedata = ResampleImage2D(reader.GetOutput(), p, update_progress)
269 #Stack images in Z axes 272 #Stack images in Z axes
270 appender.AddInput(slice_imagedata) 273 appender.AddInput(slice_imagedata)
271 #appender.AddObserver("ProgressEvent", lambda obj,evt:update_progress(appender)) 274 #appender.AddObserver("ProgressEvent", lambda obj,evt:update_progress(appender))
@@ -285,6 +288,7 @@ def CreateImageData(filelist, zspacing): @@ -285,6 +288,7 @@ def CreateImageData(filelist, zspacing):
285 return imagedata 288 return imagedata
286 289
287 290
  291 +"""
288 class ImageCreator: 292 class ImageCreator:
289 def __init__(self): 293 def __init__(self):
290 ps.Publisher().sendMessage("Cancel imagedata load", self.CancelImageDataLoad) 294 ps.Publisher().sendMessage("Cancel imagedata load", self.CancelImageDataLoad)
@@ -332,6 +336,7 @@ class ImageCreator: @@ -332,6 +336,7 @@ class ImageCreator:
332 reader.Update() 336 reader.Update()
333 337
334 #Resample image in x,y dimension 338 #Resample image in x,y dimension
  339 +
335 slice_imagedata = ResampleImage2D(reader.GetOutput(), 256, update_progress) 340 slice_imagedata = ResampleImage2D(reader.GetOutput(), 256, update_progress)
336 341
337 #Stack images in Z axes 342 #Stack images in Z axes
@@ -351,5 +356,5 @@ class ImageCreator: @@ -351,5 +356,5 @@ class ImageCreator:
351 imagedata.Update() 356 imagedata.Update()
352 357
353 return imagedata 358 return imagedata
354 - 359 +"""
355 360
invesalius/reader/dicom.py
@@ -1854,6 +1854,7 @@ class Image(object): @@ -1854,6 +1854,7 @@ class Image(object):
1854 self.type = parser.GetImageType() 1854 self.type = parser.GetImageType()
1855 self.size = (parser.GetDimensionX(), parser.GetDimensionY()) 1855 self.size = (parser.GetDimensionX(), parser.GetDimensionY())
1856 self.imagedata = parser.GetImageData() 1856 self.imagedata = parser.GetImageData()
  1857 + self.bits_allocad = parser._GetBitsAllocated()
1857 1858
1858 if (parser.GetImageThickness()): 1859 if (parser.GetImageThickness()):
1859 try: 1860 try:
invesalius/reader/dicom_reader.py
@@ -37,7 +37,10 @@ def ReadDicomGroup(dir_): @@ -37,7 +37,10 @@ def ReadDicomGroup(dir_):
37 if len(patient_group) > 0: 37 if len(patient_group) > 0:
38 filelist, dicom, zspacing = SelectLargerDicomGroup(patient_group) 38 filelist, dicom, zspacing = SelectLargerDicomGroup(patient_group)
39 filelist = SortFiles(filelist, dicom) 39 filelist = SortFiles(filelist, dicom)
40 - imagedata = CreateImageData(filelist, zspacing) 40 + size = dicom.image.size
  41 + bits = dicom.image.bits_allocad
  42 +
  43 + imagedata = CreateImageData(filelist, zspacing, size, bits)
41 session.Session().project_status = const.NEW_PROJECT 44 session.Session().project_status = const.NEW_PROJECT
42 return imagedata, dicom 45 return imagedata, dicom
43 else: 46 else:
invesalius/utils.py
@@ -82,3 +82,30 @@ def frange(start, end=None, inc=None): @@ -82,3 +82,30 @@ def frange(start, end=None, inc=None):
82 L.append(next) 82 L.append(next)
83 83
84 return L 84 return L
  85 +
  86 +def PredictingMemory(qtd, x, y, p):
  87 + m = qtd * (x * y * p)
  88 +
  89 + #314859200 = 350 MB
  90 + #house 25 MB increases the
  91 + #factor 0.4
  92 + if (m >= 314859200):
  93 + porcent = 1.5 + (m - 314859200) / 26999999 * 0.04
  94 + x = x/porcent
  95 + y = y/porcent
  96 + return x
  97 + else:
  98 + return x
  99 +
  100 + return x
  101 +
  102 +def BytesConvert(bytes):
  103 + if bytes >= 1073741824:
  104 + return str(bytes / 1024 / 1024 / 1024) + ' GB'
  105 + elif bytes >= 1048576:
  106 + return str(bytes / 1024 / 1024) + ' MB'
  107 + elif bytes >= 1024:
  108 + return str(bytes / 1024) + ' KB'
  109 + elif bytes < 1024:
  110 + return str(bytes) + ' bytes'
  111 +