Skip to content

xMohammadAsimx/lsb-watermarking

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

LSB Watermarking in MATLAB

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.


Project Overview

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

Project Structure

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

Requirements

  • MATLAB (R2020 or later recommended)
  • Image Processing Toolbox

How to Run

  1. Clone the repository:
git clone https://github.com/xMohammadAsimx/lsb-watermarking.git
  1. Open the project in MATLAB.

  2. Navigate to the src folder.

  3. Run the main script:

main

Watermarking Options

When running the program, the user can select:

Embedding methods

  1. Sequential embedding
  2. Random spreading
  3. Sequential embedding with message repetition

Additional parameters

  • Number of message repetitions
  • LSB depth (1–8 bits)
  • Random seed (for spreading mode)

Output

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/

Example Workflow

  1. Load cover image
  2. Enter watermark message
  3. Select embedding method
  4. Choose repetition count
  5. Select number of LSB bits
  6. Embed watermark
  7. Extract watermark
  8. Evaluate PSNR
  9. Test robustness using JPEG compression

Author

Mohammad Asim


License

This project is licensed under the MIT License.

About

MATLAB implementation of LSB watermarking with embedding, extraction, PSNR analysis, and JPEG robustness testing.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages