# How to do 3D affine transform where the shape of the output is different than the input

**URL:** <https://forum.opencv.org/t/how-to-do-3d-affine-transform-where-the-shape-of-the-output-is-different-than-the-input/13546>\
**Category:** Python\
**Created:** [June 15, 2023, 7:19pm UTC](https://forum.opencv.org/t/how-to-do-3d-affine-transform-where-the-shape-of-the-output-is-different-than-the-input/13546 "2023-06-15T19:19:37Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![crackwitz](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/crackwitz/32/14_2.png) [@crackwitz](https://forum.opencv.org/u/crackwitz)\
**Post date:** [June 15, 2023, 10:09pm UTC](https://forum.opencv.org/t/how-to-do-3d-affine-transform-where-the-shape-of-the-output-is-different-than-the-input/13546/2 "2023-06-15T22:09:20Z")

</div>

opencv isn’t made for voxel data. one of the fundamental assumptions is that stuff is flat (a picture) and the third dimension is “attributes” (color).

the cv::Mat type, in C++, can carry a limited number of channels (512) but that still **doesn’t** mean the APIs (warpAffine) can just interpret data as multi-dimensional.

if you’re looking for speed, either write your kernel in python and slap numba on it, or some other thing like it.

or write your kernel as opencl or some other GPU-type thing.

GPUs are good at sampling in voxel data. trilinear interpolation is commonly available.

if you’re trying to visualize voxel data volumetrically, take a class on the subject. there are approaches that run well even on GPUs that are over a decade old.

---

_[View the full topic](https://forum.opencv.org/t/how-to-do-3d-affine-transform-where-the-shape-of-the-output-is-different-than-the-input/13546)._
