I wanted to write a final post in my series on Mumford-Shah segmentation to explain how the approach we detailed so far could be extended for colour images. This time, our working example will be this charming picture of Paul Erdős with child prodigy Terrence Tao:

Mathematics transcending age barriers

Mathematics transcending age barriers

In this case, both our image and cartoon will have three components (one for each primary colour),

{g=(g1,g2,g3)u=(u1,u2,u3)

hence we have to adapt our loss functional to penalise the total deviation in every component:

J[u,K]:=Ωi=13(uigi)2dx+ΩK(u1,u2,u3)(x1,x2)F2dx+H1(K).

where F denotes the Frobenius norm. The linearity of the integration allows us to derive the PDE system and weak form equations in the same way as for the [grayscale case]({{ ref “/posts/mumford-shah-equations” }}), yielding the following UFL expressions.

    a = (
        u1 * w1
        + (v**2) * dot(grad(u1), grad(w1))
        + u2 * w2
        + (v**2) * dot(grad(u2), grad(w2))
        + u3 * w3
        + (v**2) * dot(grad(u3), grad(w3))
    ) * dx

    L = (g1 * w1 + g2 * w2 + g3 * w3) * dx
    a = (
        v * inner(grad(u), grad(u)) * w * dx
        + v * 1 / (4 * eps) * w * dx
        - eps * dot(grad(v), grad(w)) * dx
    )

    L = fem.Constant(domain, 1 / (4 * eps)) * w * dx

We can again solve the equations through alternating iteration. Here is the result:

Segmentation of Tao-Erdos picture

Not too shabby if you ask me!