Project for the Fête de la Science 2025 at LPTMS (Université Paris-Saclay).
This project demonstrates how Monte Carlo methods can be used to estimate the area of any shape, even one drawn on paper and photographed. It combines image processing and Monte Carlo sampling in a graphical application built with Rust and eframe/egui.
The program takes an input picture of a closed curve drawn on a white paper sheet, and estimates the area of the region inside the curve using random sampling.
The idea is simple:
-
Convert the image to black and white (ink vs. background),
-
Randomly sample points over the image,
-
Count how many fall inside the curve,
-
Deduce the area from the ratio:
$$ p \approx \frac{\text{hits}}{n} $$
and the estimated object area (in pixels) is:
You can also calibrate the scale using a small square of known size (e.g., 1 cm × 1 cm) drawn on the bottom left of the image, the program automatically detects it and converts pixel area into cm². In this way you can estimate the area in cm².
Click on the screenshot to open the demonstation

The project is made of two main modules and a simple entry point.
-
mc.rs: Implements the core Monte Carlo engine. → How the Monte Carlo sampling works · Function recap -
gui.rs— Defines the interactive graphical interface built witheframe/egui. → GUI workflow explained · Function recap -
main.rs— A minimal bootstrap that initializes the window and launches the GUI.
All documentation files are stored in the Documentation/ folder.
- Load image → select a file.
- Analyze → automatically binarizes and fills the shape.
- (Optional) Calibrate using a square reference (cm²).
- Monte Carlo sampling → points can be sampled all at once or progressively.
- Results → exact black-pixel count vs. Monte Carlo estimate (with 95 % CI).
The interface displays both the visual sampling overlay and numerical results in real time.
Make sure you have Rust (≥ 1.70) installed.
git clone git@github.com:PietroCaracciolo/AEMC.git
cd AEMC/code
cargo run --releaseThis will open the GUI window directly.
Pietro Caracciolo LPTMS
This project is distributed under the terms of the BSD-3-Clause License. See the LICENSE file for details.
I want to thank my colleagues Andrey Zelenskiy(LPTMS) and Lukas Kalvoda(LPTMS) for the support.