A Python-based tool that recreates images using simple geometric shapes (circles or triangles). This project builds upon geometric primitive image generation techniques to create abstract representations of target images.
- Support for multiple geometric primitives (circles and triangles)
- Command-line interface with customizable parameters
- Progress tracking with time estimates
- Intermediate result saving
- Configurable output resolution
- Performance optimizations using NumPy
- Clone the repository:
git clone https://github.com/Muneer320/Abstracta2.0
cd Abstracta2.0
- Install required dependencies:
pip install numpy Pillow
The program can be run from the command line with various options:
python main.py -i <input_image> [options]
-i, --image
: Path to the input image
-s, --shape
: Shape to use ('circle' or 'triangle', default: circle)-n, --number
: Number of shapes to generate (default: 1200)-r, --resolution
: Output resolution (default: 512)-w, --working-res
: Working resolution (default: 256)-k, --keep-progress
: Save progress images (default: True)--no-progress
: Disable saving progress images
python main.py -i input/photo.jpg -s circle -n 1000 -r 1024
-
Image Initialization
- Load and resize target image to working resolution
- Initialize canvas with average color of target image
-
Shape Generation
- Supports two primitive types:
- Circles: Defined by center point (x, y), radius, and RGB color
- Triangles: Defined by three vertices and RGB color
- Supports two primitive types:
-
Optimization Process
- Uses hill climbing algorithm to find optimal shapes
- Performs multiple attempts with random starting positions
- Mutates shapes to minimize root mean square error
- Implements efficient numpy-based calculations
-
Progress Tracking
- Real-time progress updates with score
- Time estimation for completion
- Optional intermediate result saving
The project uses several key components:
class ShapeImageGenerator:
def __init__(self, target_image, shape='circle', count=300,
base_resolution=256, output_directory="output",
keep_progress=True)
Main class responsible for:
- Image processing and shape generation
- Optimization algorithm implementation
- Progress tracking and saving
- Final image rendering
generate_random_shape()
: Creates random circle or trianglemutate_shape()
: Modifies existing shape parametershill_climbing()
: Optimizes shape placementgenerate_abstract_image()
: Main generation process
The generator includes several performance optimizations:
- NumPy-based calculations for faster processing
- Efficient random number generation
- Optimized image manipulation using PIL
- Progress tracking with time estimates
This project is an extension of Abstracta by datavorous, with additional features including:
- Multiple shape support
- Command-line interface
- Progress tracking
- Performance optimizations