【问题标题】:Reshaping Binary images into 1D vector Python将二进制图像重塑为一维矢量 Python
【发布时间】:2018-10-19 05:24:18
【问题描述】:

我正在从事一个图像处理项目,我是 Python 的初学者。任何帮助将不胜感激。我正在尝试将 matlab 代码转换为 python。下面是我的 matlab 代码-

file_name='play.png';
message=double(imread(file_name));
Mm=size(message,1);                         %Height
Nm=size(message,2);                         %Width
message_vector=round(reshape(message,1200,1)./256);
disp(message_vector)

Output of matlab code

下面是python代码

water = cv2.imread('sam.png')
gray_image = cv2.cvtColor(water, cv2.COLOR_BGR2GRAY)
file_name=im2double(gray_image)
a=np.shape(gray_image)
b=a[0]*a[1]#getting resolution
images_rs = gray_image.reshape([b, 1])#reshaping array into 1D vector
print(images_rs)

Output of python

我想要输出像我得到的带有 1 和 0 的 matlab 代码的输出。我怎样才能得到它?我在 python 中犯了错误,因为 python 中的答案与 Matlab 不同?

【问题讨论】:

    标签: python-2.7 matlab image-processing vector cv2


    【解决方案1】:

    你没有在重塑后规范化 python 中的值。将 images_rs = gray_image.reshape([b, 1]) 更新为 images_rs = gray_image.reshape([b, 1])/256. 应该可以满足您的需求。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2023-02-19
      • 2017-09-12
      • 2020-07-06
      • 1970-01-01
      • 2019-03-14
      • 1970-01-01
      • 2020-03-01
      相关资源
      最近更新 更多