Home > database >  Can a 3D numpy array be converted into a 3D image in Python?
Can a 3D numpy array be converted into a 3D image in Python?

Time:03-22

I made the following virtual "room" in a 3D array and would like to visualize it. I can't find a way to do so, please assist. The idea is to see a "3D image" of the array as a plot where the different values have different colours or just greyscale intensities, so that you can see the "patient" and the "detector" inside the "room":

import numpy as np


# Diff. values in the Room define objects: 0 = walls, 1 = inside room, 2 = patient's tissue, 3 = bone, 4 = x-ray detector

Room = np.array([[[0.0 for i in range(0,101,1)] for j in range(0,101,1)] for k in range(0,101,1)]) #The entire room with walls

for i in range(1,100,1):
    for j in range(1,100,1):
        for k in range(1,100,1):
            Room[i,j,k]  =1     # The room not counting the walls

for i in range(30,70,1):
    for j in range(30,70,1):
        for k in range(30,70,1):
            Room[i,j,k]  =1      #The patient's body (tissue)
            
for i in range(50,55,1):
    for j in range(50,55,1):
        for k in range(50,55,1):
            Room[i,j,k]  =1      #The patient's bone #1 
            
for i in range(58,63,1):
    for j in range(58,63,1):
        for k in range(58,63,1):
            Room[i,j,k]  =1      #The patient's bone #2

for i in range(88,92,1):
    for j in range(10,90,1):
        for k in range(10,90,1):
            Room[i,j,k]  =1      # X-ray Detector

CodePudding user response:

Are you looking for a volume rendering approach? There's a broad range of Python libraries with that functionality available. This is an enter image description here

  • Related