[vtkusers] rendering a series of BMP images - revisited
David Gobbi
david.gobbi at gmail.com
Mon Nov 29 14:25:59 EST 2010
If the images are greyscale, you should check to make sure that the reader
is only reading in a single-component volume:
reader.Update()
print reader.GetOutput().GetNumberOfScalarComponents()
If this returns 3 or 4, then your BMPs are actually RGB, but with R=B=G. To
be on the safe side, you should use vtkImageExtractComponents() so that you
are only providing one component to the volume mapper.
Even for greyscale, it is typical to have a vtkColorTransferFunction. You
can make it into a simple ramp:
ctf = vtkColorTranferFunction()
ctf.AddRGBPoint(0, 0.0, 0.0, 0.0)
ctf.AddRGBPoint(255, 1.0, 1.0, 1.0)
You can look at VTK/Examples/Medical/Python/Medical4.py, just note that the
example is for a 16-bit volume with a pixel intensity range of around
[0,1200] while your volume will have a pixel intensity range of [0,255].
- David
On Mon, Nov 29, 2010 at 12:14 PM, Prathamesh Kulkarni <
prathameshmkulkarni at gmail.com> wrote:
> They are gary-scale images. Hence I don't use the color transfer function.
> Is this correct? I increased the number of files from 5 to 20 and now it
> shows me a volume but with intermediate slices blanked. I think this is a
> problem of the opacity function, and I am trying to learn how to use it.
> Please let me know if there is any example for it.
>
> Thanks,
> Prathamesh
>
>
> On Mon, Nov 29, 2010 at 1:02 PM, David Gobbi <david.gobbi at gmail.com>wrote:
>
>> Hi Prathamesh,
>>
>> The range is set by SetDataExtent(), which you do.
>>
>> But there are several unusual things about your application that you don't
>> explain in your email.
>> - Are the BMP files RGB or are they greyscale?
>> - Did you mean to make a vtkColorTransferFunction for your volume?
>> - Why only five slices?
>>
>> - David
>>
>> On Mon, Nov 29, 2010 at 11:57 AM, Prathamesh Kulkarni <
>> prathameshmkulkarni at gmail.com> wrote:
>>
>>> For that I used the SetFilePrefix() and SetFilePattern. Is there any
>>> other way of setting the range of files?
>>>
>>> - Prathamesh
>>>
>>>
>>> On Mon, Nov 29, 2010 at 12:50 PM, Darshan Pai <darshanpai at gmail.com>wrote:
>>>
>>>> You probably need to set the range of the files
>>>>
>>>> On Mon, Nov 29, 2010 at 11:36 AM, Prathamesh Kulkarni <
>>>> prathameshmkulkarni at gmail.com> wrote:
>>>>
>>>>>
>>>>> Hello,
>>>>>
>>>>> I am trying to render a series of BMP images as a volume using Ray
>>>>> Casting in vtk. However, what I see is only a single slice of image.
>>>>>
>>>>> Please point me out to where I am doing a mistake. My code is attached
>>>>> below.
>>>>>
>>>>>
>>>>>
>>>>> #................................................................................................#
>>>>>
>>>>> import vtk
>>>>> from vtk import *
>>>>>
>>>>> bmp_reader = vtk.vtkBMPReader()
>>>>>
>>>>> bmp_reader.SetFilePrefix('../sampleData/sample_')
>>>>> bmp_reader.SetFilePattern('%s%d.bmp')
>>>>>
>>>>> #print bmp_reader
>>>>>
>>>>> height = 512
>>>>> width = 496
>>>>> depth = 5
>>>>>
>>>>> #this is default behaviour anyways..
>>>>> bmp_reader.SetFileNameSliceOffset(1)
>>>>> bmp_reader.SetFileNameSliceSpacing(1)
>>>>>
>>>>> #bmp_reader.SetNumberOfScalarComponents(3)
>>>>> bmp_reader.SetDataSpacing(1, 1, 1)
>>>>> bmp_reader.SetDataOrigin(0, 0, 0)
>>>>> bmp_reader.SetDataExtent(0, width-1, 0, height-1, 0, depth-1)
>>>>> bmp_reader.SetDataScalarTypeToUnsignedChar()
>>>>>
>>>>> alpha_channel_function = vtk.vtkPiecewiseFunction()
>>>>> alpha_channel_function.AddPoint(20, 0.1)
>>>>> alpha_channel_function.AddPoint(100, 1.0)
>>>>>
>>>>> volume_property = vtk.vtkVolumeProperty()
>>>>> volume_property.SetScalarOpacity(alpha_channel_function)
>>>>>
>>>>> composite_function = vtk.vtkVolumeRayCastCompositeFunction()
>>>>> #volume_mapper = vtk.vtkVolumeRayCastMapper()
>>>>> volume_mapper = vtk.vtkFixedPointVolumeRayCastMapper()
>>>>>
>>>>> #volume_mapper.SetVolumeRayCastFunction(composite_function)
>>>>> volume_mapper.SetInput(bmp_reader.GetOutput())
>>>>>
>>>>> volume = vtk.vtkVolume()
>>>>> volume.SetMapper(volume_mapper)
>>>>> volume.SetProperty(volume_property)
>>>>>
>>>>> renderer = vtk.vtkRenderer()
>>>>> render_window = vtk.vtkRenderWindow()
>>>>> render_window_interactor = vtk.vtkRenderWindowInteractor()
>>>>>
>>>>> render_window.AddRenderer(renderer)
>>>>> render_window_interactor.SetRenderWindow(render_window)
>>>>>
>>>>> renderer.AddVolume(volume)
>>>>> renderer.SetBackground(1, 1, 1)
>>>>> render_window.SetSize(500, 500)
>>>>>
>>>>> render_window_interactor.Initialize()
>>>>> render_window.Render()
>>>>> render_window_interactor.Start()
>>>>>
>>>>> _______________________________________________
>>>>> 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
>>>
>>>
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20101129/df14e7ab/attachment.htm>
More information about the vtkusers
mailing list