Spaces:
Sleeping
Sleeping
Update utils.py
Browse files
utils.py
CHANGED
@@ -94,8 +94,12 @@ class WatermarkProcessor:
|
|
94 |
for j in range(image.shape[1]):
|
95 |
for k in range(3):
|
96 |
if data_index < len(binary_secret):
|
97 |
-
#
|
98 |
-
|
|
|
|
|
|
|
|
|
99 |
data_index += 1
|
100 |
else:
|
101 |
break
|
@@ -115,6 +119,14 @@ class WatermarkProcessor:
|
|
115 |
def decode(self, image_path):
|
116 |
"""Decode watermark using simple LSB steganography"""
|
117 |
try:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
118 |
image = cv2.imread(image_path)
|
119 |
if image is None:
|
120 |
raise ValueError("Could not read image file")
|
|
|
94 |
for j in range(image.shape[1]):
|
95 |
for k in range(3):
|
96 |
if data_index < len(binary_secret):
|
97 |
+
# Get current pixel value
|
98 |
+
pixel = image[i, j, k]
|
99 |
+
# Clear the LSB by setting it to 0 and add the watermark bit
|
100 |
+
pixel = (pixel & 0xFE) | (int(binary_secret[data_index]) & 0x01)
|
101 |
+
# Ensure value stays within uint8 range
|
102 |
+
image[i, j, k] = np.uint8(pixel)
|
103 |
data_index += 1
|
104 |
else:
|
105 |
break
|
|
|
119 |
def decode(self, image_path):
|
120 |
"""Decode watermark using simple LSB steganography"""
|
121 |
try:
|
122 |
+
# Try PNG metadata method first
|
123 |
+
try:
|
124 |
+
im = Image.open(image_path)
|
125 |
+
if "TXT" in im.info:
|
126 |
+
return im.info["TXT"]
|
127 |
+
except:
|
128 |
+
pass
|
129 |
+
|
130 |
image = cv2.imread(image_path)
|
131 |
if image is None:
|
132 |
raise ValueError("Could not read image file")
|