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
0 个评论
采纳的回答
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
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
2013-12-27
Umila commented
Thank you so much sir for your kind help...i got the answer.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Logical 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!