This project implements an invisible text watermarking scheme based on a border-hash method. It allows embedding text messages into images and later extracting them.
src/
- Contains the source code filesexamples/
- Contains example images for testing
-
Border Extraction & Hashing: The outermost 1-pixel-wide border of the image is used to compute a SHA-256 hash.
-
Pseudo-Random Pixel Selection: The hash is used as a seed for a pseudo-random number generator to create a reproducible sequence of interior pixel positions.
-
Message Encoding: The user's text message is converted to bits using UTF-8 encoding, and a 16-bit header containing the message length is prepended.
-
Watermark Embedding: The bits are embedded into the least significant bit (LSB) of the blue channel of the selected interior pixels.
-
The same border hash is recomputed from the watermarked image.
-
The same pseudo-random sequence of pixel positions is generated.
-
The first 16 bits are extracted to determine the message length.
-
The remaining bits are extracted and converted back to text.
-
Clone this repository:
git clone https://github.com/prtmsh/steganography-py.git cd steganography-py
-
Install the required dependencies:
pip install -r requirements.txt
python src/main.py --mode embed --input examples/input.jpg --output examples/watermarked.png --message "Your secret message"
Note: We strongly recommend using PNG format for the output file to ensure watermark integrity. The program will automatically convert the output to PNG format if another format is specified.
python src/main.py --mode extract --input examples/watermarked.png
- Python 3
- OpenCV
- NumPy
- Pillow
- The image must be large enough to accommodate the message.
- Maximum message size is 65,535 bytes (approx. 65KB).
- Modifications to the watermarked image (especially to the border) may prevent message recovery.
- The message is encoded in the LSB of the blue channel, which may be vulnerable to certain image manipulations.
- JPEG or other lossy compression formats will corrupt the watermark - always use PNG format.
- If extraction fails, ensure you're using the exact same watermarked image that was generated (no resizing, recompression, etc.)
- The program will display debug information about message lengths during embedding and extraction
- If the extracted text is corrupted, it means the watermark has been damaged, possibly by image compression