I am attempting to run a code to render 3d images of particles using python and mlab. The images are coming up with what seems to be random noise in the background, and I'm assuming that my nested loops are part of the issue.
Here is an image of what I'm talking about: http://imgur.com/0lPMozV
And here is the code that 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()
What concerns me is even when I run this code with only black images it still gives output images. This makes me think that while reading the .bmp files it is finding "white" pixels when there are none.