[vtkusers] Artifacts in volume rendering

Aashish Chaudhary aashish.chaudhary at kitware.com
Wed Apr 13 09:54:47 EDT 2016


Hi Elvis,

Can you post your images somewhere (I couldn't find them in the email)?

Thanks,


On Wed, Apr 13, 2016 at 9:52 AM, Dženan Zukić <dzenanz at gmail.com> wrote:

> Hi Elvis,
>
> volume rendering is known to have some artifacts from certain angles. It
> is data-dependent, and sometimes the artifacts are more pronounced. This is
> due to many trade-offs between rendering speed and quality. I sometimes
> encounter them too, with volume-rendered medical data.
>
> Regards,
> Dženan
>
> On Wed, Apr 13, 2016 at 8:54 AM, Elvis Stansvik <
> elvis.stansvik at orexplore.com> wrote:
>
>> 2016-04-12 16:16 GMT+02:00 Elvis Stansvik <elvis.stansvik at orexplore.com>:
>>
>>> 2016-04-12 15:56 GMT+02:00 Elvis Stansvik <elvis.stansvik at orexplore.com>
>>> :
>>>
>>>> Hi all,
>>>>
>>>> Following Berk Geveci's great blog post from 2014 on writing a custom
>>>> HDF5 reader in Python [1], I tried to take his code and modify it to load
>>>> HDF5 files where the densities are float32 and vary between 0 and 64.
>>>>
>>>> The only change I did to his reader was to modify RequestData to scale
>>>> the loaded data and convert it to uint16, like this:
>>>>
>>>>     data = (data * 1023).astype(uint16)
>>>>
>>>> (should get me roughly in the range 0-65535).
>>>>
>>>> I then generated a test HDF5 file containing a cylindrical volume like
>>>> this:
>>>>
>>>> def create_cylinder_file(filename, height, radius):
>>>>     """Create a cylindrical volume and save it in test.hdf5.
>>>>
>>>>     The densities are saved as float32 and will vary sinusoidically
>>>>     from 0 to 64 along the cylinder height.
>>>>
>>>>     The result is saved in the "test" dataset in the output file.
>>>>     """
>>>>     z_values = 32 + 32 * sin(linspace(0, 2*pi, height))
>>>>     diameter = radius * 2
>>>>     data = zeros(shape=(diameter, diameter, height), dtype=float32)
>>>>
>>>>     for x in range(diameter):
>>>>         for y in range(diameter):
>>>>             if (x - radius)**2 + (y - radius)**2 <= radius**2:
>>>>                 data[x, y, :] = z_values
>>>>
>>>
>>> I made a quick test with densities uniformly random 0-64 instead (e.g.
>>> data[x, y, :] = uniform(0, 64, height) above instead), with the attached
>>> result. Notice how the artifacts are still present (they're particularly
>>> visible from this angle).
>>>
>>> Perhaps it's obvious to someone more experienced in visualisation than I
>>> am what is happening here?
>>>
>>
>> Noone has seen these sort of artifacts before?
>>
>> I've tried blurring my synthetic data a little, as well as turning on
>> shading again, but the artifacts are always there.
>>
>> I don't understand where these "stripes" are coming from, or why I'm
>> seeing red voxels at all towards the denser parts of the cylinder. My color
>> transfer function has no red at all in the range 40000-65535.
>>
>> Elvis
>>
>>
>>>
>>> Elvis
>>>
>>>
>>>>
>>>>     # Write array to HDF5 file.
>>>>     with h5py.File(filename, 'w') as file_:
>>>>         data_set = file_.create_dataset(
>>>>             name='test',
>>>>             shape=data.shape,
>>>>             dtype=data.dtype,
>>>>             data=data
>>>>         )
>>>>
>>>> I then test it all out using a vtkVolumeRayCastMapper based pipeline
>>>> like this:
>>>>
>>>>     reader = HDF5Source()
>>>>     reader.SetFileName('test.hdf5')
>>>>
>>>>     rayCastFunction = vtk.vtkVolumeRayCastCompositeFunction()
>>>>
>>>>     mapper = vtk.vtkVolumeRayCastMapper()
>>>>     mapper.SetVolumeRayCastFunction(rayCastFunction)
>>>>     mapper.SetInputConnection(reader.GetOutputPort())
>>>>
>>>>     colorTransferFunction = vtk.vtkColorTransferFunction()
>>>>     colorTransferFunction.AddRGBPoint(0, 0, 0, 0)     # Black
>>>>     colorTransferFunction.AddRGBPoint(20000, 1, 0, 0) # Red
>>>>     colorTransferFunction.AddRGBPoint(40000, 0, 1, 0) # Green
>>>>     colorTransferFunction.AddRGBPoint(65535, 0, 0, 1) # Blue
>>>>
>>>>     opacityTransferFunction = vtk.vtkPiecewiseFunction()
>>>>     opacityTransferFunction.AddPoint(0, 0)     # Transparent
>>>>     opacityTransferFunction.AddPoint(65535, 1) # Opaque
>>>>
>>>>     volumeProperty = vtk.vtkVolumeProperty()
>>>>     volumeProperty.SetColor(colorTransferFunction)
>>>>     volumeProperty.SetScalarOpacity(opacityTransferFunction)
>>>>     volumeProperty.ShadeOff()
>>>>     volumeProperty.SetInterpolationTypeToLinear()
>>>>
>>>>     volume = vtk.vtkVolume()
>>>>     volume.SetMapper(mapper)
>>>>     volume.SetProperty(volumeProperty)
>>>>
>>>>     renderer = vtk.vtkRenderer()
>>>>     renderer.AddVolume(volume)
>>>>     renderer.SetBackground(.85, .84, .83)
>>>>
>>>>     renderWindow = vtk.vtkRenderWindow()
>>>>     renderWindow.AddRenderer(renderer)
>>>>     renderWindow.SetSize(600, 600)
>>>>
>>>>     interactor = vtk.vtkRenderWindowInteractor()
>>>>     interactor.SetRenderWindow(renderWindow)
>>>>     interactor.Initialize()
>>>>
>>>>     renderWindow.Render()
>>>>     interactor.Start()
>>>>
>>>> I'm attaching a main.py which contains the full code, including the
>>>> HDFSource reader with my slight modification, and a screenshot showing the
>>>> result.
>>>>
>>>> Noticy how there's some strange artifacts in the denser (greener,
>>>> bluer) parts of the cylinder. Anyone know where these artifacts may come
>>>> from? It's entirely possible that it has nothing to with the custom reader,
>>>> but something with my pipeline..?
>>>>
>>>> Very grateful for any ideas!
>>>>
>>>> Cheers,
>>>> Elvis
>>>>
>>>> [1]
>>>> https://blog.kitware.com/developing-hdf5-readers-using-vtkpythonalgorithm/
>>>>
>>>
>>>
>>
>> _______________________________________________
>> 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
>>
>> Search the list archives at: http://markmail.org/search/?q=vtkusers
>>
>> Follow this link to subscribe/unsubscribe:
>> http://public.kitware.com/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
>
> Search the list archives at: http://markmail.org/search/?q=vtkusers
>
> Follow this link to subscribe/unsubscribe:
> http://public.kitware.com/mailman/listinfo/vtkusers
>
>


-- 



*| Aashish Chaudhary | Technical Leader         | Kitware Inc.            *
*| http://www.kitware.com/company/team/chaudhary.html
<http://www.kitware.com/company/team/chaudhary.html>*
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/vtkusers/attachments/20160413/7c326550/attachment.html>


More information about the vtkusers mailing list