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 Ansicht (letzte 30 Tage)
%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

Akzeptierte Antwort

Walter Roberson
Walter Roberson am 17 Sep. 2013
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 Kommentare
Walter Roberson
Walter Roberson am 18 Sep. 2013
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 am 27 Dez. 2013
Umila commented
Thank you so much sir for your kind help...i got the answer.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Community Treasure Hunt

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

Start Hunting!

Translated by