필터 지우기
필터 지우기

I have 4*4 known matrix.i m converting it into binary and i want to embed text 'abc' into that. i am also converting it into binary.but i am getting error:Undefined function or method 'bitset' for input arguments of type 'char'.

조회 수: 1 (최근 30일)
%here is my code..what wrong i am doing?
clc;
a=[1:4;5:8;9:12;13:16]
b=dec2bin(a,8)
c=size(b,1)
d=size(b,2)
text='abc'
binarytext=dec2bin(text,8)
e=size(binarytext,1)
f=size(binarytext,2)
for ii = 1:c
for jj = 1:d
watermark(ii,jj)=binarytext(mod(ii,e)+1,mod(jj,f)+1)
end
end
g=size(watermark)
watermarked_image=b
for ii = 1:c
for jj = 1:d
watermarked_image(ii,jj)=bitset(watermarked_image(ii,jj),1,1)
end
end

채택된 답변

Walter Roberson
Walter Roberson 2013년 9월 17일
What you are doing wrong is forgetting that the output of dec2bin() is an array of characters. '0' and '1' rather than 0 and 1. You are trying to bitset() on the character that is representing a single bit, not on a multi-bit pixel. If, though, you think that you really do want to set the lower bit on the '0' or '1' that is representing a single bit, then why not just instead assign '1' to all of those positions?
watermarked_image(1:c,1:d) = '1';
Perhaps somewhere along the line you wanted to convert back from the binary representation to the numeric representation?
By the way, if you examine your code, you need to figure out why you bother to calculate "watermark" or "g", since you do not use those.
  댓글 수: 3
Walter Roberson
Walter Roberson 2013년 9월 18일
Remember, the output from dec2bin is characters, '0' and '1'. When you uint8() those, you get the small integers 48 and 49. Then you try to use the 48 and 49 as being the bit values that are the source for bitset(), but the bit values need to be 0 or 1 (decimal) to succeed.
You would find it more clear if you do not use dec2bin() by itself, and instead use de2bi (if you have the appropriate toolbox) or use
dec2bin(text, 8) - '0'
which will convert the '0' and '1' characters to 0 and 1 decimal.
Once you are working with decimal values, remember to add the '0' back in before using bin2dec()
Azzi Abdelmalek
Azzi Abdelmalek 2013년 12월 27일
Umila commented
Thank you so much sir for your kind help...i got the answer.

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

추가 답변 (0개)

Community Treasure Hunt

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

Start Hunting!

Translated by