0

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]
Cris Luengo
  • 55,762
  • 10
  • 62
  • 120
  • What's a `matfile` please? I think you have omitted a significant tag. What is `sio.loadmat()` please? I think you need to be clearer what you are talking about and what you are trying to do. Thank you. – Mark Setchell Jul 08 '19 at 08:00

1 Answers1

0

I'll share with you the solution i came up with:

  1. I created a .mat file from random data in matlab and saved it.
X = rand(100,100)
save("xxx.mat","X")
  1. Using scipy.ioand this answer i loaded the .mat file into my python workspace
import scipy.io

mat = scipy.io.loadmat('xxx.mat')
X = mat["X"]
  1. Using the PILlibrary to convert the data to a black and white .bmp
from PIL import Image

img = Image.fromarray(X, 'L')
img.save('my.bmp')
img.show()

enter image description here

Sebastian Dengler
  • 1,258
  • 13
  • 30