This project implements a Least Significant Bit (LSB) spatial-domain watermarking system in MATLAB for embedding and extracting text-based watermarks in digital images.
The system allows watermark insertion into grayscale or RGB images and evaluates the impact of watermarking using PSNR (Peak Signal-to-Noise Ratio). It also includes robustness testing against JPEG compression and optional watermark length detection using autocorrelation.
Digital watermarking is commonly used for copyright protection, authentication, and data hiding. This project demonstrates a simple yet effective LSB-based watermarking technique, where watermark bits are embedded in the least significant bits of image pixels.
Key capabilities implemented:
- Watermark embedding and extraction
- Sequential and random spreading watermarking modes
- Message repetition for robustness
- PSNR analysis to evaluate visual distortion
- Autocorrelation-based watermark length detection
- JPEG compression robustness testing
- Majority-vote recovery for repeated watermarks
lsb-watermarking/
│
├── src/ # MATLAB source code
│ ├── main.m
│ ├── inject.m
│ ├── extract.m
│ ├── text_to_bits.m
│ ├── bits_to_text.m
│ ├── detect_length.m
│ ├── recover_majority.m
│ ├── majority_vote.m
│ ├── experiment_psnr.m
│ └── mypsnr.m
│
├── data/
│ ├── input/ # Original images
│ │ └── sealion.tif
│ │
│ └── output/ # Generated output images
│
├── README.md
├── LICENSE
└── .gitignore
- MATLAB (R2020 or later recommended)
- Image Processing Toolbox
- Clone the repository:
git clone https://github.com/xMohammadAsimx/lsb-watermarking.git
-
Open the project in MATLAB.
-
Navigate to the
srcfolder. -
Run the main script:
main
When running the program, the user can select:
Embedding methods
- Sequential embedding
- Random spreading
- Sequential embedding with message repetition
Additional parameters
- Number of message repetitions
- LSB depth (1–8 bits)
- Random seed (for spreading mode)
The system generates:
- Stego image
- Extracted watermark
- PSNR value between original and stego image
- Optional JPEG compressed image
- Recovered watermark after compression
Output images are saved in:
data/output/
- Load cover image
- Enter watermark message
- Select embedding method
- Choose repetition count
- Select number of LSB bits
- Embed watermark
- Extract watermark
- Evaluate PSNR
- Test robustness using JPEG compression
Mohammad Asim
This project is licensed under the MIT License.