Python 2.7 将二进制图像重塑为一维向量Python
我正在从事一个图像处理项目,我是Python的初学者。任何帮助都将不胜感激。我正在尝试将matlab代码转换为python。下面是我的matlab代码-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
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。
应该会给出你想要的