/*--------------------------------------------------------------------------
E_BLK_BLIND -- embed a block-based watermark by simply adding a
reference mark
This routine performs the following three basic steps:
1.Extract a mark from the unwatermarked image.
2.Choose a new mark that is close to the extracted mark and(hopefully)
within the detection region for the given reference mark.
3.Modify the image so that when a mark is extracted from it the
result will be (approximately) the new mark chosen above.
Step 2 is performed by blindly adding a fraction of the reference mark
to the extracted mark: newMark + alpha + refMark.
It should be pointed out that this routine could be greatly simplified,
in that step 3 involves adding a fraction of newMark - origMark to each
pixel of the image, and newMark - oriMark = alpha *refMark. This
means that steps 1 and 2 could be skipped, with step 3 using
alpha * refMark directly.
However, in later block-based embedding algorithms, step 2 will be
performed in more sophisticated ways, which do not allow such
simplification. The present routine is code with steps 1 and 2 in place
so that its relationship to these later routines is apparent.
Arguments:
c -- image to be watermarked (changed in place)
width -- width of image
height -- height of image
m -- 1-bit message to embed
alpha -- embedding strength
wr -- reference mark (length 64 vector of doubles)
Return value:
none
---------------------------------------------------------------------------*/
void E_BLK_BLIND( unsigned char *c, int width, int height,
int m, double alpha, double *wr )
{
double wm[ 64 ]; /*message mark*/
double vo[ 64 ]; /*mark extracted from image before modification*/
double vm[ 64 ]; /*new mark that is (hopefully) inside
the detection region around vm*/
/*Encode message in a pattern*/
ModulateOneBit( m, wr, wm, 64, 1 );
/*Embed*/
ExtractMark( c, width, height, vo );
MixBlind( vo, alpha, wm, vm );
InvExtractMark( c, width, height, vw );
}
/*-------------------------------------------------------------------------
D_BLK_CC -- detect block-based watermarks using normalized correlation
Arguments:
c -- image
width -- width of image
height -- height of image
tcc -- detection threshold
wr -- reference mark(8*8 array of doubles)
Return value:
decoded message(0 or 1), or NO_WMK if no watermark if found
--------------------------------------------------------------------------*/
int D_BLK_CC(unsigned char *c, int width, int height,
double tcc, double *wr)
{
double v[ 64 ]; /*mark extracted from image*/
double cc; /*correlation coefficient between wr and v*/
int m; /*decoded message(or NO_WMK)*/
/*Compute the correlation coefficient between wr and a mark extracted
from the image*/
ExtractMark( c, width, height, v );
cc = CorrCoef( v, wr );
/*Decode the message*/
if( cc > tcc )
m = 1;
else if( cc < -tcc)
m = 0;
else
m = NO_WMK;
return m;
}
/*--------------------------------------------------------------------------
ExtractMark -- extrat a mark vector from an image by dividing the image
into 8*8 blocks and their average.
Arguments:
c -- image from which to extrat mark
width -- width of image
height -- height of image
v -- where to store resulting 64-element vector
Return value:
none
---------------------------------------------------------------------------*/
void ExtractMark( unsigned char *c, int width, int height, double *v )
{
int imgX, imgY; /*coordinates in image*/
int imgI; /*index into c*/
int markX, markY; /*coordinates in averaged block*/
int markI; /*index into averaged block8*/
int n[ 64 ]; /*number of pixels accumulated into
each of the 64 elements of v*/
/*Initialize v and n to 0.*/
for( markI = 0; markI < 64; markI = markI + 1)
{
v[ markI ] = 0;
n[ markI ] = 0;
}
/*Accumalate pixels*/
for( imgY = 0; imgY < height; imgY = imgY + 1)
for( imgX = 0; imgX < width; imgX = imgX + 1)
{
/*Find index for this pixel in image.*/
imgI = imgY * width + imgX;
/*Find index for this pixel in accumulated block*/
markX = imgX % 8;
markY = imgY % 8;
markI = markY * 8 + markX;
/*Accumalate.*/
v[ markI ] = v[ markI ] + c[ imgI ];
n[ markI ] = n[ markI ] + 1;
}
/*Divide by n to obtain average of 8*8 blocks.*/
for( markI = 0; markI < 64; markI = markI + 1)
v[ markI ] = v[ markI ] / n[ markI ];
}
/*----------------------------------------------------------------------------
MixBlind -- use blind embedding to choose a new vector in mark space
that is close to a given extracted mark and (hopefully) inside
the detection region
Arguments:
vo -- mark extracted from original image
alpha -- embedding strength
wm -- message mark
vm -- where to store resulting vector
Return value:
none
----------------------------------------------------------------------------*/
void MixBlind( double *vo, double alpha, double *wm, double *vw)
{
int i;
for( i = 0; i < 64; i = i + 1)
vw[ i ] = vo[ i ] + alpha * wm[ i ];
}
/*----------------------------------------------------------------------------
InvExtractMark -- modify an image so that when entered into ExtractMark
it will produce(approximately) a given mark
In principle, for each pixel in the image,c,this function could simply let
c[ imgl] = c[ imgl ] + vw[ markl ] - vo[ markl ],
where imgl is the index of a pixel, markl is the corresponding index in
the extracted vector, vw is the desired new vector, and vo is the vector
obtained by applying ExtractMark to the original, unmodified image.
(Recall that each element of an extracted mark is the average of a set
of pixels.) Unfortunately, due to clipping and round-off errors, this
does not achieve the level of precision required for our experiments.
In other words, if we implement this with clipping and rounding, and
then enter the resulting image into ExtractMark, the vector we obtain is
not always close enough to vw.
To fix this problem, we use the following algorithm:
1.Initialize n[mark] to the number of pixels averaged together to obtain
the markl'th element of an extracted vector.
2.Initialize delta[markl] = n[markl](vw[markl]-vo[markl]) to the total
amount we want to add to the pixels that go into the markl'th element
of an extracted vector.
3.Loop through the pixels in the image. At the imgl'th pixel, perform
the following steps:
a.Let oldPixel = the original value of the pixel, c[imgl].
b.Compute newPixel = c[imgl] + delta[markl] / n[markl], where
markl is the index of the extracted vector element that
corresponds to imgl.
c.Set c[imgl] to the value of newPixel with clilpping and rounding.
Thus, c[imgl] will not be exactly equal to newPixel.
d.Decrement n[markl]. This is now the number of pixels remaining
in the set that are averaged for element markl.
e.Let delta[markl] = delta[markl] - (c[imgl] - oldPixel).
This is now the total amount to be added to the remaining
n[markl] pixels.
If no errors where introduced by clipping and rounding, this algorithm
would yield exactly the same results as the simpler method. However,
when an error is introduced, it will usually be corrected over subsequent
pixels. Thus, this represents a simple form of error diffusion.
Arguments:
c -- image to modify(changed in place)
width -- width of image
height -- height of image
vw -- new mark
Return value:
none
----------------------------------------------------------------------------*/
void InvExtractMark( unsigned char *c, int width,
i
没有合适的资源?快使用搜索试试~ 我知道了~
经典教程《Digital Watermarking and Steganography》的配套源码
共20个文件
c:10个
cpp:9个
rar:1个
需积分: 10 21 下载量 128 浏览量
2018-05-08
17:41:21
上传
评论 1
收藏 76KB RAR 举报
温馨提示
经典教程《Digital Watermarking and Steganography》的配套源码,对数字水印方向的学者来说绝对是个很好的学习资料,其中所包含的水印技术都是通用算法,适合图像,语音和视频等通用方向。电子版书籍见我的其他资源
资源推荐
资源详情
资源评论
收起资源包目录
数字水印书本源码(Source code for digital watermarking book).rar (20个子文件)
数字水印书本源码(Source code for digital watermarking book)
C3 E_BLK_BLIND & D_BLK_CC.c 13KB
C17 E_DCTQ & D_DCTQ.cpp 18KB
C13 E_PERC_GSGALE_D_LC.cpp 15KB
C2 E_FIXED_LC & D_LC.c 2KB
C10 E_LATTICE & D_LATTICE.c 13KB
C19 E_PXL & D_PXL.cpp 4KB
数字水印书本源码(Source code for digital watermarking book).rar 37KB
C7 E_BLK_FIXED_CC & D_BLK_CC.c 5KB
C14 E_PERC_SHAPE_LC.cpp 5KB
C18 E_SFSIG & D_SFSIG.cpp 7KB
C16 E_MOD & D_LC.cpp 937B
C11 E_BLIND_D_WHITE.cpp 6KB
C5 E_TRELLIS_8 & D_TRELLIS_8.c 8KB
C8 E_BLK_FIXED_R & D_BLK_CC.c 5KB
C6 E_BLK_8 & D_BLK_8.c 2KB
C9 E_DIRTY_PAPER & D_DIRTY_PAPER.c 5KB
C4 E_SIMPLE_8 & D_SIMPLE_8.c 7KB
C1 E_BLIND & D_LC.c 4KB
C12 E_BLK_BLIND_D_WHITE_BLK_CC.cpp 2KB
C15 E_PERC_OPT_D_LC.cpp 2KB
共 20 条
- 1
资源评论
qq_1196581964
- 粉丝: 44
- 资源: 15
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功