Skip to main content

Advanced image protection system against AI training and unauthorized use

Project description

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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

antiai-0.1.0.tar.gz (47.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

antiai-0.1.0-py3-none-any.whl (42.9 kB view details)

Uploaded Python 3

File details

Details for the file antiai-0.1.0.tar.gz.

File metadata

  • Download URL: antiai-0.1.0.tar.gz
  • Upload date:
  • Size: 47.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.12

File hashes

Hashes for antiai-0.1.0.tar.gz
Algorithm Hash digest
SHA256 87af0a3771e2dbc13d9ffc0b4df6b689de1356ab966c991583ff19e179cf0fb5
MD5 c909e71f45eccc6725e5e9b073cdbba3
BLAKE2b-256 1122044535d1f3f36047c2e25edb200fd7a8a78ce558a52e2036b5a539167e69

See more details on using hashes here.

File details

Details for the file antiai-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: antiai-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 42.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.12

File hashes

Hashes for antiai-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b066f7f37073959e9d14b0b6ab9c38e2505d0395448fe4d0217fa6d1c5534970
MD5 9ce4d21e7c04a0b86aa9ce71b90e8521
BLAKE2b-256 3838adf73bf9f194bb7d632fdcfc4e7b029d94f99966b0ba6225bc8c62d93fad

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page