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 367 print ">Not used the IPPSorter"
368 368 filelist = [i.image.file for i in dicom_group.GetHandSortedList()]
369 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 375 # 1(a): Fix gantry tilt, if any
373 376 tilt_value = dicom.acquisition.tilt
... ...
invesalius/data/imagedata_utils.py
... ... @@ -24,7 +24,7 @@ import wx.lib.pubsub as ps
24 24  
25 25 import constants as const
26 26 from data import vtk_utils
27   -
  27 +import utils
28 28  
29 29 # TODO: Test cases which are originally in sagittal/coronal orientation
30 30 # and have gantry
... ... @@ -217,7 +217,7 @@ def ExtractVOI(imagedata,xi,xf,yi,yf,zi,zf):
217 217 voi.Update()
218 218 return voi.GetOutput()
219 219  
220   -def CreateImageData(filelist, zspacing):
  220 +def CreateImageData(filelist, zspacing, size, bits):
221 221 message = "Generating multiplanar visualization..."
222 222  
223 223 if not const.VTK_WARNING:
... ... @@ -245,12 +245,16 @@ def CreateImageData(filelist, zspacing):
245 245 spacing = imagedata.GetSpacing()
246 246 imagedata.SetSpacing(spacing[0], spacing[1], zspacing)
247 247 else:
  248 +
248 249 update_progress= vtk_utils.ShowProgress(2*len(filelist),
249 250 dialog_type = "ProgressDialog")
250 251  
251 252 # Reformat each slice and future append them
252 253 appender = vtk.vtkImageAppend()
253 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 259 # Reformat each slice
256 260 for x in xrange(len(filelist)):
... ... @@ -262,10 +266,9 @@ def CreateImageData(filelist, zspacing):
262 266 reader.AddObserver("ProgressEvent", lambda obj,evt:
263 267 update_progress(reader,message))
264 268 reader.Update()
265   -
  269 +
266 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 272 #Stack images in Z axes
270 273 appender.AddInput(slice_imagedata)
271 274 #appender.AddObserver("ProgressEvent", lambda obj,evt:update_progress(appender))
... ... @@ -285,6 +288,7 @@ def CreateImageData(filelist, zspacing):
285 288 return imagedata
286 289  
287 290  
  291 +"""
288 292 class ImageCreator:
289 293 def __init__(self):
290 294 ps.Publisher().sendMessage("Cancel imagedata load", self.CancelImageDataLoad)
... ... @@ -332,6 +336,7 @@ class ImageCreator:
332 336 reader.Update()
333 337  
334 338 #Resample image in x,y dimension
  339 +
335 340 slice_imagedata = ResampleImage2D(reader.GetOutput(), 256, update_progress)
336 341  
337 342 #Stack images in Z axes
... ... @@ -351,5 +356,5 @@ class ImageCreator:
351 356 imagedata.Update()
352 357  
353 358 return imagedata
354   -
  359 +"""
355 360  
... ...
invesalius/reader/dicom.py
... ... @@ -1854,6 +1854,7 @@ class Image(object):
1854 1854 self.type = parser.GetImageType()
1855 1855 self.size = (parser.GetDimensionX(), parser.GetDimensionY())
1856 1856 self.imagedata = parser.GetImageData()
  1857 + self.bits_allocad = parser._GetBitsAllocated()
1857 1858  
1858 1859 if (parser.GetImageThickness()):
1859 1860 try:
... ...
invesalius/reader/dicom_reader.py
... ... @@ -37,7 +37,10 @@ def ReadDicomGroup(dir_):
37 37 if len(patient_group) > 0:
38 38 filelist, dicom, zspacing = SelectLargerDicomGroup(patient_group)
39 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 44 session.Session().project_status = const.NEW_PROJECT
42 45 return imagedata, dicom
43 46 else:
... ...
invesalius/utils.py
... ... @@ -82,3 +82,30 @@ def frange(start, end=None, inc=None):
82 82 L.append(next)
83 83  
84 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 +
... ...