我正在尝试传输小 .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);
我在做什么错?
修补一点后,我找到了解决方法。问题是位深度。
这是正确的代码:
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)