0

I want to plot 3D visualizations of DICOM Scans, but I am stuck on this error.

I am using the marching cubes method. First from mesh verts and faces and returned then passed into plt_3d. Modules imported:

import numpy as np

import pydicom as pyd

import os

import matplotlib.pyplot as plt

from glob import glob

from mpl_toolkits.mplot3d.art3d import Poly3DCollection

import scipy.ndimage

from skimage import morphology

from skimage import measure

from skimage.transform import resize

from sklearn.cluster import KMeans

from plotly import version

from plotly.offline import download_plotlyjs, init_notebook_mode, plot, iplot

from plotly.tools import FigureFactory as FF

from plotly.graph_objs import *

init_notebook_mode(connected=True)

imgs_after_resamp is the pixel array(3d) which contains the DICOM Data

def make_mesh(image, threshold=-300, step_size=1):
    p = image.transpose(2,1,0)
    verts, faces, norm, val = measure.marching_cubes_lewiner(p, threshold, 
step_size=step_size, allow_degenerate=True) 
    print(verts)
    return verts, faces
def plotly_3d(verts, faces):
    x,y,z = zip(*verts)
    fig = FF.create_trisurf(x=x,
                    y=y, 
                    z=z, 
                    plot_edges=False,
                    colormap=colormap,
                    simplices=faces,
                    backgroundcolor='rgb(64, 64, 64)',
                    title="Interactive Visualization")
    iplot(fig)
def plt_3d(verts, faces):

    print(“Drawing”)
    x,y,z = zip(*verts)
    fig = plt.figure(figsize=(10, 10))
    ax = fig.add_subplot(111, projection='3d')
    mesh = Poly3DCollection(verts[faces], linewidths=0.05, alpha=1)
    face_color = [1, 1, 0.9]
    mesh.set_facecolor(face_color)
    ax.add_collection3d(mesh)

    ax.set_xlim(0, max(x))
    ax.set_ylim(0, max(y))
    ax.set_zlim(0, max(z))
    ax.set_axis_bgcolor((0.7, 0.7, 0.7))
    plt.show()
v, f = make_mesh(imgs_after_resamp, 350)
new3d=np.vectorize(plt_3d)
new3d(v,f)

ValueError Traceback (most recent call last) in ----> 1 plot_ve(imgs_re,400)

TypeError: type object argument after * must be an iterable, not numpy.float32

H. Garg
  • 41
  • 4
  • Could you provide (a) the full traceback of the error, (b) full code including all imports, and (c) some sample data? I cannot immediately tell from looking at this code where the error is. – Juan Nov 04 '19 at 03:36
  • @Juan Can you please check now, if there is anything missing please let me know. – H. Garg Nov 04 '19 at 08:01
  • There is no `plot_ve` or `imgs_re` in your code, so that cannot be the full traceback. Where is the error happening *in your code*? You also did not provide sample data... – Juan Nov 05 '19 at 00:43
  • By "full traceback", I mean *all of the lines of the error message*, not just the last 1-2 lines. – Juan Nov 05 '19 at 00:43

0 Answers0