I have saved a 3D matrix with coordinate (row = 288, col = 288, slice(z) =266) in Matlab.
Now I want to load it in Python. Unfortunately, after loading, it is as (row = 288, col = 266, slice(z) =288) in Python.
Given that, Matlab syntax for size: (rows, columns, slices in 3rd dimension) and Python syntax for size: (slices in 3rd dim, rows, columns).
For example, in the following code, when I want to viwe the variable A as an array it is as (row = 288, col = 266, slice(z) =288):
from math import sqrt
from skimage import data
import matplotlib.pyplot as plt
import cv2
import pydicom
import scipy.io as sio
import os
import numpy as np
for root, dirs, files in
os.walk('G:\PCodes\Other_Codes'):
matfiles = [_ for _ in files if _.endswith('.mat')]
for matfile in matfiles: # matfile: 'Final_Volume.mat'
Patient_All_Info = sio.loadmat(os.path.join(root, matfile)) # Patient_All_Info : {dict}
Patient_All_Info.items()
A = Patient_All_Info["Final_Volume"] # A: {ndarray} : (288, 266, 288) - it isn't as (row = 288, col = 288, slice(z) =266) coordinates.
S = np.shape(A) # S: <class 'tuple'>: (288, 288, 266) ?
dcm_image = pydicom.read_file('A')
image = dcm_image.pixel_array
plt.imshow(image, cmap='gray')
plt.show()
How to load a saved 3D matrix (Dicom Matrix) of Matlab in Python?
loadmat
returns might require some sort of transpose (axis swap). I'd have to experiment with small examples from Octave to demonstrate. – hpaulj