实际上我正在尝试用Python创建.png图像。数据来自Matlab文件。 代码解决方案在问题上提出:
Create .PNG images in Python from MatLab data
代码有效但我正在尝试拥有更高质量的图像并优化创建图像的过程。您知道如何获得质量更快的解决方案吗?我使用img = scipy.misc.toimage(data[:,:,i], mode='I')
测试代码,但图像是完全黑色的。对于优化我不知道。谢谢
代码在这里:
!/usr/bin/python
# -*- coding: utf-8 -*-
import scipy.io
import pylab as pl
import numpy as np
from scipy import misc
from glob import glob
# 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']
for i in range(data.shape[2]):
misc.imsave('image_%s.png' % i, data[:,:,i] )
编辑:这对我有用
def saveImages(data, fileName):
img = scipy.misc.toimage(data, low=0, high=255, mode='P')
img.save(fileName)
return img
imP = saveImages(data[i,:,:], 'image_%s.png' % i)