Search code examples
c++cudainterpolationraytracingtexture2d

GPU-Computation (CUDA) tex2d/tex3d - How to deal with anisotropic pixel/voxel


I am quite new to cuda programming and i have a question about the texXD function. My goal is to implement a simple GPU-based ray tracer using the optimized CUDA functionality.

See CUDA texture API that is used by NVIDIA.

At my research I have to deal with images that have a different resolution for every dimension (like CT images, (x,y) have a different resolution as (z)). Resampling to an isotropic pixel/voxel size might bring up some problems (especially for medical diagnosis).

For example i have an image with size (100px x 50px) and a resolution of (2px/mm x 1px/mm). The ray enters the image at an arbitrary point and leaves is somewhere else. The ray is sampled in the direction form entrance to leaving point. At each sample point (pos.x,pos.y) the tex2D function carries out an (bicubicbilinear) interpolation taking the neighbour pixel values into account weighted by their distance from the sample point.

example image: In both shapes the corner points are named the same way(x1,y1),.... The only difference is the physical space between the corner points. The interpolation point is (x,y). I computed an example using the formula for rectangular grids and yield a different results for both grids. But if I use the ratio of areas of the numbered rectangles I got a different result.

My Question: Will CUDA take care of the different resolutions of the dimensions or does CUDA see all pixel in the same distance (and therefore as a squared grid)? The formula used by CUDA seems to be the one for a squared grid (google:CUDA Texture fetching).

Or can I resample the image to squared grid before using tex2D without a substantial information loss?

Any suggestions are recommended. If you need some more clarification, feel free to ask. I will specifiy my question.


Solution

  • I don't believe what (I think it is) you are trying to do can be achieved using textures. The sole filtering mode supported using textures is described here.

    Some salient points:

    1. Textures don't have resolution. The just have dimensions.
    2. Textures data is implicitly uniformly spaced in all dimensions.
    3. Texture interpolation is done in a reduced accuracy fixed point arithmetic format which gives 8 bits of representational accuracy

    None of this seems like anything that would be useful for the interpolation on a non-uniform grid which you are describing. At a minimum you would need to perform a coordinate transformation before you could use the uniform filtering mode. The amount of effort and expense would be about the same as just writing an interpolation routine yourself in user code.