automatic invisible watermarking of images

automatic invisible  watermarking of images using qrcode to embed the
information
This commit is contained in:
diptamath 2017-09-04 02:35:02 +05:30
parent 4c3e3a17ba
commit a3288051d7
6 changed files with 57 additions and 0 deletions

BIN
hello.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 910 KiB

BIN
hello_qrcode.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 441 B

BIN
hello_watermark.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.8 MiB

BIN
hello_watermark_1bit.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.1 KiB

31
invisible watermarking.py Normal file
View file

@ -0,0 +1,31 @@
from PIL import Image
from sys import argv
from qrcode import make as makeQR
if __name__ == '__main__':
qr = makeQR("hello sourya")
qw, qh = qr.size
im = Image.open("hello.jpg")
w, h = im.size
if qw > w:
qr = qr.resize((w, w))
elif qh > h:
qr = qr.resize((h, h))
qw, qh = qr.size
imd = im.load()
for i in range(w):
for j in range(h):
d = imd[i, j]
imd[i, j] = d[:-1] + ((d[-1] | 1) if qr.getpixel((i % qw, j % qh)) else (d[-1] & ~1),)
from os.path import splitext
root, ext = splitext("hello.jpg")
im.save(root + '_watermark.png')
qr.save(root+'_qrcode'+'.png')

26
retrive watermark.py Normal file
View file

@ -0,0 +1,26 @@
from PIL import Image
from sys import argv
from qrcode import make as makeQR
if __name__ == '__main__':
im = Image.open("hello_watermark.png")
s = w, h = im.size
imd = im.load()
oim = Image.new('1', s)
oimd = oim.load()
for i in range(w):
for j in range(h):
d = imd[i, j]
oimd[i, j] = 255 * (d[-1] & 1)
# oimd[i,j] = 255 * (d[-1]>>1 & 1)
# oimd[i,j] = 255 * (1 if d[-1] & 0b111 == 0b111 else 0)
from os.path import splitext
root, ext = splitext("hello_watermark.png")
fname = root + '_1bit' + ext
oim.save(fname)