0

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?

patra
  • 9
  • 4
  • 1
    It looks like your title has _nothing_ to do with your actual question. Please fix it. – ChrisGPT was on strike Apr 21 '17 at 20:20
  • what should I name it? I have problem with dimension of output array. help me by good title. @Chris – patra Apr 21 '17 at 20:21
  • Then maybe your question needs rewording… it looks like you really want to know "How can I extract images from a Matlab mlarray and display them?" That doesn't seem to have anything to do with array dimensions. – ChrisGPT was on strike Apr 21 '17 at 20:23

1 Answers1

0

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()
Community
  • 1
  • 1
patra
  • 9
  • 4