Convert image to a binary stream

3 次查看(过去 30 天)
I am working on error control in WMSNs. I want to transmit a video through binary symmetric channel with error probability P. So I have frames (images) in each GoP which are shown by a matrix.
Each matrix element have decimal value which might be positive or negative. As explained [here][1] I need to convert this whole matrix to a binary stream. I used
m = reshape(dec2bin(typecast(b(:),'uint8'),8).',1,[]);
for converting elements to binary streams but I cannot get back the exact number using
b_recovered = reshape(typecast(uint8(bin2dec(reshape(m,8,[]).')),'double'),size(b));
On the other side, for sending this matrix through binary symmetric channel, I have to convert the whole matrix to just one bit stream which I'm not sure how to do that. And convert them to a matrix of measured values of a image again.

回答(1 个)

GEEVARGHESE TITUS
GEEVARGHESE TITUS 2017-2-25
The following code will give the original values back
b=imread('coins.png');
m = reshape(dec2bin(typecast(b(:),'uint8'),8).',1,[])';
c2= reshape(str2num(m),8,[])';
c3=c2*(2.^(size(c2,2)-1 :-1:0))';
c4=uint8(reshape(c3,[size(b,1) size(b,2)]));
err=c4-b;% zeros indicating the values are same

产品

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by