We're a community of 1077K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,076,382 Members — Technology Publication meets Social Media

# Discrete Cosine Transform (DCT) Formula for embedding watermarks

Hello everyone and good day!!!

I'm trying to embedd an image watermark to another image for copyright protection and I plan to use DCT and embedding the watermark in the middle band coefficeint of the host image. The problem is I don't know which of the formulas to use since there are a lot of them when I google DCT. I get confuse on which is which?

Base from what I read so far
1. the image is divided into 8x8 sub-blocks
2. then DCT is applied to each of the sub-blocks. I'm stuck here what happens next?

I'm using OpenCV and c++ to implement this.

Can anyone help me with my problem?

Thanks!!!

2
Contributors
3
Replies
3 Days
Discussion Span
1 Year Ago
Last Updated
4
Views
sandz24
Newbie Poster
21 posts since Jan 2012
Reputation Points: 10
Skill Endorsements: 0

Base from what I read so far
1. the image is divided into 8x8 sub-blocks
2. then DCT is applied to each of the sub-blocks. I'm stuck here what happens next?

What happens next is specific to the image-file-format. For instance, for lossy compression in the JPEG format, the resulting DCT values are quantized in some way (each is adjusted to fall onto one of a small fixed set of values, and presumably values sufficiently close to zero are thrown out completely). Once quantization has occurred, the original pixel values can no longer be exactly recovered, thus the "lossy" nature of the compression. On the flip side, for most natural photographs, 90% compression still results in an acceptable reconstructed image.

For your purposes, you need to determine:
1. which are the "middle band coefficients" (note that coefficients are 2D in nature, there isn't just one middle-band coefficient)
2. how to modify those values to include your watermark
3. how to determine, for your use-case of copyright protection, whether a given image contains your watermark.

raptr_dflo
Practically a Master Poster
605 posts since Aug 2010
Reputation Points: 76
Skill Endorsements: 1

I will be using bmp for the host image and I'm still thinking if I will use gray scale image or binary for the watermark. Is the process the same as JPEG?

And what do you mean by "note that coefficients are 2D in nature, there isn't just one middle-band coefficient". Does that mean that I really have to use 2D to transform them to their coefficients?

Thanks :)

sandz24
Newbie Poster
21 posts since Jan 2012
Reputation Points: 10
Skill Endorsements: 0

I'm not overly-familiar with the .bmp image format, but I suspect that any compression used is lossless, since I use it all the time to make stupid little 100x100 image-tiles with just a couple of colors, and they always look good. (Try making a small image with solid-color areas using just a few colors, for example in Microsoft MSPaint, and save it as a JPEG, then view the results -- note the artifacts introduced into various 8x8 blocks of pixels.)

As far as DCT, there's nothing special about 8x8 regions, except that that's how the JPEG image file format is defined. The DCT is converting data from amplitude-per-pixel-location (spatial/temporal domain) to amplitude-per-frequency (frequency domain). Since your data starts out as 2D (pixels in an image), the DCT is also 2D, meaning each value corresponds to a pair of frequencies, one in each direction. One of the values, probably at (0,0), corresponds to the information with no frequency contribution in either direction -- the mean of all values in the region. Other values in the same row/column correspond to other frequencies which exist in only one direction. Remaining values correspond to products of frequencies in each direction. See wikipedia for more insight.

As far as watermarking an image, you need to apply the DCT to get to the frequency-domain (in 8x8 pixel chunks, if you so desire), add your watermarking wherever you want, then apply the inverse DCT to get back to the spatial-domain. Now you have a modified version of your original image, where if you apply the DCT again, your watermark should be right where you left it. Determining how to modify the frequency-domain values, to apply your watermark, so that you can detect whether an image is yours or not, is up to you.

While somewhat off the immediate topic, note that (1) a sufficiently-lossy image compression, (2) crop operation or (3) resize operation will probably destroy your ability to detect your DCT-based watermark. In the first case, there's a potential that the original pixel values will be disrupted badly enough that the DCT will not give values sufficiently-close to the original ones (after you applied your watermark). Cropping the left-most column of pixels off the image (for example) shifts which pixels are considered in each 8x8 block. Resizing the image changes how much of the picture ends up in each 8x8 block (and usually blurs the original pixel values). Being able to determine algorithmically that an image is in some sense "the same" as an original is a non-trivial problem! :)

raptr_dflo
Practically a Master Poster
605 posts since Aug 2010
Reputation Points: 76
Skill Endorsements: 1

Post: Markdown Syntax: Formatting Help

You
View similar articles that have also been tagged: