Extract and embed data bits into image using matlab
2 次查看(过去 30 天)
显示 更早的评论
I got a question want to raise up here. My problem is I want to embed the 2 LSB from each of the character into 2 * 2 matrix and continuous embed until the data is successfully being embed all. But now I cant make it. Your help is really appreciated. Here is my part of the code.
fid = fopen('test.txt'); %open the text file
readText = fread(fid);
fclose(fid); %close the file function
char_in_bit = uint8(readText);
ascii_binary = dec2bin(char_in_bit,7);
size_char = size(char_in_bit); %determine the length of the text file
display(char_in_bit);
display(size_char);
display(BlockRONI);
display(ascii_binary);
for a=1 : size(ascii_binary,1)
for b=1:6
if blocksize==2
n=1;
for r=1:2
for c=1:2
block(r,c)=bitset(block(r,c),1,char_in_bit(n));
n=n+1;
block(r,c)=bitset(block(r,c),2,char_in_bit(n));
%display(block(r,c));
end
end
end
end
block(r,c) = bitset(block(r,c), 7, char_in_bit(n));
end
watermarked_image(y2:y2+blocksize-1, x2:x2+blocksize-1)=block;
watermarked_image_int=uint8(watermarked_image);
imwrite(watermarked_image_int,'watermarked.jpg');
The below data is my input from test.txt file 1010111 1101001 1101100 1101100 1101001 1100001 1101101 and my image that i want embed is gray-scale 8 bit image.
Kindly give me suggestion and appreciate your help
4 个评论
回答(1 个)
Image Analyst
2012-12-26
Why is this line:
block(r,c) = bitset(block(r,c), 7, char_in_bit(n));
outside of your loops over r and c, and even outside of your b loop? Do you know what r and c are then? They're 2, so you're always setting block(2,2).
And what ia A and why should it be all 1's? In your code, what variable take on this/these value(s): "010111 1101001 1101100 1101100 1101001 1100001 1101101 "? Is that char_in_bit? Is it the whole string or just 8 0 and 1 at a time? And what about that sequence of binary numbers means that A should be all 1's?
But my main question is: are you using the debugger to help yourself? Are you stepping through code and examining variables as you go?
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!