Commit ae401042405ecc87da5069458e1ce1243827c86a
1 parent
f1d4f62b
Exists in
master
and in
68 other branches
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 | 53 | ps.Publisher().subscribe(self.__set_current_mask_threshold_limits, |
| 54 | 54 | 'Update threshold limits') |
| 55 | 55 | |
| 56 | + ps.Publisher().subscribe(self.UpdateWindowLevelBackground,\ | |
| 57 | + 'Bright and contrast adjustment image') | |
| 58 | + | |
| 56 | 59 | def __set_current_mask_threshold_limits(self, pubsub_evt): |
| 57 | 60 | thresh_min = pubsub_evt.data[0] |
| 58 | 61 | thresh_max = pubsub_evt.data[1] |
| ... | ... | @@ -62,7 +65,7 @@ class Slice(object): |
| 62 | 65 | if self.current_mask: |
| 63 | 66 | index = self.current_mask.index |
| 64 | 67 | self.SetMaskEditionThreshold(index, (thresh_min, thresh_max)) |
| 65 | - | |
| 68 | + | |
| 66 | 69 | |
| 67 | 70 | |
| 68 | 71 | #--------------------------------------------------------------------------- |
| ... | ... | @@ -338,6 +341,7 @@ class Slice(object): |
| 338 | 341 | cross.Modified() |
| 339 | 342 | self.cross = cross |
| 340 | 343 | |
| 344 | + self.window_level = vtk.vtkImageMapToWindowLevelColors() | |
| 341 | 345 | #cast = vtk.vtkImageCast() |
| 342 | 346 | #cast.SetInput(cross.GetOutput()) |
| 343 | 347 | #cast.GetOutput().SetUpdateExtentToWholeExtent() |
| ... | ... | @@ -368,13 +372,14 @@ class Slice(object): |
| 368 | 372 | |
| 369 | 373 | |
| 370 | 374 | def __create_background(self, imagedata): |
| 375 | + self.imagedata = imagedata | |
| 371 | 376 | |
| 372 | 377 | thresh_min, thresh_max = imagedata.GetScalarRange() |
| 373 | 378 | ps.Publisher().sendMessage('Update threshold limits list', (thresh_min, |
| 374 | 379 | thresh_max)) |
| 375 | 380 | |
| 376 | 381 | # map scalar values into colors |
| 377 | - lut_bg = vtk.vtkLookupTable() | |
| 382 | + lut_bg = self.lut_bg = vtk.vtkLookupTable() | |
| 378 | 383 | lut_bg.SetTableRange(thresh_min, thresh_max) |
| 379 | 384 | lut_bg.SetSaturationRange(0, 0) |
| 380 | 385 | lut_bg.SetHueRange(0, 0) |
| ... | ... | @@ -382,13 +387,26 @@ class Slice(object): |
| 382 | 387 | lut_bg.Build() |
| 383 | 388 | |
| 384 | 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 | 391 | img_colours_bg.SetOutputFormatToRGBA() |
| 387 | 392 | img_colours_bg.SetLookupTable(lut_bg) |
| 388 | 393 | img_colours_bg.SetInput(imagedata) |
| 389 | 394 | |
| 390 | 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 | 410 | def CreateMask(self, imagedata=None, name=None): |
| 393 | 411 | |
| 394 | 412 | future_mask = Mask() | ... | ... |