【发布时间】:2016-07-23 22:10:16
【问题描述】:
对于同一个矩阵,matplotlib和matlab中函数imshow()生成的图像是不同的。如何在matplotlib中改变imshow()的一些参数在matlab中可以得到相同的结果
%matlab
img = 255*rand(101);
img(:,1:50)=3;
img(:,52:101)=1;
img(:,51)=2;
trans_img=imtranslate(img,[3*cos(pi/3),3*sin(pi/3)]);
imshow(trans_img)
This is an image generated by matlab
#python
import numpy as np
import matplotlib.pyplot as plt
from mlab.releases import latest_release as mtl #call matlab function
img = 255 * np.random.uniform(0, 1, (101, 101))
img[:, 51:101] = 1
img[:, 0:50] = 3
img[:, 50] = 2
trans_img = mtl.imtranslate(img, [[3*math.cos(math.pi/3),3*math.sin(math.pi/3)]]
i = plt.imshow(trans_img, cmap=plt.cm.gray)
plt.show(i)
This is an image generated by matplotlib
两种情况下的trans_img矩阵是一样的,但是matlab和python中的图片不一样
【问题讨论】:
-
您需要更具体地了解您正在生成的图像以及两个版本之间的确切差异。
-
抱歉,我已经更新了我的代码的一些细节以使这个问题更具体。
标签: python matlab matplotlib