Active Contour Models (Snakes) or Dynamic Time Warping techniques often use Dynamic Programming (DP) to minimize an energy function across a sequence of points. This is equivalent to finding the minimum cost path in a chain graph.
We consider a simplified 1D contour segmentation problem represented by a chain of pixels w1,w2,…,wn, where wn∈{−1,0,1} represents the relative vertical shift of the contour at position n.
The total cost S of a contour assignment w is:
S(w)=∑nUn(wn)+∑nPn,n−1(wn,wn−1)
where:
Implement the core recurrence relation of the DP solution (Viterbi algorithm) to find the minimum cumulative cost Sn,k of reaching pixel n with label k:
Sn,k=Un(wn=k)+minl[Sn−1,l+Pn,n−1(wn=k,wn−1=l)]
Given the cumulative costs Sn−1 for the previous column and the costs Un, calculate the minimum cumulative costs Sn for the current column.
The smoothness cost Pn,n−1 is defined by the ℓ₁ norm (Manhattan distance) between adjacent labels:
Pn,n−1(k,l)=∣k−l∣
Unary: [2.0, 1.0, 5.0], Cumulative: [3.0, 2.0, 4.0]
[5.000, 3.000, 8.000]
For each target label k:
Sₙ(-1) = U(-1) + min{S_{n-1}(-1)+0, S_{n-1}(0)+1, S_{n-1}(1)+2}
Sₙ(0) = U(0) + min{S_{n-1}(-1)+1, S_{n-1}(0)+0, S_{n-1}(1)+1}
Sₙ(1) = U(1) + min{S_{n-1}(-1)+2, S_{n-1}(0)+1, S_{n-1}(1)+0}