当前位置:网站首页>[200 opencv routines] 219 Add digital watermark (blind watermark)
[200 opencv routines] 219 Add digital watermark (blind watermark)
2022-07-05 09:50:00 【Xiaobai youcans】
OpenCV routine 200 piece General catalogue
【youcans Of OpenCV routine 200 piece 】219. Add a digital watermark ( Blind watermarking )
8.2 Add digital blind watermark
Digital watermark , It refers to embedding feature information into audio 、 In digital signals such as images or videos .
Digital watermarking is divided into clear watermarking and blind watermarking (blind watermark). The information contained in the watermark can be seen when watching an image or video . Blind watermarking is embedded in the image in the form of digital data , You can't see it under normal conditions , Watermark information can only be extracted after special processing . Blind watermark is also called hidden watermark , Information hiding can be realized 、 Copyright certification 、 Identity Authentication 、 Digital signature and other functions .
Least significant bit (Least significant bit) Blind watermarking , It is the most simple and convenient method to realize blind watermarking . The principle of this method is to save the digital watermark information as a binary image , Embedded into the lowest bit of the original image , Replace the least significant bit of the original image with the watermark image .
With 8 For example, a bit gray image , Pixels in the original image P The gray value of is determined by 8 Bit binary number ( p 7 , p 6 , . . . , p 1 , p 0 ) (p_7, p_6,...,p_1,p_0) (p7,p6,...,p1,p0) Express , The pixel value of the pixel in the binary watermark image is determined by 1 Bit binary number b 0 b_0 b0 Express . Use the pixel value of the watermark image b 0 b_0 b0 Replace the least significant bit of the original image p 0 p_0 p0, Get the embedded watermark 8 Bit binary number ( p 7 , p 6 , . . . , p 1 , b 0 ) (p_7, p_6,...,p_1,b_0) (p7,p6,...,p1,b0).
The process of extracting blind watermark is opposite to embedding watermark , From the original image embedded with watermark 8 Bit binary number ( p 7 , p 6 , . . . , p 1 , b 0 ) (p_7, p_6,...,p_1,b_0) (p7,p6,...,p1,b0) in , Separate least significant bits b 0 b_0 b0 Generate watermark image .
The process of extracting blind watermark , For the original image embedded with watermark , take 8 Bit binary number ( p 7 , p 6 , . . . , p 1 , b 0 ) (p_7, p_6,...,p_1,b_0) (p7,p6,...,p1,b0) The least significant position of zero .
routine A4.11: Add digital blind watermark to gray image
# A4.10 Embed digital blind watermark in gray image
img = cv.imread("../images/imgLena.tif", 0) # Load the original image , single channel
watermark = cv.imread("../images/logoCV.png", 0) # # Load watermark image , single channel
markResize = cv.resize(watermark, img.shape[:2]) # Adjust the picture size and img Same size
_, binary = cv.threshold(markResize, 175, 1, cv.THRESH_BINARY) # 0/1 Binary image
# Embed watermark into the original image
# img (g7,g6,...g1,0) AND 254(11111110) -> imgH7: (g7,g6,...g1,0)
imgH7 = cv.bitwise_and(img, 254) # Bitwise and operation , Image lowest order LSB=0
# imgH7: (g7,g6,...g1,0) OR b -> imgMark: (g7,g6,...g1,b)
imgMark = cv.bitwise_or(imgH7, binary) # (g7,g6,...g1,b)
# Extract the watermark from the embedded watermark image
# extract = np.mod(imgMark, 2) # Modular arithmetic , Take the lowest bit of the image LSB
extract = cv.bitwise_and(imgMark, 1) # Bitwise and operation , Take the lowest bit of the image LSB
plt.figure(figsize=(9, 6))
plt.subplot(221), plt.title("original gray"), plt.axis('off')
plt.imshow(img, cmap='gray')
plt.subplot(222), plt.title("watermark"), plt.axis('off')
plt.imshow(binary, cmap='gray')
plt.subplot(223), plt.title("embedding watermark"), plt.axis('off')
plt.imshow(imgMark, cmap='gray')
plt.subplot(224), plt.title("extracted watermark"), plt.axis('off')
plt.imshow(extract, cmap='gray')
plt.tight_layout()
plt.show()
routine A4.12: Embed digital blind watermarking with different contents in each channel of color image
Separate the channels of the color image , Digital watermarking with the same content can be embedded , Digital watermarks of different contents can also be embedded .
# A4.12 Embed digital blind watermarking with different contents in each channel of color image
img = cv.imread("../images/imgLena.tif", 1) # Load the original image , single channel
# Load or generate watermark information
watermark = cv.imread("../images/logoCV.png", 0) # # Load watermark image , single channel
markResize = cv.resize(watermark, img.shape[:2]) # Adjust the picture size and img Same size
_, binary = cv.threshold(markResize, 175, 1, cv.THRESH_BINARY) # 0/1 Binary image
mark1 = np.ones(img.shape[:2], np.uint8)
cv.putText(mark1, str(np.datetime64('today')), (50, 100), cv.FONT_HERSHEY_SIMPLEX, 2, 0, 2)
cv.putText(mark1, str(np.datetime64('now')), (50, 150), cv.FONT_HERSHEY_DUPLEX, 1, 0)
mark2 = np.ones(img.shape[:2], np.uint8)
cv.putText(mark2, "200 examples for OpenCV", (50, 300), cv.FONT_HERSHEY_SIMPLEX, 2, 0, 2)
cv.putText(mark2, "[email protected], 2022", (50, 350), cv.FONT_HERSHEY_DUPLEX, 1, 0)
# Embed watermark into the original image
# img: (g7,g6,...g1,0) -> imgH7: (g7,g6,...g1,0)
imgH7 = (img >> 1) << 1 # Move right -> Move left , Image lowest order LSB=0
# imgH7: (g7,g6,...g1,0) OR b -> imgMark: (g7,g6,...g1,b)
# Insert digital watermark into each channel respectively binary,mark1,mark2
b = cv.bitwise_or(imgH7[:, :, 0], binary) # (g7,g6,...g1,b)
g = cv.bitwise_or(imgH7[:, :, 1], mark1) # (g7,g6,...g1,m1)
r = cv.bitwise_or(imgH7[:, :, 2], mark2) # (g7,g6,...g1,m2)
imgMark = cv.merge([b, g, r])
# # Extract the watermark from the embedded watermark image
b, g, r = cv.split(imgMark) # Split into BGR Independent channel
bMark = cv.bitwise_and(b, 1) # Bitwise and operation , take B The lowest bit of the channel LSB
gMark = cv.bitwise_and(g, 1) # Bitwise and operation , take G The lowest bit of the channel LSB
rMark = cv.bitwise_and(r, 1) # Bitwise and operation , take R The lowest bit of the channel LSB
plt.figure(figsize=(9, 6))
plt.subplot(231), plt.title("original gray"), plt.axis('off')
plt.imshow(cv.cvtColor(img, cv.COLOR_BGR2RGB))
plt.subplot(232), plt.title("watermark"), plt.axis('off')
plt.imshow(binary, cmap='gray')
plt.subplot(233), plt.title("embedding watermark"), plt.axis('off')
plt.imshow(cv.cvtColor(imgMark, cv.COLOR_BGR2RGB))
plt.subplot(234), plt.title("watermark ch-B"), plt.axis('off')
plt.imshow(bMark, cmap='gray')
plt.subplot(235), plt.title("watermark ch-G"), plt.axis('off')
plt.imshow(gMark, cmap='gray')
plt.subplot(236), plt.title("watermark ch-R"), plt.axis('off')
plt.imshow(mark2, cmap='gray')
plt.show()
【 At the end of this section 】
Copyright notice :
[email protected] Original works , Reprint must be marked with the original link :(https://blog.csdn.net/youcans/article/details/125506913)
Copyright 2022 youcans, XUPT
Crated:2022-6-28
Welcome to your attention 『youcans Of OpenCV routine 200 piece 』 series , Ongoing update
Welcome to your attention 『youcans Of OpenCV Learning lessons 』 series , Ongoing update
210. There are so many holes in drawing a straight line ?
211. Draw vertical rectangle
212. Draw a slanted rectangle
213. Draw a circle
214. Detailed explanation of parameters for drawing ellipse
215. Draw approximate ellipses based on polylines
216. Draw polylines and polygons
217. Mouse interaction to obtain polygon area
218. Multi line oblique text watermark
219. Add digital blind watermark
边栏推荐
- La voie de l'évolution du système intelligent d'inspection et d'ordonnancement des petites procédures de Baidu
- From "chemist" to developer, from Oracle to tdengine, two important choices in my life
- 写入速度提升数十倍,TDengine 在拓斯达智能工厂解决方案上的应用
- TDengine 已经支持工业英特尔 边缘洞见软件包
- 盗版DALL·E成梗图之王?日产5万张图像,挤爆抱抱脸服务器,OpenAI勒令改名
- 百度智能小程序巡檢調度方案演進之路
- Common fault analysis and Countermeasures of using MySQL in go language
- Apache DolphinScheduler 入门(一篇就够了)
- 植物大战僵尸Scratch
- [ManageEngine] how to make good use of the report function of OpManager
猜你喜欢
百度智能小程序巡检调度方案演进之路
Vs code problem: the length of long lines can be configured through "editor.maxtokenizationlinelength"
Roll up, break 35 - year - old Anxiety, animation Demonstration CPU recording Function call Process
TDengine × Intel edge insight software package accelerates the digital transformation of traditional industries
SMT32H7系列DMA和DMAMUX的一点理解
【sourceTree配置SSH及使用】
干货整理!ERP在制造业的发展趋势如何,看这一篇就够了
H.265编码原理入门
Evolution of Baidu intelligent applet patrol scheduling scheme
How to improve the operation efficiency of intra city distribution
随机推荐
What about wechat mall? 5 tips to clear your mind
Why don't you recommend using products like mongodb to replace time series databases?
Roll up, break 35 - year - old Anxiety, animation Demonstration CPU recording Function call Process
Apache DolphinScheduler 系统架构设计
百度智能小程序巡检调度方案演进之路
【OpenCV 例程200篇】219. 添加数字水印(盲水印)
Tdengine can read and write through dataX, a data synchronization tool
Android 隐私沙盒开发者预览版 3: 隐私安全和个性化体验全都要
Nips2021 | new SOTA for node classification beyond graphcl, gnn+ comparative learning
Figure neural network + comparative learning, where to go next?
解决idea调试过程中liquibase – Waiting for changelog lock….导致数据库死锁问题
Principle and performance analysis of lepton lossless compression
Deep understanding of C language pointer
美图炒币半年亏了3个亿,华为被曝在俄罗斯扩招,AlphaGo的同类又刷爆一种棋,今日更多大新闻在此...
idea用debug调试出现com.intellij.rt.debugger.agent.CaptureAgent,导致无法进行调试
Wechat applet obtains household area information
代码语言的魅力
Tdengine connector goes online Google Data Studio app store
小程序启动性能优化实践
MySQL does not take effect in sorting string types