实际上,我正在尝试用Python创建.png图像。数据来自Matlab文件。
这是我的密码。运行时出现错误:
回溯(最近一次呼叫):
“文件”从Matlab.py读取“,第20行,英寸
matriz[x][y][z]=数据[x][y][z]
索引器错误:列表索引超出范围
Matlab文件的数据是512x512x200双数组。在> {'__version__': '1.0', 'St3D': array([[[ -4.98510788e-02,
> -4.98139346e-02, -4.97636073e-02, ...,
> -5.19862428e-02, -5.20095813e-02, -5.20122990e-02],
> [ -4.98249255e-02, -4.97792210e-02, -4.97507640e-02, ...,
> -5.19832396e-02, -5.19884452e-02, -5.20089354e-02],
> [ -4.98121755e-02, -4.97751679e-02, -4.97488529e-02, ...,
> -5.19605824e-02, -5.19734534e-02, -5.20023879e-02],
> ...,
> [[ 9.10799464e-05, 1.75287655e-04, 2.26928715e-04, ...,
> 1.10619951e-04, 1.04038395e-04, 7.44506576e-05],
> [ 6.29097917e-05, 1.20765020e-04, 1.91577341e-04, ...,
> 8.24078623e-05, 8.96774520e-05, 7.44268856e-05],
> [ 4.14273859e-05, 7.96562916e-05, 1.20801256e-04, ...,
> 9.05750282e-05, 8.13201896e-05, 6.77554603e-05],
> ...,
> [ 1.72297366e-04, 1.68849830e-04, 2.21771692e-04, ...,
> 2.30046391e-04, 2.51247428e-04, 2.58021432e-04],
> [ 2.06350049e-04, 1.92126121e-04, 2.58923928e-04, ...,
> 2.48977658e-04, 2.78131275e-04, 2.76242136e-04],
> [ 2.42915268e-04, 2.47607632e-04, 2.89283796e-04, ...,
> 2.58819021e-04, 2.76203977e-04, 2.82977241e-04]]]), '__header__': 'MATLAB 5.0 MAT-file, Platform: PCWIN64, Created on: Fri
> Sep 19 17:03:17 2014', '__globals__': []}
#!/usr/bin/python
# -*- coding: utf-8 -*-
import pprint
import scipy.io
import numpy
from scipy import misc
from PIL import Image
# import file into a dictionary
fMatLab = scipy.io.loadmat('St3D', mat_dtype = True, squeeze_me = True, struct_as_record=False)
# read in the structure
data = fMatLab['St3D']
matriz = [[[0 for col in range(data.shape[0])] for row in range(data.shape[1])] for x in range(data.shape[2])]
for x in range(0,data.shape[0]):
for y in range(0,data.shape[1]):
for z in range(0,data.shape[2]):
matriz[x][y][z] = data[x][y][z]
for i in range(len(matriz)):
#im = numpy.random.random_integers(0, 255, 512*512).reshape((512, 512))
misc.imsave('transect_%s.png' % i, matriz[i])
from glob import glob
filelist = glob('transect*.png')
filelist.sort()