简体   繁体   中英

How can I extract images from a Matlab mlarray and display them

In Python, I have an array comes from Matlab function using Matlab engine.

import matlab.engine
import numpy as N
eng = matlab.engine.start_matlab()
a= eng.func()
print(type(a))
print(N.shape(a))

the console output is :

 <class 'matlab.mlarray.double'>
  (135L, 134L, 7L)

in which there is 7 gray images with size of 135x134. how can I extract each image and show them by loop?

I solved it according to last nice answer in How to efficiently convert Matlab engine arrays to numpy ndarray?

b = N.array(a._data).reshape(a.size, order='F')  

it change 'a' to Numpy. and then I call each image simply.

for i in range(0, 6):
  c = b[:,:,i] #now c is 135x134 
  plt.imshow(c)
  plt.show()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM