Problems displaying 3D images from .bmp files using python with mlab

I am trying to run a code to render 3d particle images using python and mlab. The images come up with what appears to be random noise in the background and I'm guessing my nested loops are part of the problem.

Here is an image of what I am talking about: http://imgur.com/0lPMozV

And here is the code I'm running:

import os
from scipy import misc
from PIL import Image
import numpy

path='/path/to/files/'
data=[]
listing=sorted(os.listdir(path))
for file in listing:
    if '.bmp' in file:
        fim=misc.imread(os.path.join(path, file), flatten=0)
        data.append(fim)


print "x: %s y: %s z: %s" %(len(data[0][0]),len(data[0]), len(data))

x=[]; y=[]; z=[]; xyz=[]
for k in range(len(data)-1):
    for m in range(len(data[k])-1):
        for n in range(len(data[k][m])-1):
            p=int(data[k][m][n])
            if p==1:
                x.append(n)
                y.append(m)
                z.append(k)

from mayavi import mlab
mlab.figure(size=(1200,900))
mlab.points3d(x,y,z,mode='cube',scale_mode='none',resolution=5,scale_factor=1)
mlab.show()

      

As for me, even when I run this code with only black images, it still outputs the output images. This makes me think that when reading .bmp files, it finds "white" pixels when there are none.

+3


source to share





All Articles