how to convert an image into bits???

how we can convert an image into bits ?? and that bits back to image?

댓글 수: 2

Star Strider
Star Strider 2015년 2월 24일
A relatively simple solution (since what you want is quite definitely not obvious) is to scan it, then print the scanned image.
user06
user06 2015년 2월 25일
actually i want to insert the image bits into different image. so i need to convert the image into binary bits..

댓글을 달려면 로그인하십시오.

답변 (5개)

Shoaibur Rahman
Shoaibur Rahman 2015년 2월 24일

2 개 추천

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))

댓글 수: 16

user06
user06 2015년 2월 25일
편집: user06 2015년 2월 25일
this code is not giving the output image as the input image. input and output images i m attaching. and yes i m trying to convert image pixels into binary bits.
Shoaibur Rahman
Shoaibur Rahman 2015년 2월 25일
편집: Shoaibur Rahman 2015년 2월 25일
I_out in my code is double type. So, when plotting as an image using imshow, convert that first into uint8, and that will give you a perfect reconstruction. Hope this helps.
I_in = imread('input_image.jpg'); % image that you attached
% 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));
subplot(121), imshow(I_in), title('Input Image')
subplot(122), imshow(uint8(I_out)), title('Reconstracted Image')
Guillaume
Guillaume 2015년 2월 25일
I completely fail to see the utility of converting an image into a string of '0' and '1' characters. What useful processing can you do afterward, that wouldn't be obtained much faster by not bothering with the string conversion?
If you want to perform bit operations, there are matlab functions that operate on bits without any transformation of the original data.
user06
user06 2015년 2월 26일
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.
Guillaume
Guillaume 2015년 2월 26일
A simple search through the forum for steganography would have shown you that this question is asked and answered at least once a week.
alex rod
alex rod 2015년 12월 31일
편집: alex rod 2015년 12월 31일
You can recover the image adding this at the end of the code, also I found very useful converting an image to bits (I'm working on a simulation of a convolutional channel encoding and Viterbi decoding) an this helped me a lot thanks ;)
imwrite(uint8(I_out),'path of your new image')
prathap velugoti
prathap velugoti 2016년 4월 6일
in the decoding i get just get a white image as out put
Image Analyst
Image Analyst 2016년 4월 6일
Then you did something wrong, either on computing the image, or displaying it. That's all I can say with what you've given us.
Sanjeev Tyagi
Sanjeev Tyagi 2017년 3월 14일
편집: Walter Roberson 2017년 3월 14일
B: Cannot display variables with more than 524288 elements.
C: is displaying the binary stream
D: Cannot display variables with more than 524288 elements.
I: is working
I_out: working
Dear Shoaibur Rahman, Ur code is usefull for me.
My purpose is search the Binary-pattern into binary stream of color image, then I want to implement the concept of Steganography for my research.
Please please provide me the code to search the binary-pattern into file of binary-stream of Colored image,
Please help me, how to solve given problem
B: Cannot display variables with more than 524288 elements.
D: Cannot display variables with more than 524288 elements.
Sanjeev Tyagi
Sanjeev Tyagi 2017년 3월 14일
편집: Walter Roberson 2017년 3월 14일
In MATLAB variables values are not displayed of following variables
B: Cannot display variables with more than 524288 elements.
C: is displaying the binary stream
D: Cannot display variables with more than 524288 elements
so Binary stream could not be displayed, please help me
Walter Roberson
Walter Roberson 2017년 3월 14일
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.
Winda Mariana
Winda Mariana 2021년 6월 30일
how to convert the image into a bit sequence according to the size of the image?
Winda Mariana
Winda Mariana 2021년 6월 30일
the image has a size of 7x7 pixels, so i want to convert the image into bit like this. How can i do it, sir?
0 0 0 0 0 0 0
0 0 0 0 0 0 0
0 0 0 1 1 0 0
0 0 0 0 0 0 0
0 0 0 0 0 0 0
0 0 1 0 1 0 0
0 0 1 0 1 0 0
filename = 'flamingos.jpg';
img = imread(filename);
if ndims(img) > 2
img = rgb2gray(img);
end
img = imresize(img, [7 7]);
%img is now 7 x 7 grayscale
BW = imbinarize(img);
as_bits = double(BW)
as_bits = 7×7
0 0 1 0 0 0 0 0 0 0 1 0 0 0 0 1 1 1 1 0 0 0 0 0 1 1 0 0 0 0 0 1 1 0 0 1 1 1 1 1 1 0 0 1 1 1 1 1 1
dung nguyen
dung nguyen 2021년 11월 25일
@Walter Roberson the image has a size of 1920x2560 , i want to convert the image into bit , How can i do , thanks you
Walter Roberson
Walter Roberson 2021년 11월 25일
https://www.mathworks.com/matlabcentral/answers/180075-how-to-convert-an-image-into-bits#answer_169133 shows how.

댓글을 달려면 로그인하십시오.

Image Analyst
Image Analyst 2015년 2월 24일

0 개 추천

It's already in bits, as are all numbers in computers.

댓글 수: 7

user06
user06 2015년 2월 24일
then how to extract it?
Image Analyst
Image Analyst 2015년 2월 24일
We don't know what you want. The image is already a variable in your program that you got from imread() presumably. Do you want to turn a gray level into a 1's and 0's string of 8 bits for each number? If so, why? But if so, you can use code given by Shoaibur. If not then you need to explain what you want to do? Are you using local binary patterns for image processing or what? You seem to be a person of very very few words, and this does not help us to answer your question.
user06
user06 2015년 2월 25일
actually i want to insert the image bits into different image. so i need to convert the image into binary bits..
Image Analyst
Image Analyst 2015년 2월 25일
See my attached demo for copying and pasting an image or portion of an image that you specify into a bigger image.
Image Analyst
Image Analyst 2015년 2월 25일
Please describe what you want. No one can figure it out. I just gave you code to do copying and pasting. Is that what "insert the image bits into different image" means? Who knows? Only you. Or perhaps you mean watermarking or steganography, though you didn't add any tag for those concepts so I have my doubts. But your imprecise language leaves them as possibilities. Will you clear up exactly what you want? I have a demo for LSB Steganography if that's what you want, but I have hundreds of demos and I can't post them all, so let me know if you're working on steganography.
user06
user06 2015년 2월 26일
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.
Image Analyst
Image Analyst 2021년 6월 30일
"actually i m working on watermarking"
See my atttached demo on Least significant bit watermarking.

댓글을 달려면 로그인하십시오.

Image Analyst
Image Analyst 2021년 11월 25일

0 개 추천

If you want to view bitplanes 0 through 7, as binary images, see my attached demo.
Andy Paulo Ureña
Andy Paulo Ureña 2022년 1월 18일

0 개 추천

Hello there! I hope you can help me with this question... I'm simulating a Digital Comm System, so i want to transmit an image and for that i converted that image into a bitstream, i used "imbinarize" function and reshape the matrix into a row vector for the "transmission" which function should i use to make the opposite process for the recosntruction of the image? Thanks!
Walter Roberson
Walter Roberson 2022년 1월 18일

0 개 추천

reshape() to reconstruct the image. The remote side will need to know the image size, so either the size will need to be fixed or else you will need to transmit size information.
Note that your process will end up with a black and white image. If you want grey or color then you will need to use something different than imbinarize

카테고리

도움말 센터File Exchange에서 Convert Image Type에 대해 자세히 알아보기

질문:

2015년 2월 24일

답변:

2022년 1월 18일

Community Treasure Hunt

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

Start Hunting!

Translated by