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
python mayavi


source to share


No one has answered this question yet

Check out similar questions:

2112
How do I copy a file in Python?
1675
Why is reading lines from stdin much slower in C ++ than Python?
1470
How do I remove a key from a Python dictionary?
1414
How do you add a file in Python?
1349
Why can't Python parse this JSON data?
1315
How do I remove an item from a list by index?
1139
Extracting extension from filename in Python
1130
Importing files from different folders
1043
Find all files in directory with .txt extension in Python
989
If Python is interpreted, what are .pyc files?



All Articles
Loading...
X
Show
Funny
Dev
Pics