MATLAB: 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’.

lsb watermarking

%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

Best Answer

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.