Skip to content

PietroCaracciolo/AEMC

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Areas Estimation using Monte Carlo

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.


Overview

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:

  1. Convert the image to black and white (ink vs. background),

  2. Randomly sample points over the image,

  3. Count how many fall inside the curve,

  4. Deduce the area from the ratio:

    $$ p \approx \frac{\text{hits}}{n} $$

and the estimated object area (in pixels) is:

$$ A_{\text{obj}} \approx p \times A_{\text{image}} $$

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².


Demonstration

Click on the screenshot to open the demonstation Watch the video here!

Code structure

The project is made of two main modules and a simple entry point.

All documentation files are stored in the Documentation/ folder.

How it works (in short)

  1. Load image → select a file.
  2. Analyze → automatically binarizes and fills the shape.
  3. (Optional) Calibrate using a square reference (cm²).
  4. Monte Carlo sampling → points can be sampled all at once or progressively.
  5. 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.


Installation & Run

Make sure you have Rust (≥ 1.70) installed.

git clone git@github.com:PietroCaracciolo/AEMC.git
cd AEMC/code
cargo run --release

This will open the GUI window directly.


Author

Pietro Caracciolo LPTMS


License

This project is distributed under the terms of the BSD-3-Clause License. See the LICENSE file for details.


Acknowledgements

I want to thank my colleagues Andrey Zelenskiy(LPTMS) and Lukas Kalvoda(LPTMS) for the support.

About

Monte Carlo area estimation from photographed drawings. Rust + egui graphical app combining image processing and Monte Carlo sampling.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages