Commit 592ad4b80855569eec864d105c6521aed5704526
1 parent
bc0c7923
Exists in
master
and in
67 other branches
Pseudo colours are working again
Showing
1 changed file
with
34 additions
and
13 deletions
Show diff stats
invesalius/data/slice_.py
... | ... | @@ -75,6 +75,11 @@ class Slice(object): |
75 | 75 | self.blend_filter = None |
76 | 76 | self.matrix = None |
77 | 77 | |
78 | + self.number_of_colours = 256 | |
79 | + self.saturation_range = (0, 0) | |
80 | + self.hue_range = (0, 0) | |
81 | + self.value_range = (0, 1) | |
82 | + | |
78 | 83 | self.buffer_slices = {"AXIAL": SliceBuffer(), |
79 | 84 | "CORONAL": SliceBuffer(), |
80 | 85 | "SAGITAL": SliceBuffer()} |
... | ... | @@ -354,7 +359,8 @@ class Slice(object): |
354 | 359 | else: |
355 | 360 | n_image = self.get_image_slice(orientation, slice_number) |
356 | 361 | image = iu.to_vtk(n_image, self.spacing, slice_number, orientation) |
357 | - image = self.do_ww_wl(image) | |
362 | + ww_wl_image = self.do_ww_wl(image) | |
363 | + image = self.do_colour_image(ww_wl_image) | |
358 | 364 | if self.current_mask and self.current_mask.is_shown: |
359 | 365 | if self.buffer_slices[orientation].vtk_mask: |
360 | 366 | print "Getting from buffer" |
... | ... | @@ -373,7 +379,8 @@ class Slice(object): |
373 | 379 | else: |
374 | 380 | n_image = self.get_image_slice(orientation, slice_number) |
375 | 381 | image = iu.to_vtk(n_image, self.spacing, slice_number, orientation) |
376 | - image = self.do_ww_wl(image) | |
382 | + ww_wl_image = self.do_ww_wl(image) | |
383 | + image = self.do_colour_image(ww_wl_image) | |
377 | 384 | |
378 | 385 | if self.current_mask and self.current_mask.is_shown: |
379 | 386 | n_mask = self.get_mask_slice(orientation, slice_number) |
... | ... | @@ -652,17 +659,13 @@ class Slice(object): |
652 | 659 | |
653 | 660 | def UpdateColourTableBackground(self, pubsub_evt): |
654 | 661 | values = pubsub_evt.data |
655 | - | |
656 | - if (values[0]): | |
657 | - self.lut_bg.SetNumberOfColors(values[0]) | |
658 | - | |
659 | - self.lut_bg.SetSaturationRange(values[1]) | |
660 | - self.lut_bg.SetHueRange(values[2]) | |
661 | - self.lut_bg.SetValueRange(values[3]) | |
662 | - | |
663 | - thresh_min, thresh_max = self.window_level.GetOutput().GetScalarRange() | |
664 | - self.lut_bg.SetTableRange(thresh_min, thresh_max) | |
665 | - | |
662 | + self.number_of_colours= values[0] | |
663 | + self.saturation_range = values[1] | |
664 | + self.hue_range = values[2] | |
665 | + self.value_range = values[3] | |
666 | + for buffer_ in self.buffer_slices.values(): | |
667 | + buffer_.discard_vtk_image() | |
668 | + ps.Publisher().sendMessage('Reload actual slice') | |
666 | 669 | |
667 | 670 | def InputImageWidget(self, pubsub_evt): |
668 | 671 | widget, orientation = pubsub_evt.data |
... | ... | @@ -788,6 +791,24 @@ class Slice(object): |
788 | 791 | m[mask == 254] = 254 |
789 | 792 | return m |
790 | 793 | |
794 | + def do_colour_image(self, imagedata): | |
795 | + # map scalar values into colors | |
796 | + lut_bg = vtk.vtkLookupTable() | |
797 | + lut_bg.SetTableRange(imagedata.GetScalarRange()) | |
798 | + lut_bg.SetSaturationRange(self.saturation_range) | |
799 | + lut_bg.SetHueRange(self.hue_range) | |
800 | + lut_bg.SetValueRange(self.value_range) | |
801 | + lut_bg.Build() | |
802 | + | |
803 | + # map the input image through a lookup table | |
804 | + img_colours_bg = vtk.vtkImageMapToColors() | |
805 | + img_colours_bg.SetOutputFormatToRGB() | |
806 | + img_colours_bg.SetLookupTable(lut_bg) | |
807 | + img_colours_bg.SetInput(imagedata) | |
808 | + img_colours_bg.Update() | |
809 | + | |
810 | + return img_colours_bg.GetOutput() | |
811 | + | |
791 | 812 | def do_colour_mask(self, imagedata): |
792 | 813 | scalar_range = int(imagedata.GetScalarRange()[1]) |
793 | 814 | r, g, b = self.current_mask.colour | ... | ... |