0

I am trying to load an matlab image in .mat format in python using scipy. it give an error. However, when I load in matlab it shows me exactly what it looks like. How can I load the .mat image in python?

Traceback (most recent call last):

  File "<ipython-input-28-d42e90ca2d13>", line 1, in <module>
    mat_dict = loadmat('D:/Dataset/Multi-resolution_data/Visual/High/1/image100_256.mat');

  File "d:\python\python37\lib\site-packages\scipy\io\matlab\mio.py", line 217, in loadmat
    MR, _ = mat_reader_factory(f, **kwargs)

  File "d:\python\python37\lib\site-packages\scipy\io\matlab\mio.py", line 78, in mat_reader_factory
    raise NotImplementedError('Please use HDF reader for matlab v7.3 files')

NotImplementedError: Please use HDF reader for matlab v7.3 files```


```im= load('D:/Dataset/Multi-resolution_data/Visual/High/1/image100_256.mat')

output is 256x256x11```
Aadnan Farooq A
  • 626
  • 4
  • 8
  • 19
  • 2
    Possible duplicate of [reading v 7.3 mat file in python](https://stackoverflow.com/questions/17316880/reading-v-7-3-mat-file-in-python) – busybear Sep 04 '19 at 00:10
  • Thanks for that. I found one of the provided solution works for me. `import hdf5storage mat = hdf5storage.loadmat(file_path)` However, it comes in dictionary. How can I put the matrix in dictionary to variable? I tried couple of different ways img=mat.keys(). but didnt worked – Aadnan Farooq A Sep 04 '19 at 00:25
  • 1
    Seems like you could use some pointers on how [dictionaries work](https://docs.python.org/3/tutorial/datastructures.html#dictionaries) or am I misunderstanding your issue? Assuming not, you should be able to access your matrix with something like `mat[key_for_image]`. – busybear Sep 04 '19 at 00:30
  • worked with `array=mat['im1']` – Aadnan Farooq A Sep 04 '19 at 01:34

0 Answers0