1

Reading cv::Mat from Matlab's .mat in python get different results compared to Matlab , as follow

import scipy.io as sio  
import numpy as np
data = sio.loadmat('image.mat')
img = data['img']
cv2.imshow('img', img)

the image as follows:

the result using python to read mat

but in matlab:

image = load('image.mat')
imshow(image.img)

the result as follow:

enter image description here

it seems that the python has wrong with parseing the matrix.

shizhz
  • 11,715
  • 3
  • 39
  • 49
Rhapsody
  • 77
  • 1
  • 5

1 Answers1

2

The issue is with default color conventions of Matlab and OpenCV, OpenCV uses BGR color convention instead of RGB color space, So in order to get your image displayed properly you need to swap the B and R channels, There are multiple ways to do this, as per OpenCV it can be done as:

img = cv2.cvtColor(img, cv2.COLOR_RGB2BGR) 
ZdaR
  • 22,343
  • 7
  • 66
  • 87