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.
- 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:
.antiAIformat designed specifically for protection - Easy Integration: Simple API for encoding, decoding, and verification
pip install antiaifrom 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}")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 = imperceptibleEmbeds 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")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()
)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
encoder = AntiAIEncoder()
results = encoder.encode_batch(
input_images=["img1.jpg", "img2.jpg", "img3.jpg"],
output_dir="protected/",
author="Batch User",
protection_level=6
)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']}")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']}")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| 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 |
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.
- Method: Projected Gradient Descent (PGD)
- Loss Function: Feature maximization
- Constraint: L-infinity bounded perturbations
- Quality: PSNR > 40 dB typical
- Transform: Discrete Wavelet Transform (DWT)
- Embedding: DCT coefficient modification
- Robustness: Mid-frequency embedding
- Capacity: ~0.1 bits per pixel
Contributions are welcome! Please see CONTRIBUTING.md for details.
git clone https://github.com/Ross-cripto/antiai.git
cd antiai
pip install -e ".[dev]"
pre-commit installpytest test/ -v --cov=antiaiThis project is licensed under the MIT License - see the LICENSE file for details.
- Inspired by Glaze and Nightshade
- Built with PyTorch, NumPy, and PIL
- Special thanks to the computer vision and adversarial ML research communities
- Author: Rosniel Miguel Allesta Fundora
- Email:r16221639@gmail.com
- GitHub: @Ross-cripto
Made with β€οΈ to protect artists and creators from unauthorized AI use.