MATLAB Answers

how to convert an image into bits???

221 views (last 30 days)
user06 on 24 Feb 2015
Commented: Walter Roberson on 14 Mar 2017
how we can convert an image into bits ?? and that bits back to image?
user06 on 25 Feb 2015
actually i want to insert the image bits into different image. so i need to convert the image into binary bits..

Sign in to comment.

Answers (2)

Shoaibur Rahman
Shoaibur Rahman on 24 Feb 2015
It is not clear to me exactly what is your goal? Are you trying to convert image pixels into binary bits? If so, you can use dec2bin for that, and bin2dec to get your image back.
I_in = your image...
% encoding image into array of bits
B = dec2bin(I_in);
C = reshape(B',1,numel(B)); % converted into bits
% decoding image from bits
D = reshape(C,size(B,2),size(B,1));
I_out = reshape(bin2dec(D'),size(I_in))
Walter Roberson
Walter Roberson on 14 Mar 2017
524288 elements is 512 x 1024. If you were to display more than that many elements at the same time, you would be devoting an average of less than 2 pixels each to them. At that point you should be considering using imagesc() to display the array.
You cannot get around the 524288 limit; it is built-in to MATLAB. If you need to use the variable browser to look at part of the array, then extract a portion of the array that is no more than 512 x 1024 (or 1024 x 512) and assign it to a variable and view that variable.
Or just disp() the entire array.

Sign in to comment.

Image Analyst
Image Analyst on 24 Feb 2015
It's already in bits, as are all numbers in computers.
user06 on 26 Feb 2015
actually i m working on watermarking.and i need to process each and every pixel of image. and according to the pixel value (whether 0 or 1) i need to take appropriate action.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!