How senacen/anaglyph-ai works
Main Components
• Frontend: A React/Vite application written mainly in TypeScript. It contains components such as AnaglyphEditor, ImageUpload, Footer, and App. This part handles the user interface for uploading images, setting parameters (e.g., disparity strength, zero parallax options), and displaying results.
• Backend: A Flask-based Python application with files such as app.py, anaglyph_generator.py, depth_map_generator.py, and a notebook for random image processing. This layer handles the core logic of depth map generation (using a model like DepthAnythingV2), stereo pair generation, image shifting, inpainting using OpenCV, and merging to produce the final anaglyph.
• External Services & Libraries:
• An external depth estimation model (DepthAnythingV2).
• OpenCV inpainting functions.
• NumPy for numerical operations.
• Docker & Deployment: Both the frontend and backend have separate Dockerfiles along with .env files, indicating containerized deployment and likely orchestration for a production environment.
Relationships & Data Flow
• User Interface (Browser/Client) → Frontend React Application: The user interacts with the web application, uploads images, tweaks parameters (like disparity strength, pop in/pop out, minimise retinal rivalry).
• Frontend → API Calls to Backend: Once an image is uploaded or settings are adjusted, the frontend sends a REST (or HTTP) API request to the Flask backend.
• Backend Processing:
• Receives the image and command parameters.
• Generates a depth map using the depth estimation module.
• Computes the stereo image pair through pixel shift calculation based on the depth data.
• Applies OpenCV inpainting to fill missing pixels (or holes) in the generated eye images.
• Backend → Frontend Response: The processed 3D anaglyph image is then returned to the frontend to be displayed.
Architectural Patterns & Design Principles
• Separation of Concerns: Distinct separation between the frontend (user interface) and backend (image processing and API logic).
• Containerization: Each layer is containerized (frontend and backend have Dockerfiles and proper environment configurations), suggesting microservice-friendly modularity.
• Modular Processing: The backend comprises separate Python scripts (e.g., depth_map_generator.py for depth estimation, anaglyph_generator.py for merging images) capturing specific stages of processing. This modular design aids in easier debugging and scalability.
Technologies and Frameworks to Highlight
• Frontend: React with TypeScript, Vite (for development/build), CSS modules for component styling, and ESLint for code quality.
• Backend: Flask as the web framework; Python libraries such as NumPy for image manipulation, OpenCV for inpainting, and integration with external depth estimation models.
• Deployment: Docker for containerization; possible orchestration when deployed in production.
• Data Input/Output: HTTP endpoints for communication between frontend and backend.