Numpy fastest 3D to 2D projection

user2290362

I have a 3D array of binary data. I want to project this to 3 2D images - side on, head on, birds eye.

I have written the code:

for x in range(data.shape[2]):
    for y in range(data.shape[0]):
        val = 0
        for z in range(data.shape[1]):
            if data[y][z][x] > 0:
                val = 255
                break
        side[y][x] = val

But this is horrifically slow (75s!) for a ~700x300x300 matrix.

What is the fastest way of achieving this task?

EDIT:

To save the image, I have used:

sideImage = Image.fromarray(side)
sideImage.convert('RGB').save("sideImage.png")
YXD

You can compute it as follows:

>>> data = np.random.random_sample((200, 300, 100)) > 0.5
>>> data.any(axis=-1).shape # show the result has the shape we want
(200, 300)
>>> data.any(axis=-1)
array([[ True,  True,  True, ...,  True,  True,  True],
       [ True,  True,  True, ...,  True,  True,  True],
       [ True,  True,  True, ...,  True,  True,  True],
       ...,
       [ True,  True,  True, ...,  True,  True,  True],
       [ True,  True,  True, ...,  True,  True,  True],
       [ True,  True,  True, ...,  True,  True,  True]], dtype=bool)
>>>

You can scale values if you need

>>> data.any(axis=-1) * 255
array([[255, 255, 255, ..., 255, 255, 255],
       [255, 255, 255, ..., 255, 255, 255],
       [255, 255, 255, ..., 255, 255, 255],
       ...,
       [255, 255, 255, ..., 255, 255, 255],
       [255, 255, 255, ..., 255, 255, 255],
       [255, 255, 255, ..., 255, 255, 255]])
>>>

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Numpy fastest 3D to 2D projection

From Dev

Closest point projection of a 3D point to 3D triangles with numpy/scipy

From Dev

Numpy : 3D to 2D

From Dev

numpy - fastest way to build 2d array with permuted copies of numpy 1d array

From Dev

Mask a 3d array with a 2d mask in numpy

From Dev

Reorganizing a 2D numpy array into 3D

From Dev

Slice 3D ndarray with 2D ndarray in numpy?

From Dev

reshape numpy 3D array to 2D

From Dev

numpy with python: convert 3d array to 2d

From Dev

Convert 3d Numpy array to 2d

From Dev

Indexing a 2d array with a 3d array in numpy

From Dev

Plot 3d in 2d with numpy?

From Dev

Reshape numpy array from 3D to 2D

From Dev

Reshaping 3D Numpy Array to a 2D array

From Dev

Ortho projection of 3D points with a vector

From Dev

3D projection doesnt work

From Dev

3D projection to screen PHP

From Dev

Why use a Matrix for 3D Projection?

From Dev

Matplotlib separate 2D contour projection plots of 3D data

From Dev

python : 2D perspective projection of a 3D surface plot

From Dev

Analysis of a 3D point cloud by projection in a 2D surface

From Dev

3D to 2D projection using view frustum has issues with translation

From Dev

How to determine the projection (2D or 3D) of a matplotlib axes object?

From Dev

python : 2D perspective projection of a 3D surface plot

From Dev

Iterative non-linear-least-squares opimizing a 3d to 2d projection

From Dev

Fastest method to create 2D numpy array whose elements are in range

From Dev

python/numpy fastest method for 2d kernel rank filtering on masked arrays (and/or selective ranking)

From Dev

Numpy: Fastest way of computing diagonal for each row of a 2d array

From Dev

Fastest way to convert a list of indices to 2D numpy array of ones

Related Related

  1. 1

    Numpy fastest 3D to 2D projection

  2. 2

    Closest point projection of a 3D point to 3D triangles with numpy/scipy

  3. 3

    Numpy : 3D to 2D

  4. 4

    numpy - fastest way to build 2d array with permuted copies of numpy 1d array

  5. 5

    Mask a 3d array with a 2d mask in numpy

  6. 6

    Reorganizing a 2D numpy array into 3D

  7. 7

    Slice 3D ndarray with 2D ndarray in numpy?

  8. 8

    reshape numpy 3D array to 2D

  9. 9

    numpy with python: convert 3d array to 2d

  10. 10

    Convert 3d Numpy array to 2d

  11. 11

    Indexing a 2d array with a 3d array in numpy

  12. 12

    Plot 3d in 2d with numpy?

  13. 13

    Reshape numpy array from 3D to 2D

  14. 14

    Reshaping 3D Numpy Array to a 2D array

  15. 15

    Ortho projection of 3D points with a vector

  16. 16

    3D projection doesnt work

  17. 17

    3D projection to screen PHP

  18. 18

    Why use a Matrix for 3D Projection?

  19. 19

    Matplotlib separate 2D contour projection plots of 3D data

  20. 20

    python : 2D perspective projection of a 3D surface plot

  21. 21

    Analysis of a 3D point cloud by projection in a 2D surface

  22. 22

    3D to 2D projection using view frustum has issues with translation

  23. 23

    How to determine the projection (2D or 3D) of a matplotlib axes object?

  24. 24

    python : 2D perspective projection of a 3D surface plot

  25. 25

    Iterative non-linear-least-squares opimizing a 3d to 2d projection

  26. 26

    Fastest method to create 2D numpy array whose elements are in range

  27. 27

    python/numpy fastest method for 2d kernel rank filtering on masked arrays (and/or selective ranking)

  28. 28

    Numpy: Fastest way of computing diagonal for each row of a 2d array

  29. 29

    Fastest way to convert a list of indices to 2D numpy array of ones

HotTag

Archive