Commit ae401042405ecc87da5069458e1ce1243827c86a

Authored by Paulo Henrique Junqueira Amorim
1 parent f1d4f62b

ADD: adding of the code window and level for the 2D

Showing 1 changed file with 21 additions and 3 deletions   Show diff stats
invesalius/data/slice_.py
@@ -53,6 +53,9 @@ class Slice(object): @@ -53,6 +53,9 @@ class Slice(object):
53 ps.Publisher().subscribe(self.__set_current_mask_threshold_limits, 53 ps.Publisher().subscribe(self.__set_current_mask_threshold_limits,
54 'Update threshold limits') 54 'Update threshold limits')
55 55
  56 + ps.Publisher().subscribe(self.UpdateWindowLevelBackground,\
  57 + 'Bright and contrast adjustment image')
  58 +
56 def __set_current_mask_threshold_limits(self, pubsub_evt): 59 def __set_current_mask_threshold_limits(self, pubsub_evt):
57 thresh_min = pubsub_evt.data[0] 60 thresh_min = pubsub_evt.data[0]
58 thresh_max = pubsub_evt.data[1] 61 thresh_max = pubsub_evt.data[1]
@@ -62,7 +65,7 @@ class Slice(object): @@ -62,7 +65,7 @@ class Slice(object):
62 if self.current_mask: 65 if self.current_mask:
63 index = self.current_mask.index 66 index = self.current_mask.index
64 self.SetMaskEditionThreshold(index, (thresh_min, thresh_max)) 67 self.SetMaskEditionThreshold(index, (thresh_min, thresh_max))
65 - 68 +
66 69
67 70
68 #--------------------------------------------------------------------------- 71 #---------------------------------------------------------------------------
@@ -338,6 +341,7 @@ class Slice(object): @@ -338,6 +341,7 @@ class Slice(object):
338 cross.Modified() 341 cross.Modified()
339 self.cross = cross 342 self.cross = cross
340 343
  344 + self.window_level = vtk.vtkImageMapToWindowLevelColors()
341 #cast = vtk.vtkImageCast() 345 #cast = vtk.vtkImageCast()
342 #cast.SetInput(cross.GetOutput()) 346 #cast.SetInput(cross.GetOutput())
343 #cast.GetOutput().SetUpdateExtentToWholeExtent() 347 #cast.GetOutput().SetUpdateExtentToWholeExtent()
@@ -368,13 +372,14 @@ class Slice(object): @@ -368,13 +372,14 @@ class Slice(object):
368 372
369 373
370 def __create_background(self, imagedata): 374 def __create_background(self, imagedata):
  375 + self.imagedata = imagedata
371 376
372 thresh_min, thresh_max = imagedata.GetScalarRange() 377 thresh_min, thresh_max = imagedata.GetScalarRange()
373 ps.Publisher().sendMessage('Update threshold limits list', (thresh_min, 378 ps.Publisher().sendMessage('Update threshold limits list', (thresh_min,
374 thresh_max)) 379 thresh_max))
375 380
376 # map scalar values into colors 381 # map scalar values into colors
377 - lut_bg = vtk.vtkLookupTable() 382 + lut_bg = self.lut_bg = vtk.vtkLookupTable()
378 lut_bg.SetTableRange(thresh_min, thresh_max) 383 lut_bg.SetTableRange(thresh_min, thresh_max)
379 lut_bg.SetSaturationRange(0, 0) 384 lut_bg.SetSaturationRange(0, 0)
380 lut_bg.SetHueRange(0, 0) 385 lut_bg.SetHueRange(0, 0)
@@ -382,13 +387,26 @@ class Slice(object): @@ -382,13 +387,26 @@ class Slice(object):
382 lut_bg.Build() 387 lut_bg.Build()
383 388
384 # map the input image through a lookup table 389 # map the input image through a lookup table
385 - img_colours_bg = vtk.vtkImageMapToColors() 390 + img_colours_bg = self.img_colours_bg = vtk.vtkImageMapToColors()
386 img_colours_bg.SetOutputFormatToRGBA() 391 img_colours_bg.SetOutputFormatToRGBA()
387 img_colours_bg.SetLookupTable(lut_bg) 392 img_colours_bg.SetLookupTable(lut_bg)
388 img_colours_bg.SetInput(imagedata) 393 img_colours_bg.SetInput(imagedata)
389 394
390 return img_colours_bg.GetOutput() 395 return img_colours_bg.GetOutput()
391 396
  397 + def UpdateWindowLevelBackground(self, pubsub_evt):
  398 + window, level = pubsub_evt.data
  399 + window_level = self.window_level
  400 + window_level.SetInput(self.imagedata)
  401 + window_level.SetWindow(window)
  402 + window_level.SetLevel(level)
  403 + window_level.SetOutputFormatToLuminance()
  404 + window_level.Update()
  405 +
  406 + thresh_min, thresh_max = window_level.GetOutput().GetScalarRange()
  407 + self.lut_bg.SetTableRange(thresh_min, thresh_max)
  408 + self.img_colours_bg.SetInput(window_level.GetOutput())
  409 +
392 def CreateMask(self, imagedata=None, name=None): 410 def CreateMask(self, imagedata=None, name=None):
393 411
394 future_mask = Mask() 412 future_mask = Mask()