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'.

%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

 Accepted 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.

3 Comments

thank you sir..But i have another problem..I write another code in similar way with some changes.watermark is also generated as 4*4 matrix given=>[1 0 0 0;1 0 0 0;1 0 0 0;1 0 0 0],now when i am embedding this watermark into lsb then each lsb should replace by watermark bit available at that position.bt i am not getting that.so i am now confused about bitset(a,1,v )function.can you please help me.here is part of my code.
clc;
a=[20 15 14 16;10 5 7 8;12 8 5 3; 9 6 7 5]
b=dec2bin(a,8)
b=double(a)
b=uint8(a)
c=size(b,1)
d=size(b,2)
text='AB'
char_in_bit=uint8(text)
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
watermark=uint8(watermark)
g=size(watermark)
watermarked_image=b
%watermarked_image=double(watermarked_image)
%watermarked_image=uint8(watermarked_image)
for ii = 1:c
for jj = 1:d
watermarked_image(ii,jj)=bitset(watermarked_image(ii,jj),1,watermark(ii,jj));
end
end
display(watermarked_image)
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()
Umila commented
Thank you so much sir for your kind help...i got the answer.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!