[prev in list] [next in list] [prev in thread] [next in thread] 

List:       vtkusers
Subject:    Re: [vtkusers] rendering a series of BMP images - revisited
From:       Prathamesh Kulkarni <prathameshmkulkarni () gmail ! com>
Date:       2010-11-29 19:55:59
Message-ID: AANLkTik=Cim2sF7DnOpKLkk4Xoy_VNL3jjCzRqXgFsRL () mail ! gmail ! com
[Download RAW message or body]

[Attachment #2 (multipart/alternative)]


Thanks, that takes care of most of my questions. I will try all these out.

- Prathamesh

On Mon, Nov 29, 2010 at 1:25 PM, David Gobbi <david.gobbi@gmail.com> wrote:

> 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@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@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@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@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@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
>>>>
>>>>
>>>
>>
>

[Attachment #5 (text/html)]

<div dir="ltr">Thanks, that takes care of most of my questions. I will try all these \
out.<br><br>- Prathamesh<br><br><div class="gmail_quote">On Mon, Nov 29, 2010 at 1:25 \
PM, David Gobbi <span dir="ltr">&lt;<a \
href="mailto:david.gobbi@gmail.com">david.gobbi@gmail.com</a>&gt;</span> wrote:<br> \
<blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px \
solid rgb(204, 204, 204); padding-left: 1ex;">If the images are greyscale, you should \
check to make sure that the reader is only reading in a single-component volume:<div> \
<br></div><div>reader.Update()</div><div>print \
reader.GetOutput().GetNumberOfScalarComponents()</div>

<div><br></div><div>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.</div>


<div><br></div><div>Even for greyscale, it is typical to have a \
vtkColorTransferFunction.  You can make it into a simple \
ramp:</div><div><br></div><div>ctf = \
vtkColorTranferFunction()</div><div><div>ctf.AddRGBPoint(0,    0.0, 0.0, 0.0)</div>


<div>ctf.AddRGBPoint(255,  1.0, 1.0, 1.0)</div><div><br></div><div>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].</div>


<div><br></div><font color="#888888"><div> - David</div></font><div><div></div><div \
class="h5"><br><div class="gmail_quote">On Mon, Nov 29, 2010 at 12:14 PM, Prathamesh \
Kulkarni <span dir="ltr">&lt;<a href="mailto:prathameshmkulkarni@gmail.com" \
target="_blank">prathameshmkulkarni@gmail.com</a>&gt;</span> wrote:<br>


<blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px \
solid rgb(204, 204, 204); padding-left: 1ex;"><div dir="ltr">They are gary-scale \
images. Hence I don&#39;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.<br>



<br>Thanks,<br><font \
color="#888888">Prathamesh</font><div><div></div><div><br><br><div \
class="gmail_quote">On Mon, Nov 29, 2010 at 1:02 PM, David Gobbi <span \
dir="ltr">&lt;<a href="mailto:david.gobbi@gmail.com" \
target="_blank">david.gobbi@gmail.com</a>&gt;</span> wrote:<br>


<blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px \
solid rgb(204, 204, 204); padding-left: 1ex;"> Hi Prathamesh,<div><br></div><div>The \
range is set by SetDataExtent(), which you do.</div><div><br></div><div>But there are \
several unusual things about your application that you don&#39;t explain in your \
email.</div><div>





- Are the BMP files RGB or are they greyscale?</div><div>- Did you mean to make a \
vtkColorTransferFunction for your volume?</div><div>- Why only five \
slices?</div><div><br></div><font color="#888888"><div>  - David</div>



</font><div><div></div><div><div><br><div class="gmail_quote">

On Mon, Nov 29, 2010 at 11:57 AM, Prathamesh Kulkarni <span dir="ltr">&lt;<a \
href="mailto:prathameshmkulkarni@gmail.com" \
target="_blank">prathameshmkulkarni@gmail.com</a>&gt;</span> wrote:<br><blockquote \
class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, \
204, 204); padding-left: 1ex;">





<div dir="ltr">For that I used the SetFilePrefix() and SetFilePattern. Is there any \
other way of setting the range of files?<br><font color="#888888"><br>- \
Prathamesh</font><div><div></div><div><br><br><div class="gmail_quote">





On Mon, Nov 29, 2010 at 12:50 PM, Darshan Pai <span dir="ltr">&lt;<a \
href="mailto:darshanpai@gmail.com" \
target="_blank">darshanpai@gmail.com</a>&gt;</span> wrote:<br> <blockquote \
class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, \
204, 204); padding-left: 1ex;">You probably need to set the range of the files \
<br><br><div class="gmail_quote"><div><div>

</div>


<div>On Mon, Nov 29, 2010 at 11:36 AM, Prathamesh Kulkarni <span dir="ltr">&lt;<a \
href="mailto:prathameshmkulkarni@gmail.com" \
target="_blank">prathameshmkulkarni@gmail.com</a>&gt;</span> wrote:<br> \
</div></div><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; \
border-left: 1px solid rgb(204, 204, 204); padding-left: \
1ex;"><div><div></div><div><div dir="ltr"><div><br></div><div>Hello,</div> \
<div><br></div><div>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. </div> \
<div><br></div> <div>Please point me out to where I am doing a mistake. My code is \
attached below.</div><div><br></div><div><br></div><div>#................................................................................................#</div>









<div><br></div><div>import vtk</div><div>from vtk import \
*</div><div><br></div><div>bmp_reader = \
vtk.vtkBMPReader()</div><div><br></div><div>bmp_reader.SetFilePrefix(&#39;../sampleData/sample_&#39;)</div><div>bmp_reader.SetFilePattern(&#39;%s%d.bmp&#39;)</div>









<div><br></div><div>#print bmp_reader</div><div><br></div><div>height = \
512</div><div>width = 496</div><div>depth = 5</div><div><br></div><div>#this is \
default behaviour anyways..</div><div>bmp_reader.SetFileNameSliceOffset(1)</div>








<div>bmp_reader.SetFileNameSliceSpacing(1)</div><div><br></div><div>#bmp_reader.SetNumberOfScalarComponents(3)</div><div>bmp_reader.SetDataSpacing(1, \
1, 1)</div><div>bmp_reader.SetDataOrigin(0, 0, \
0)</div><div>bmp_reader.SetDataExtent(0, width-1, 0, height-1, 0, depth-1)</div>








<div>bmp_reader.SetDataScalarTypeToUnsignedChar()</div><div><br></div><div>alpha_channel_function \
= vtk.vtkPiecewiseFunction()</div><div>alpha_channel_function.AddPoint(20, \
0.1)</div><div>alpha_channel_function.AddPoint(100, 1.0)</div>








<div><br></div><div>volume_property = \
vtk.vtkVolumeProperty()</div><div>volume_property.SetScalarOpacity(alpha_channel_function)</div><div><br></div><div>composite_function \
= vtk.vtkVolumeRayCastCompositeFunction()</div>







<div>
#volume_mapper = vtk.vtkVolumeRayCastMapper()</div><div>volume_mapper = \
vtk.vtkFixedPointVolumeRayCastMapper()</div><div><br></div><div>#volume_mapper.SetVolu \
meRayCastFunction(composite_function)</div><div>volume_mapper.SetInput(bmp_reader.GetOutput())</div>









<div><br></div><div>volume = \
vtk.vtkVolume()</div><div>volume.SetMapper(volume_mapper)</div><div>volume.SetProperty(volume_property)</div><div><br></div><div>renderer \
= vtk.vtkRenderer()</div><div>render_window = vtk.vtkRenderWindow()</div>








<div>render_window_interactor = \
vtk.vtkRenderWindowInteractor()</div><div><br></div><div>render_window.AddRenderer(ren \
derer)</div><div>render_window_interactor.SetRenderWindow(render_window)</div><div><br></div><div>renderer.AddVolume(volume)</div>









<div>renderer.SetBackground(1, 1, 1)</div><div>render_window.SetSize(500, \
500)</div><div><br></div><div>render_window_interactor.Initialize()</div><div>render_window.Render()</div><div>render_window_interactor.Start()</div>









</div>
<br></div></div>_______________________________________________<br>
Powered by <a href="http://www.kitware.com" target="_blank">www.kitware.com</a><br>
<br>
Visit other Kitware open-source projects at <a \
href="http://www.kitware.com/opensource/opensource.html" \
target="_blank">http://www.kitware.com/opensource/opensource.html</a><br> <br>
Please keep messages on-topic and check the VTK FAQ at: <a \
href="http://www.vtk.org/Wiki/VTK_FAQ" \
target="_blank">http://www.vtk.org/Wiki/VTK_FAQ</a><br> <br>
Follow this link to subscribe/unsubscribe:<br>
<a href="http://www.vtk.org/mailman/listinfo/vtkusers" \
target="_blank">http://www.vtk.org/mailman/listinfo/vtkusers</a><br> \
<br></blockquote></div><br> </blockquote></div><br></div></div></div>
<br>_______________________________________________<br>
Powered by <a href="http://www.kitware.com" target="_blank">www.kitware.com</a><br>
<br>
Visit other Kitware open-source projects at <a \
href="http://www.kitware.com/opensource/opensource.html" \
target="_blank">http://www.kitware.com/opensource/opensource.html</a><br> <br>
Please keep messages on-topic and check the VTK FAQ at: <a \
href="http://www.vtk.org/Wiki/VTK_FAQ" \
target="_blank">http://www.vtk.org/Wiki/VTK_FAQ</a><br> <br>
Follow this link to subscribe/unsubscribe:<br>
<a href="http://www.vtk.org/mailman/listinfo/vtkusers" \
target="_blank">http://www.vtk.org/mailman/listinfo/vtkusers</a><br> \
<br></blockquote></div><br></div> \
</div></div></blockquote></div><br></div></div></div> \
</blockquote></div><br></div></div></div> </blockquote></div><br></div>



_______________________________________________
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


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic