embedding a character in an image

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-02 07:31:10

Oh, nested loops... that's not the way to go.

You want to replace the least significant bits of the first l pixels with the binary ascii representation of your input string.


First thing that went wrong - converting char to binary:
Converting a character to its binary representation should be done using bitget

>> bitget( uint8('J'), 1:8 )
0    1    0    1    0    0    1    0

Gives back 1-by-8 binary array, while using dec2bin:

>> dec2bin( uint8('J'), 8 ) 
01001010

Gives back 1-by-8 string: the actual numeric values of this array are

>> uint8(dec2bin( uint8('J'), 8 ))
48   49   48   48   49   48   49   48

Can you appreciate the difference between the two methods?

If you insist on using dec2bin, consider

>> dec2bin( uint8('J'), 8 ) - '0'
0     1     0     0     1     0     1     0

Second point - nested loops:
Matlab favors vector/matrix vectorized operations rather than loops.

Here's a nice way of doing it without loops, assuming cover is a gray scale image (that is it has a single color channel rather than 3) of type uint8.

NoLsb = bitshift( bitshift( cover, -1 ), 1 ); %// use shift operation to set lsb to zero 
lsb = cover - NoLsb; %// get the lsb values of ALL pixels
lsb( 1:l ) = mbins; %// set lsb of first l pixels to bits of message
steg = NoLsb + lsb; %// this is it!
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!