Short Version
How do I apply this partial derivative to a line integral along a contour in an image? The contour is a B-spline and the term I am trying to resolve is below. The detailing of each part of this expression can be found in the "Long, Detailed Version" starting at the paragraph "The 2nd term is a little more complex."
$${\frac{\partial}{\partial\vec{c}}}\left({\oint_u}\ {||{\nabla_\sigma}I(x(u), y(u))||\ du}\right)$$
Long, Detailed Version
I'm implementing a relatively highly cited academic research paper: "Interobserver Reproducibility of Quantitative Cartilage Measurements: Comparison of B-Spline Snakes and Manual Segmentation". In short, the paper outlines how you can get a B-spline to outline knee cartilage in a 2D slice of an MRI. I am stuck at minimizing the cost function using gradient descent. The cost function is defined as followed:
$$E_{tot} = {\alpha}E_D + {\beta}E_I + {\gamma}E_C$$
The 1st term, $E_D$, is the "Internal Deformation Energy" of the contour. It characterizes the elastic properties of a contour and controls therefore its rigidity. The 2nd term, $E_I$, is the "Image Forces Energy". These forces attract the contour to the edges of the cartilage, and therefore take the image intensities into account. The 3rd term, $E_C$, is only valid if we're attempting to expand this algorithm to 3D, but since I'm only focused on 2D slices for now we can ignore this term. $\alpha$, $\beta$, and $\gamma$ are heuristic parameters to balance the contribution of each term.
$$E_{tot} = \alpha E_D + \beta E_I$$
The initial B-spline contour is created by a set of user selected points. This initial contour is defined by a set of $N$ control points $\vec{c}$. Note: control points $\neq$ user selected points. The user-selected points points are used to get the initial contour's control points.
In the paper, the authors suggest $E_{tot}$ can be represented as $E_{tot}(\vec{c},\sigma)$. This can be seen when we expand the $E_D$ and $E_I$ terms with equivalents provided by the authors:
$$E_{tot}(\vec{c},\sigma) = {\alpha}({\vec{c}^\intercal}B{\vec{c}}) + {\beta}\left(-\frac{1}{L}{\oint_u}\ {||{\nabla_\sigma}I(x(u), y(u))||\ du}\right)$$
In the 1st term, the $B$ is a $2N \times 2N$ so called rigidity matrix consisting of scalars only.
The 2nd term is a little more complex. Say we have an image, $I(x, y)$. If we take the Derivative of Gaussian (DoG) of the image we get ${\nabla_\sigma}I(x, y)$, where $\sigma$ is the standard deviation of the Gaussian kernel used, AKA the "scale of the filter". The magnitude of that resulting DoG image is ${||{\nabla_\sigma}I(x, y)||}$, which is another image. Next, $\ {\oint_u}{||{\nabla_\sigma}I(x(u), y(u))|| du}\ $ is the line integral of ${||{\nabla_\sigma}I(x, y)||}$ along that B-spline contour. Lastly, we divide by the length of the contour, $L$, to normalize the integral.
According to the paper, we have to minimize $E_{tot}(\vec{c},\sigma)$ at various levels of $\sigma$. However, to simplify this, I want to focus on minimize at one smoothing level by setting $\sigma = 4$. Therefore we're trying to minimize the following instead:
$$E_{tot}(\vec{c}) = {\alpha}({\vec{c}^\intercal}B{\vec{c}}) + {\beta}\left(-\frac{1}{L}{\oint_u}\ {||{\nabla_4}I(x(u), y(u))||\ du}\right)$$
I define gradient descent for this problem as:
$$\vec{c_{i+1}} = \vec{c_{i}} - {\mu} {\frac{\partial}{\partial\vec{c}}} {E_{tot}(\vec{c})}$$
Where $\mu$ is the learning rate. To solve this problem, we have to calculate ${\frac{\partial}{\partial\vec{c}}} {E_{tot}(\vec{c})}$. The first term is easy:
$${\frac{\partial}{\partial\vec{c}}}{\alpha}{\vec{c}^\intercal}B{\vec{c}} = 2{\alpha}B{\vec{c}}$$
Now the second term:
$${\frac{\partial}{\partial\vec{c}}}\left(-{\beta}\frac{1}{L}{\oint_u}\ {||{\nabla_\sigma}I(x(u), y(u))||\ du}\right) \Rightarrow -{\beta}\frac{1}{L}{\frac{\partial}{\partial\vec{c}}}\left({\oint_u}\ {||{\nabla_\sigma}I(x(u), y(u))||\ du}\right)$$
I'm not sure how to gracefully apply ${\frac{\partial}{\partial\vec{c}}}$ to the line integral. What I eventually settled on was to apply ${\frac{\partial}{\partial\vec{c}}}$ directly to the B-spline contour. To do this, we have to look closer at the B-spline definition.
Let $\vec{p}(u) = (x(u), y(u))^\intercal$ be a point in the B-spline contour parameterized by $u$. Thus, we can define the image intensities along the contour as:
$$I(x(u), y(u)) = I(\vec{p}(u))$$
Provided in the paper, these contour points can be put in terms of $u$ by:
$$\vec{p}(u) = \sum_{i=1}^N \vec{c_i} B_i(u)$$
where $B_i(u)$ are polynomial B-spline basis functions of order 3 and are defined by:
$$B_i(u) = \begin{cases} \frac{1}{2}(u-i)^2, & 0 \leq u < 1 \\ \frac{3}{4}-[(u-i)-\frac{3}{2}]^2, & 1 \leq u < 2 \\ \frac{1}{2}[(u-i)-3]^2, & 2 \leq u < 3 \\ 0, & otherwise \end{cases}$$
This evaluates to:
$$B_i(u) = \begin{cases} \frac{1}{2}u^2-ui+\frac{1}{2}i^2, & 0 \leq u < 1 \\ -u^2 - i^2 + 2ui + 3u - 3i - \frac{3}{2}, & 1 \leq u < 2 \\ \frac{1}{2}u^2 + \frac{1}{2}i^2 - ui - 3u + 3i + \frac{9}{2}, & 2 \leq u < 3 \\ 0, & otherwise \end{cases}$$
Now if we consider $\vec{c}$ as a variable, we can define $\vec{p}(u)$ as $\vec{p}(\vec{c}, u)$ thus giving us a $\vec{c}$ variable in the line integral ${\oint_u}\ {||{\nabla_\sigma}I(\vec{p}(\vec{c}, u))||\ du}$. So now I try to apply ${\frac{\partial}{\partial\vec{c}}}$ to that line integral by applying it directly to the path, $\vec{p}(\vec{c}, u)$. The motive for this is purely intuitive since I could find a mathematical rule that allowed me to apply ${\frac{\partial}{\partial\vec{c}}}$ directly to the line integral.
My thinking here is that since the line integral above is the integral of the magnitude of the DoG image along the contour parameterized by u ($\vec{p}(u)$), by parameterizing the contour with 2 terms ($\vec{p}(\vec{c}, u)$) we're still able to take the line integral along the contour while having something to take the partial derivative of ($\vec{p}(\vec{c}, u)$). This reasoning is pretty weak, but it's an assumption I made to get a solution at least.
So I apply ${\frac{\partial}{\partial\vec{c}}}\vec{p}(\vec{c}, u)$ as follows:
$${\frac{\partial}{\partial\vec{c}}}\vec{p}(\vec{c}, u) = \begin{cases} {\frac{\partial}{\partial\vec{c}}} \sum_{i=1}^N \vec{c_i} [\frac{1}{2}u^2-ui+\frac{1}{2}i^2], & 0 \leq u < 1 \\ {\frac{\partial}{\partial\vec{c}}} \sum_{i=1}^N \vec{c_i}[-u^2 - i^2 + 2ui + 3u - 3i - \frac{3}{2}], & 1 \leq u < 2 \\ {\frac{\partial}{\partial\vec{c}}} \sum_{i=1}^N \vec{c_i}[\frac{1}{2}u^2 + \frac{1}{2}i^2 - ui - 3u + 3i + \frac{9}{2}], & 2 \leq u < 3 \\ 0, & otherwise \end{cases}$$
Let the stuff in the square brackets be $b_i$, so that for each part of the piece-wise we can rewrite the summations as:
$${\frac{\partial}{\partial\vec{c}}} \sum_{i=1}^N \vec{c_i} b_i \Rightarrow {\frac{\partial}{\partial\vec{c}}} (\vec{c}^\intercal \cdot \vec{b}) \Rightarrow \vec{b} = \sum_{i=1}^N b_i$$
This gives us:
$${\frac{\partial}{\partial\vec{c}}}\vec{p}(\vec{c}, u) = \begin{cases} \frac{1}{6}N^3+\frac{1}{2}Nu^2-\frac{1}{2}N^2u-\frac{1}{2}Nu+\frac{1}{4}N^2+\frac{1}{12}N, & 0 \leq u < 1 \\ -\frac{1}{3}N^3+N^2u-Nu^2+4Nu-2N^2-\frac{19}{6}N, & 1 \leq u < 2 \\ \frac{1}{6}N^3-\frac{1}{2}N^2u-2Nu+\frac{13}{4}N^2+\frac{91}{12}N, & 2 \leq u < 3 \\ 0, & otherwise \end{cases}$$
This above result $({\frac{\partial}{\partial\vec{c}}}\vec{p}(\vec{c}, u))$ is most likely wrong because each part of the piece-wise gives a scalar value instead of a coordinate pair of a new path. I would have liked to see a coordinate pair in this "solution" since coordinates would at least give me a path to integrate along. A few questions:
1. Is there anything wrong with my math?
2. Is there any other way to apply the partial derivative?
3. Any alternatives to directly calculating the derivative of the cost function?
4. Any other feedback would be greatly appreciated.