Skip to content

DaivikGirish/Image_Camouflage_GeneticAlgorithm

Repository files navigation

Genetic Algorithm for Object Camouflaging Optimization

Author: Daivik Girish
UCID: dg643


Problem Statement

  • Challenge: Design camouflaging patterns that blend an object into its background.
  • Objective: Reduce detectability by humans and machine vision by maximizing visual and structural similarity and minimizing saliency.

Importance of Camouflaging

  • Military & Security: Conceal equipment and personnel.
  • Computer Vision: Test robustness of recognition algorithms.
  • Biomimicry: Inspire design from nature's camouflage.
  • Human-Computer Interaction: Enhance AR and interface visuals.

Methodology & Workflow

  1. Initialization: Load object/background images, generate random camouflage patterns.
  2. Fitness Evaluation: Blend object and background, calculate MSE, SSIM, and saliency.
  3. Selection: Elite selection of best individuals.
  4. Crossover & Mutation: Create new patterns via blending crossover and Gaussian mutation.
  5. Repetition: Iterate for a set number of generations, tracking fitness and image quality.

Hyperparameters

  • object_image_path: Path to object image
  • background_image_path: Path to background image
  • image_size: Resize images (e.g., 64x64)
  • num_generations: Number of generations
  • population_size: Number of chromosomes (e.g., 50)
  • mutation_rate: Probability of mutation per gene
  • mutation_strength: Std. dev. for Gaussian noise
  • noise_strength: Random noise intensity during mutation

Fitness Calculation

  • MSE: Mean squared error between blended and background images
  • Saliency Map: Highlights visually important regions
  • SSIM: Structural similarity index
  • Final Fitness: SSIM - MSE - Saliency

Genetic Operators

Crossover

  • Blending Crossover:
    • offspring1 = α * parent1 + (1-α) * parent2
    • offspring2 = α * parent2 + (1-α) * parent1
    • α randomly chosen in [0.4, 0.6]

Mutation

  • Gaussian Mutation:
    • Applies noise to randomly selected genes
    • Values clamped to [0, 1] (valid pixel range)

Results

  • Fitness vs. Generations: Shows improvement over time
  • Final Blended Image: Demonstrates effective camouflage after 3000 generations

Tools Used

  • Language: Python
  • Libraries:
    • torch (with GPU support)
    • numpy, matplotlib, scikit-image, torchmetrics
  • Hardware: CPU/GPU compatible

Key Findings

  • Genetic Algorithm evolves effective camouflage patterns
  • Combined fitness (SSIM, MSE, saliency) ensures both visual and structural similarity
  • Final patterns significantly reduce object saliency

Conclusion & Future Work

  • Is GA the best for image camouflaging?
    • Not always; alternatives like neural networks or other evolutionary strategies may outperform GA in some cases.
  • Future Directions:
    • Hybrid GA + Deep Learning (e.g., CNNs)
    • Real-time processing
    • Refined mutation/crossover strategies

Project Structure

├── main.py                 # Main entry point
├── camouflage_ga.py        # Genetic algorithm class
├── config.py               # Configuration and hyperparameters
├── image_utils.py          # Image processing utilities
├── fitness_functions.py    # Fitness evaluation functions
├── genetic_operators.py    # Crossover and mutation operators
├── visualization.py        # Plotting and visualization functions
├── requirements.txt        # Python dependencies
├── images/                 # Input images (object/background)
├── presentation/           # Project presentation (PPTX, docs)
└── README.md               # This file

How to Run

  1. Place your object and background images in the images/ folder as image.jpg and background.jpg.
  2. Install dependencies:
    pip install -r requirements.txt
  3. Run the main script:
    python main.py

Troubleshooting

  • Missing images: Ensure images/image.jpg and images/background.jpg exist or update paths in config.py.
  • Import errors: Install all dependencies from requirements.txt.
  • CUDA out of memory: Reduce image size or population size, or run on CPU.
  • Slow performance: Use GPU if available, or reduce generations/population size.

Contributing

Contributions are welcome! To contribute:

  1. Fork the repository
  2. Create a new branch for your feature or bugfix
  3. Make your changes with clear commit messages
  4. Submit a pull request with a description of your changes

For more details, see the presentation in the presentation/ folder.

About

An evolutionary approach to generate camouflage patterns using PyTorch. Optimizes image blending with backgrounds by evolving pixel-level patterns to minimize visual saliency, MSE, and maximize SSIM. Useful for research in visual obfuscation, pattern design, and neural perception.

Topics

Resources

Stars

2 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages