← Back to list

Manual Derivation Series: Level Set (CV Model) and Python Implementation

The Snake model has several drawbacks:

Chwmwei · 2026-03-29 12:46 · 0 claps · 2.6 min read
#chan-vese #computer-vision
Open on Medium ↗

Manual Derivation Series: Level Set (CV Model) and Python Implementation

The Snake model has several drawbacks:

It is difficult to track point merging/splitting on the curve (the distribution of points is hard to analyze). It cannot handle segmentation tasks with multiple objects. It cannot handle objects with holes. It also performs poorly on concave objects (for highly concave regions, more points are needed to represent the curve, but the number of points is fixed, so performance degrades).

CV Brain

CV Brain

In the level set method, curve points are not represented explicitly. Instead, curves are represented by level sets of a higher-dimensional function, i.e., an implicit representation. The Chan-Vese model (CV model), proposed by Chan and Vese in 2001, is an active contour model based on region energy minimization (a level set method). It does not rely on image edge gradients; instead, it segments the image into object and background regions and minimizes an energy functional so that gray levels within each region become homogeneous. It is especially suitable for image segmentation with heavy noise and blurry boundaries.

Core characteristics and principles: Region-based rather than edge-based: Unlike the traditional Snake model, the CV model relies on mean gray levels inside regions, making it more robust to false edges and noise. Level set representation: It uses a level set function to evolve the contour and can automatically handle topological changes (such as splitting or merging). Energy functional composition: The core includes two terms: a data-fitting term (enforcing gray-level homogeneity within regions) and a regularization term (smoothing the contour). Application scope: It is widely used in medical image segmentation and computer vision, and is suitable for complex scenarios with intensity inhomogeneity.

Mathematically, the Chan-Vese (CV) model is a continuous optimization problem based on variational methods and partial differential equations (PDEs), while in Python it is converted into a discrete numerical computation process. Mathematical derivation (backward reasoning / goal-driven): Logic: If the goal is to separate foreground and background, then at the optimal state (minimum energy), the inside intensity should be uniform, the outside intensity should be uniform, and the boundary should be as short as possible. Direction: Starting from the desired result (energy functional E), variational methods are used to derive, in reverse, how the curve should move at each step to reach that result. This is a process of reverse-designing the rules from the endpoint.

Python code implementation (forward evolution / process-driven): Logic: Start with a random initial circle, apply the mathematically derived rule to push it, and observe where it evolves. Direction: Starting from the current state, iterate step by step to approach the optimum. This is a process of moving forward along the time axis from the starting point toward the endpoint.

Github Repository: https://github.com/wudye/computer-vision-algorithm/blob/main/3levelSet/cv.ipynb


메타데이터
post_id
44d34ae3ef2c
slug
manual-derivation-series-level-set-cv-model-and-python-implementation-44d34ae3ef2c
url
https://medium.com/@chwmwei/manual-derivation-series-level-set-cv-model-and-python-implementation-44d34ae3ef2c
canonical_url
https://medium.com/@chwmwei/manual-derivation-series-level-set-cv-model-and-python-implementation-44d34ae3ef2c
author_url
https://medium.com/@chwmwei
status
ok
fetched_at
2026-06-13 07:35:29