[vtkusers] Extract a slice and save it as jpg/png
Chris Turner
cturnercomplex at googlemail.com
Wed Jul 14 12:59:16 EDT 2010
alright thanks Jothy - I changed that but still the results are the same
On Wed, Jul 14, 2010 at 12:28 PM, Jothy <jothybasu at gmail.com> wrote:
> You are not setting the opaccity/color transfer function properly
>
> try this , my scalar values range from 0-100.
>
> # The following class is used to store transparencyv-values for later
> retrival. In our case, we want the value 0 to be
> # completly opaque whereas the three different cubes are given different
> transperancy-values to show how it works.
> alphaChannelFunc = vtk.vtkPiecewiseFunction()
> alphaChannelFunc.AddPoint(0, 0.0)
> alphaChannelFunc.AddPoint(10, 0.005)
> alphaChannelFunc.AddPoint(50, 0.1)
> alphaChannelFunc.AddPoint(100, 0.15)
>
> # This class stores color data and can create color tables from a few
> color points. For this demo, we want the three cubes
> # to be of the colors red green and blue.
> colorFunc = vtk.vtkColorTransferFunction()
> colorFunc.AddRGBPoint(0, 1.0, 0.0, 0.0)
> colorFunc.AddRGBPoint(50, 0.0, 1.0, 0.0)
> colorFunc.AddRGBPoint(100, 0.0, 0.0, 1.0)
>
> Jothy
>
>
>
> On Wed, Jul 14, 2010 at 5:22 PM, Chris Turner
> <cturnercomplex at googlemail.com> wrote:
>>
>> So I tried to volume render the VOI but I only saw a black rectangle
>> and as soon as i try to click into the window it disappeared.
>>
>> Thats the code I added:
>> # create a rendering window and renderer
>> renderer = vtk.vtkRenderer()
>> window = vtk.vtkRenderWindow()
>> window.AddRenderer(renderer)
>>
>> iren = vtk.vtkRenderWindowInteractor()
>> iren.SetRenderWindow(window)
>>
>> # enable user interface interactor
>> window.SetSize(500,500)
>> renderer.SetBackground(1,1,1)
>> caster = vtk.vtkImageCast()
>>
>> caster.SetInput(voi.GetOutput())
>>
>> caster.SetOutputScalarTypeToUnsignedShort()
>>
>>
>>
>> rayCastFunction = vtk.vtkVolumeRayCastMIPFunction()
>> volumeMapper = vtk.vtkVolumeRayCastMapper()
>>
>> volumeMapper.SetInput(caster.GetOutput())
>>
>> volumeMapper.SetVolumeRayCastFunction(rayCastFunction)
>>
>> volumeProperty = vtk.vtkVolumeProperty() #slicer.vtkVolumeProperty()
>>
>> colorTransferFunction = vtk.vtkColorTransferFunction()
>>
>> colorTransferFunction.AddRGBPoint( 100.0, 1,1,1)
>>
>>
>>
>> opacityTransferFunction = vtk.vtkPiecewiseFunction()
>> opacityTransferFunction.AddPoint( 100, 1.0);
>>
>>
>> volumeProperty.SetColor(colorTransferFunction)
>>
>> volumeProperty.SetScalarOpacity(opacityTransferFunction)
>>
>> volumeProperty.SetInterpolationTypeToLinear()
>>
>> volumeProperty.ShadeOn()
>>
>>
>>
>> Volume = vtk.vtkVolume()
>>
>> Volume.SetMapper(volumeMapper)
>>
>> Volume.SetProperty(volumeProperty)
>> renderer.AddViewProp(Volume)
>>
>> iren.Start()
>>
>> Also when I use "print str(image)" I get the following output:
>>
>> vtkImageData (0x1bc4ef0)
>> Debug: Off
>> Modified Time: 404
>> Reference Count: 3
>> Registered Events: (none)
>> Source: (none)
>> Information: 0x1bc5060
>> Data Released: False
>> Global Release Data: Off
>> UpdateTime: 0
>> Release Data: Off
>> UpdateExtent: Not Initialized
>> WholeExtent: 0, 0, 0, 0, 0, 0
>> RequestExactExtent: Off
>> Field Data:
>> Debug: Off
>> Modified Time: 402
>> Reference Count: 1
>> Registered Events: (none)
>> Number Of Arrays: 0
>> Number Of Components: 0
>> Number Of Tuples: 0
>> Number Of Points: 1
>> Number Of Cells: 1
>> Cell Data:
>> Debug: Off
>> Modified Time: 392
>> Reference Count: 1
>> Registered Events: (none)
>> Number Of Arrays: 0
>> Number Of Components: 0
>> Number Of Tuples: 0
>> Copy Tuple Flags: ( 1 1 1 1 1 0 1 )
>> Interpolate Flags: ( 1 1 1 1 1 0 0 )
>> Pass Through Flags: ( 1 1 1 1 1 1 1 )
>> Scalars: (none)
>> Vectors: (none)
>> Normals: (none)
>> TCoords: (none)
>> Tensors: (none)
>> GlobalIds: (none)
>> PedigreeIds: (none)
>> Point Data:
>> Debug: Off
>> Modified Time: 398
>> Reference Count: 1
>> Registered Events: (none)
>> Number Of Arrays: 1
>> Array 0 name = ImageFile
>> Number Of Components: 1
>> Number Of Tuples: 1
>> Copy Tuple Flags: ( 1 1 1 1 1 0 1 )
>> Interpolate Flags: ( 1 1 1 1 1 0 0 )
>> Pass Through Flags: ( 1 1 1 1 1 1 1 )
>> Scalars:
>> Debug: Off
>> Modified Time: 397
>> Reference Count: 1
>> Registered Events: (none)
>> Name: ImageFile
>> Data type: short
>> Size: 1
>> MaxId: 0
>> NumberOfComponents: 1
>> Information: 0
>> Name: ImageFile
>> Number Of Components: 1
>> Number Of Tuples: 1
>> Size: 1
>> MaxId: 0
>> LookupTable: (none)
>> Array: 0x1bc9a10
>> Vectors: (none)
>> Normals: (none)
>> TCoords: (none)
>> Tensors: (none)
>> GlobalIds: (none)
>> PedigreeIds: (none)
>> Bounds:
>> Xmin,Xmax: (0, 0)
>> Ymin,Ymax: (0, 0)
>> Zmin,Zmax: (0, 0)
>> Compute Time: 0
>> ScalarType: 4
>> NumberOfScalarComponents: 1
>> Spacing: (1, 1, 1)
>> Origin: (0, 0, 0)
>> Dimensions: (1, 1, 1)
>> Increments: (1, 1, 1)
>> Extent: (0, 0, 0, 0, 0, 0)
>>
>> But when I load it in ParaView the image has the correct parameters.
>>
>> I'm confused.
>>
>> Chris
>>
>> On Wed, Jul 14, 2010 at 11:55 AM, Jothy <jothybasu at gmail.com> wrote:
>> > Are you able to render this atleast, before trying to save?
>> >
>> > Jothy
>> >
>> > On Wed, Jul 14, 2010 at 4:27 PM, Chris Turner
>> > <cturnercomplex at googlemail.com> wrote:
>> >>
>> >> bounds are (-69.3 ,323 ,332 ,9.68,468,448)
>> >> extents are (0,0,0,79,145,116)
>> >>
>> >> I changed the SetVOI to (-69,323,332,-68,468,448) but same result.
>> >>
>> >>
>> >> On Wed, Jul 14, 2010 at 11:01 AM, Jothy <jothybasu at gmail.com> wrote:
>> >> > Have you checked that your setVOi is with the bounds of the Image.
>> >> > What
>> >> > are
>> >> > your bounds?
>> >> >
>> >> > Jothy
>> >> >
>> >> > On Wed, Jul 14, 2010 at 3:58 PM, Chris Turner
>> >> > <cturnercomplex at googlemail.com> wrote:
>> >> >>
>> >> >> No didn't do the trick either.
>> >> >>
>> >> >> No file, no error/warning message.
>> >> >>
>> >> >> Thanks though!
>> >> >>
>> >> >> On Wed, Jul 14, 2010 at 10:54 AM, Jothy <jothybasu at gmail.com> wrote:
>> >> >> > Try SetVOI(0,0,0,79,1,146)
>> >> >> >
>> >> >> > Jothy
>> >> >> >
>> >> >> > On Wed, Jul 14, 2010 at 3:44 PM, Chris Turner
>> >> >> > <cturnercomplex at googlemail.com> wrote:
>> >> >> >>
>> >> >> >> Hi David & Bill,
>> >> >> >>
>> >> >> >> thanks for your patience and your help I appreciate it a lot! So
>> >> >> >> this
>> >> >> >> is the code with David's suggestion:
>> >> >> >>
>> >> >> >> import os
>> >> >> >> import vtk
>> >> >> >> import sys
>> >> >> >>
>> >> >> >>
>> >> >> >> reader=vtk.vtkImageReader()
>> >> >> >> reader.SetFileName("/tmp/lungROI.vtk")
>> >> >> >> reader.Update()
>> >> >> >>
>> >> >> >> lut=vtk.vtkLookupTable()
>> >> >> >> lut.SetRange(-1024, +4095)
>> >> >> >>
>> >> >> >> map=vtk.vtkImageMapToColors()
>> >> >> >> map.SetInput(reader.GetOutput())
>> >> >> >> map.SetLookupTable(lut)
>> >> >> >>
>> >> >> >>
>> >> >> >> voi=vtk.vtkExtractVOI()
>> >> >> >> voi.SetInput(map.GetOutput())
>> >> >> >> voi.SetVOI(0,0,0,79,146,1)
>> >> >> >> voi.Update()
>> >> >> >>
>> >> >> >> writerp=vtk.vtkPNGWriter()
>> >> >> >> writerp.SetInput(voi.GetOutput())
>> >> >> >> writerp.SetFileName("/tmp/out.png")
>> >> >> >> writerp.Write()
>> >> >> >>
>> >> >> >> print "done"
>> >> >> >>
>> >> >> >>
>> >> >> >> .... but still no output nor an error message. You can take a
>> >> >> >> look
>> >> >> >> at
>> >> >> >> the Image here:
>> >> >> >>
>> >> >> >> http://www.load.to/t8MWurwasf/lungROI.vtk (~10mb)
>> >> >> >>
>> >> >> >> Thanks Again,
>> >> >> >> Chris
>> >> >> >>
>> >> >> >>
>> >> >> >> On Tue, Jul 13, 2010 at 4:38 PM, David Gobbi
>> >> >> >> <david.gobbi at gmail.com>
>> >> >> >> wrote:
>> >> >> >> > Hi Chris,
>> >> >> >> >
>> >> >> >> > This could be an instance of trying to write 16-bit data to a
>> >> >> >> > JPEG
>> >> >> >> > file. Try adding vtkImageMapToColors with a suitable
>> >> >> >> > vtkLookupTable.
>> >> >> >> > The Range of the lookup table will have to be set to something
>> >> >> >> > reasonable for the image, a range of (-1024, +4095) is a good
>> >> >> >> > place
>> >> >> >> > to
>> >> >> >> > start and then you can increase or decrease the range in order
>> >> >> >> > to
>> >> >> >> > get
>> >> >> >> > the contrast right.
>> >> >> >> >
>> >> >> >> > David
>> >> >> >> >
>> >> >> >> >
>> >> >> >> > On Tue, Jul 13, 2010 at 2:15 PM, Bill Lorensen
>> >> >> >> > <bill.lorensen at gmail.com>
>> >> >> >> > wrote:
>> >> >> >> >> Post you entire example. And, if you can post a link to your
>> >> >> >> >> data...
>> >> >> >> >>
>> >> >> >> >> On Tue, Jul 13, 2010 at 3:57 PM, Chris Turner
>> >> >> >> >> <cturnercomplex at googlemail.com> wrote:
>> >> >> >> >>> Hi Bill,
>> >> >> >> >>>
>> >> >> >> >>> thanks for your answer! But didn't do the trick.
>> >> >> >> >>> So strange I thought this was a standard question and
>> >> >> >> >>> procedure.
>> >> >> >> >>> And
>> >> >> >> >>> that there has to be a easy way to do that.
>> >> >> >> >>>
>> >> >> >> >>> And why don't I even get a error message or something. Even
>> >> >> >> >>> when
>> >> >> >> >>> I
>> >> >> >> >>> turn on the debug mode there is nothing suspicious.
>> >> >> >> >>>
>> >> >> >> >>> Anybody has another approach?
>> >> >> >> >>>
>> >> >> >> >>> Thanks
>> >> >> >> >>> Chris
>> >> >> >> >>>
>> >> >> >> >>> On Mon, Jul 12, 2010 at 10:16 AM, Bill Lorensen
>> >> >> >> >>> <bill.lorensen at gmail.com> wrote:
>> >> >> >> >>>> Try,
>> >> >> >> >>>> voi.SetVOI(0,0,0,511,511,0)
>> >> >> >> >>>>
>> >> >> >> >>>> On Mon, Jul 12, 2010 at 10:07 AM, Chris Turner
>> >> >> >> >>>> <cturnercomplex at googlemail.com> wrote:
>> >> >> >> >>>>> Really? Am I the only one with that problem?
>> >> >> >> >>>>>
>> >> >> >> >>>>> On Fri, Jul 9, 2010 at 5:02 PM, Chris Turner
>> >> >> >> >>>>> <cturnercomplex at googlemail.com> wrote:
>> >> >> >> >>>>>> Hi Everyone!
>> >> >> >> >>>>>>
>> >> >> >> >>>>>> I'm trying to extract a slice from a vtkImageData object
>> >> >> >> >>>>>> and
>> >> >> >> >>>>>> save
>> >> >> >> >>>>>> it as picture.
>> >> >> >> >>>>>>
>> >> >> >> >>>>>> That's how I do it:
>> >> >> >> >>>>>>
>> >> >> >> >>>>>> voi=vtkExtractVOI()
>> >> >> >> >>>>>> voi.SetInput(imageData)
>> >> >> >> >>>>>> voi.SetVOI(0,0,0,512,512,1)
>> >> >> >> >>>>>> voi.Update()
>> >> >> >> >>>>>>
>> >> >> >> >>>>>> writer=vtkJPEGWriter()
>> >> >> >> >>>>>> writer.SetInput(voi.GetOutput())
>> >> >> >> >>>>>> writer.SetFileName("slice.jpg")
>> >> >> >> >>>>>> writer.Write()
>> >> >> >> >>>>>>
>> >> >> >> >>>>>> ImageData is 512x512x40 spacing 1,1,1
>> >> >> >> >>>>>>
>> >> >> >> >>>>>> The strange thing is I don't get an output nor an error
>> >> >> >> >>>>>> message.
>> >> >> >> >>>>>> So
>> >> >> >> >>>>>> I
>> >> >> >> >>>>>> think I'm missing something here.... but it can't figure
>> >> >> >> >>>>>> out
>> >> >> >> >>>>>> what.
>> >> >> >> >>>>>>
>> >> >> >> >>>>>> So does anybody have an idea or a better solution?
>> >> >> >> >>>>>>
>> >> >> >> >>>>>> Thanks
>> >> >> >> >>>>>> Chris
>> >> >> >> >>>>>>
>> >> >> >> >>>>> _______________________________________________
>> >> >> >> >>>>> Powered by www.kitware.com
>> >> >> >> >>>>>
>> >> >> >> >>>>> Visit other Kitware open-source projects at
>> >> >> >> >>>>> http://www.kitware.com/opensource/opensource.html
>> >> >> >> >>>>>
>> >> >> >> >>>>> Please keep messages on-topic and check the VTK FAQ at:
>> >> >> >> >>>>> http://www.vtk.org/Wiki/VTK_FAQ
>> >> >> >> >>>>>
>> >> >> >> >>>>> Follow this link to subscribe/unsubscribe:
>> >> >> >> >>>>> http://www.vtk.org/mailman/listinfo/vtkusers
>> >> >> >> >>>>>
>> >> >> >> >>>>
>> >> >> >> >>>
>> >> >> >> >> _______________________________________________
>> >> >> >> >> Powered by www.kitware.com
>> >> >> >> >>
>> >> >> >> >> Visit other Kitware open-source projects at
>> >> >> >> >> http://www.kitware.com/opensource/opensource.html
>> >> >> >> >>
>> >> >> >> >> Please keep messages on-topic and check the VTK FAQ at:
>> >> >> >> >> http://www.vtk.org/Wiki/VTK_FAQ
>> >> >> >> >>
>> >> >> >> >> Follow this link to subscribe/unsubscribe:
>> >> >> >> >> http://www.vtk.org/mailman/listinfo/vtkusers
>> >> >> >> >>
>> >> >> >> >
>> >> >> >> _______________________________________________
>> >> >> >> Powered by www.kitware.com
>> >> >> >>
>> >> >> >> Visit other Kitware open-source projects at
>> >> >> >> http://www.kitware.com/opensource/opensource.html
>> >> >> >>
>> >> >> >> Please keep messages on-topic and check the VTK FAQ at:
>> >> >> >> http://www.vtk.org/Wiki/VTK_FAQ
>> >> >> >>
>> >> >> >> Follow this link to subscribe/unsubscribe:
>> >> >> >> http://www.vtk.org/mailman/listinfo/vtkusers
>> >> >> >
>> >> >> >
>> >> >> _______________________________________________
>> >> >> Powered by www.kitware.com
>> >> >>
>> >> >> Visit other Kitware open-source projects at
>> >> >> http://www.kitware.com/opensource/opensource.html
>> >> >>
>> >> >> Please keep messages on-topic and check the VTK FAQ at:
>> >> >> http://www.vtk.org/Wiki/VTK_FAQ
>> >> >>
>> >> >> Follow this link to subscribe/unsubscribe:
>> >> >> http://www.vtk.org/mailman/listinfo/vtkusers
>> >> >
>> >> >
>> >> _______________________________________________
>> >> Powered by www.kitware.com
>> >>
>> >> Visit other Kitware open-source projects at
>> >> http://www.kitware.com/opensource/opensource.html
>> >>
>> >> Please keep messages on-topic and check the VTK FAQ at:
>> >> http://www.vtk.org/Wiki/VTK_FAQ
>> >>
>> >> Follow this link to subscribe/unsubscribe:
>> >> http://www.vtk.org/mailman/listinfo/vtkusers
>> >
>> >
>> _______________________________________________
>> Powered by www.kitware.com
>>
>> Visit other Kitware open-source projects at
>> http://www.kitware.com/opensource/opensource.html
>>
>> Please keep messages on-topic and check the VTK FAQ at:
>> http://www.vtk.org/Wiki/VTK_FAQ
>>
>> Follow this link to subscribe/unsubscribe:
>> http://www.vtk.org/mailman/listinfo/vtkusers
>
>
More information about the vtkusers
mailing list