Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/python-2.7/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 2.7 将二进制图像重塑为一维向量Python_Python 2.7_Matlab_Image Processing_Vector_Cv2 - Fatal编程技术网

Python 2.7 将二进制图像重塑为一维向量Python

Python 2.7 将二进制图像重塑为一维向量Python,python-2.7,matlab,image-processing,vector,cv2,Python 2.7,Matlab,Image Processing,Vector,Cv2,我正在从事一个图像处理项目,我是Python的初学者。任何帮助都将不胜感激。我正在尝试将matlab代码转换为python。下面是我的matlab代码- file_name='play.png'; message=double(imread(file_name)); Mm=size(message,1); %Height Nm=size(message,2); %Width message_vecto

我正在从事一个图像处理项目,我是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)

下面是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)


我希望输出像我得到的matlab代码与1和0。我怎么能得到呢?我在python中犯了错误,因为python中的答案与Matlab中的答案不一样?

在重新格式化后,您没有规范化python中的值。更新
images\u rs=gray\u image.重塑([b,1])
images\u rs=gray\u image.重塑([b,1])/256。
应该会给出你想要的