Reputation: 1
I am trying to split 4 elements in 'xxx.mat' file and want to store each element into a separate list. In other words, I want (100,100) data and save into other list and then, I want to make image file (.bmp) by using that data (100,100).
xxx.mat file includes
type size
list 0
bytes 1
string 1
float64 (100,100)
I have tried
a = np.genfromtxt('xxx.mat', delimiter=',')
However, I have got the result as
[[nan nan ....... nan nan]
[nan nan ....... nan nan]
I tried to compare the data by using the following code (I have converted MAT-file to CSV file)
mat_contents = sio.loadmat('xxx.mat')
a= np.genfromtxt('xxx.csv', delimiter=',')
[[nan nan ....... nan nan]
[nan nan ....... nan nan]
Upvotes: 0
Views: 688
Reputation: 1308
I'll share with you the solution i came up with:
X = rand(100,100)
save("xxx.mat","X")
scipy.io
and this answer i loaded the .mat file into my python workspaceimport scipy.io
mat = scipy.io.loadmat('xxx.mat')
X = mat["X"]
PIL
library to convert the data to a black and white .bmpfrom PIL import Image
img = Image.fromarray(X, 'L')
img.save('my.bmp')
img.show()
Upvotes: 0