如何在MATLAB中将图像传输到位和后面

时间:2017-12-13 17:10:14

标签: image matlab

我正在尝试传输一个小的 .jpg 数字。我使用以下行将图片转换为位:

pic = imread('****.jpg');
x = reshape((dec2bin(typecast(pic(:),'uint8'),8)-'0').',1,[]);

然后,我正在尝试以下方法来重建图像:

n = 250;
m = 250;
s = num2cell(reshape(x,8,[])',2);
b = cellfun(@(x) bin2dec(strrep(num2str(x),' ','')), s);
out = reshape(b,n,m);  

我收到此错误消息:

Error using reshape
To RESHAPE the number of elements must not change.
Error in transmit_pic (line 13)
out = reshape(b,n,m);

我做错了什么?

1 个答案:

答案 0 :(得分:0)

经过一点点修补后,我找到了解决方法。问题是位深度。

这是正确的代码:

pic = imread('***.png');

x = reshape((dec2bin(pic,8)-'0').',1,[]);
[m, n] = size(pic);

s = num2cell(reshape(x,8,[])',2);
b = cellfun(@(x) bin2dec(strrep(num2str(x),' ','')), s);
out=reshape(b,m,n);  

image(out)