reagvis commited on
Commit
d95dcda
·
verified ·
1 Parent(s): 69a429c

Upload water_marking.py

Browse files
Files changed (1) hide show
  1. water_marking.py +44 -0
water_marking.py ADDED
@@ -0,0 +1,44 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import cv2
2
+ import numpy as np
3
+ from pywt import dwt2, idwt2 # For DWT watermarking
4
+
5
+ # ---------- CONFIG ----------
6
+ victim_id_path = "new_cases/WhatsApp Image 2025-04-18 at 14.45.03.jpeg" # Victim's ID face
7
+ scammer_selfie_path = "new_cases/hardik_picture.jpg" # Scammer's face image
8
+ face_swapped_path = "new_cases/ChatGPT Image May 25, 2025, 10_52_19 AM.png" # Output of deepfake tool (SimSwap)
9
+ final_output_path = "new_cases/forged_with_watermark.jpg"
10
+
11
+ GPT_Key = "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"
12
+
13
+ def embed_watermark_dwt_color(host_image_path, watermark_image_path, alpha=0.3):
14
+ # Load and resize images
15
+ host = cv2.imread(host_image_path)
16
+ host = cv2.resize(host, (380, 507))
17
+ watermark = cv2.imread(watermark_image_path)
18
+ watermark = cv2.resize(watermark, (380, 507))
19
+
20
+ # Split into channels
21
+ host_channels = cv2.split(host)
22
+ wm_channels = cv2.split(watermark)
23
+
24
+ # Watermark each channel using DWT
25
+ watermarked_channels = []
26
+ for h_channel, wm_channel in zip(host_channels, wm_channels):
27
+ LL, (LH, HL, HH) = dwt2(h_channel, 'haar')
28
+ wLL, (wLH, wHL, wHH) = dwt2(wm_channel, 'haar')
29
+ wLH = cv2.resize(wLH, (LH.shape[1], LH.shape[0]))
30
+ LL_wm = 0.1 * (wHH) + 0.60 * LL + 0.40 * wLL
31
+ coeffs = (LL_wm, (wLH, wHL, wHH))
32
+ watermarked = idwt2(coeffs, 'haar')
33
+ watermarked_channels.append(np.clip(watermarked, 0, 255).astype(np.uint8))
34
+
35
+ # Merge channels back
36
+ watermarked_img = cv2.merge(watermarked_channels)
37
+ return watermarked_img
38
+
39
+ # Run the watermark embedding
40
+ watermarked_img = embed_watermark_dwt_color(face_swapped_path, victim_id_path)
41
+
42
+ # Save the output
43
+ cv2.imwrite(final_output_path, watermarked_img)
44
+ final_output_path