Skip to content

Ross-cripto/antiai

Repository files navigation

AntiAI - Advanced Image Protection System

Python 3.9+ License: MIT Code style: black

AntiAI is a comprehensive Python library for protecting images against unauthorized AI training, style mimicry, and content theft. It implements state-of-the-art adversarial perturbations, invisible watermarking, and robust metadata management.

🎯 Key Features

  • Adversarial Protection: Imperceptible perturbations that confuse AI models
  • Invisible Watermarking: Robust watermarks surviving compression and edits
  • Metadata Management: Complete authorship and copyright tracking
  • File Integrity: Cryptographic signatures and tampering detection
  • Custom Format: .antiAI format designed specifically for protection
  • Easy Integration: Simple API for encoding, decoding, and verification

πŸš€ Quick Start

Installation

pip install antiai

Basic Usage

from antiai import AntiAIEncoder, AntiAIDecoder

# Protect an image
encoder = AntiAIEncoder()
encoder.encode(
    input_image="artwork.jpg",
    output_path="artwork.antiAI",
    author="Your Name",
    protection_level=7  # 0-10
)

# Decode protected image
decoder = AntiAIDecoder()
image, metadata = decoder.decode("artwork.antiAI")

print(f"Author: {metadata.author.name}")
print(f"Protected: {metadata.protection.adversarial}")

πŸ“š Documentation

Protection Mechanisms

1. Adversarial Perturbation

Adds imperceptible noise that causes AI models to fail at:

  • Feature extraction
  • Style transfer
  • Content recognition
from antiai.protection import AdversarialProtection

protector = AdversarialProtection(strength=8)
protected_image, metadata = protector.protect(original_image)

print(f"PSNR: {metadata['quality']['psnr_db']:.2f} dB")  # >40 = imperceptible

2. Invisible Watermarking

Embeds identifying information using DWT-DCT:

  • Survives JPEG compression
  • Resistant to resizing
  • Extractable for proof of ownership
from antiai.protection import InvisibleWatermark

watermarker = InvisibleWatermark(strength=0.1)
marked_image, metadata = watermarker.embed(image, "unique_id_12345")

3. Metadata & Copyright

Complete authorship tracking with:

  • Creator information
  • Copyright statements
  • Usage terms
  • AI training restrictions
from antiai.protection.metadata import MetadataBuilder

metadata = (
    MetadataBuilder()
    .set_author("Artist Name", email="artist@example.com")
    .set_copyright("Β© 2025 Artist Name", license="All Rights Reserved")
    .set_ai_restrictions(do_not_train=True, do_not_scrape=True)
    .build()
)

File Format

The .antiAI format structure:

[HEADER - 512 bytes]
  - Magic bytes: "ANTIAI\x00\x01"
  - Version, dimensions, protection level
  
[METADATA CHUNK]
  - Author, copyright, creation date
  - Protection details
  
[WATERMARK CHUNK]
  - Invisible watermark data
  
[IMAGE DATA CHUNK]
  - PNG-compressed protected image
  
[SIGNATURE - 256 bytes]
  - SHA-256 integrity signature

πŸ” Advanced Features

Batch Processing

encoder = AntiAIEncoder()
results = encoder.encode_batch(
    input_images=["img1.jpg", "img2.jpg", "img3.jpg"],
    output_dir="protected/",
    author="Batch User",
    protection_level=6
)

Verification

from antiai import ProtectionVerifier

verifier = ProtectionVerifier()
result = verifier.verify("artwork.antiAI")

if result['authentic']:
    print("βœ“ Image is authentic and protected")
else:
    print(f"βœ— Issues: {result['issues']}")

Image Comparison

verifier = ProtectionVerifier()
comparison = verifier.compare_images("original.jpg", "copy.jpg")

print(f"Similarity: {comparison['similarity_percent']:.1f}%")
print(f"Likely same image: {comparison['likely_same_image']}")

πŸ› οΈ Tools

The examples/ folder includes ready-to-use tools:

Tool Description
viewer.py Minimalist GUI viewer for .antiAI files (Tkinter)
protect.py CLI tool for protecting images
demo.py Interactive demonstration of all features
# View a protected image
python examples/viewer.py

# Protect an image from command line
python examples/protect.py input.jpg -o output.antiAI --level 7

# Run interactive demo
python examples/demo.py

πŸ›‘οΈ Protection Levels

Level Strength Use Case Quality Impact
0-2 Minimal Basic protection Imperceptible
3-5 Moderate General use Very minor
6-8 Strong Professional work Minor
9-10 Maximum High-value art Noticeable

πŸ“Š Performance

Typical encoding performance on a modern CPU:

  • Small images (512x512): ~1-2 seconds
  • Medium images (1920x1080): ~3-5 seconds
  • Large images (4K): ~10-15 seconds

GPU acceleration (CUDA) can provide 2-4x speedup.

πŸ”¬ Technical Details

Adversarial Algorithm

  • Method: Projected Gradient Descent (PGD)
  • Loss Function: Feature maximization
  • Constraint: L-infinity bounded perturbations
  • Quality: PSNR > 40 dB typical

Watermark Algorithm

  • Transform: Discrete Wavelet Transform (DWT)
  • Embedding: DCT coefficient modification
  • Robustness: Mid-frequency embedding
  • Capacity: ~0.1 bits per pixel

🀝 Contributing

Contributions are welcome! Please see CONTRIBUTING.md for details.

Development Setup

git clone https://github.com/Ross-cripto/antiai.git
cd antiai
pip install -e ".[dev]"
pre-commit install

Running Tests

pytest test/ -v --cov=antiai

πŸ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

πŸ™ Acknowledgments

  • Inspired by Glaze and Nightshade
  • Built with PyTorch, NumPy, and PIL
  • Special thanks to the computer vision and adversarial ML research communities

πŸ“§ Contact

πŸ”— Links


Made with ❀️ to protect artists and creators from unauthorized AI use.

About

The best library for protecting images against unauthorized AI training, style mimicry, and content theft.

Resources

License

Contributing

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages