# how to convert an image in to binary bits sequence ??????

조회 수: 107(최근 30일)
user06 4 Mar 2015
댓글: user06 7 Mar 2015
b= round(a./256);
but i got binary bits like this
1 0 1 0 0 1 0 0 0 0
0 0 0 1 0 1 0 1 0 0
.
.
.
1 0 0 0 0 0 0 0 0 0
0 1 0 1 0 1 0 1 0 0
.
.
1 0 1 0 1 0
0 0 0 0 0 0
but what i want is: b = (1 0 1 0 1 0 0 0 .....n)

로그인 to comment.

### 채택된 답변

Guillaume 4 Mar 2015
You question is very unclear due to imprecise language.
Are you intending to binarise the image? That is convert each pixel to a single 0 or 1, as you've done with your b = round(a / 256), which convert all pixels below intensity 128 to 0 and all above 127 to 1. Or as your watermarking tag and question title suggest, convert each pixel to a sequence of bits?
If the latter, the best course is actually not to do it and use matlab's bit wise operators. This will be much faster than converting to a matrix of bits and back.
Example, replace LSB of matrix with random 0 or 1:
orig_image = imread('cameraman.tif'); %demo image shipped with matlab
lsb_replacement = uint8(randi([0 1], size(orig_matrix))); %random replacement
%set lsb to 0 (with AND 254) and replace with OR:
new_image = bitor(bitand(orig_matrix, 254), lsb_replacement);
imshowpair(orig_image, new_image, 'montage')
isequal(bitget(new_image, 1), lsb_replacement) %should return true

#### 댓글 수: 8

표시 이전 댓글 수: 5
user06 5 Mar 2015
it is not giving the correct o/p...
suppose i have a message like [1 1 1 0 0 0 0 1 1 1 1 0 0 1 1 0]
so i want o/p as[ 1 3 0 4 1 4 0 2 1 2 0 1]
Guillaume 5 Mar 2015
Hum:
>>runlengthencoding([1 1 1 0 0 0 0 1 1 1 1 0 0 1 1 0])
ans =
1 3 0 4 1 4 0 2 1 2 0 1
Works fine here.
Unless you've done the compression improvement that I mention in my 2nd comment, which of course gives a different result.
If you look at your output the odd elements are alternating 0 and 1, so you only need to know the first one. So [1 3 4 4 2 2 1] is more compact and encode exactly the same information.
user06 7 Mar 2015
thank u so much..:)

로그인 to comment.

### 추가 답변(0개)

이 질문에 답변하려면 로그인을(를) 수행하십시오.

Translated by