Imagine a black-and-white image in which a few pixels have changed color. A simple way to estimate a cleaner binary image is to replace each pixel with the most common color in its neighborhood. That can remove isolated defects, but it can also erase thin lines or small details that are supposed to be there.

An optimization model offers a different way to express the problem. It treats the choice of color for every pixel as a binary decision and searches for an image that balances fidelity to the observation with consistency between neighboring pixels.

A model of the image

Let yi be the observed binary value of pixel i, and let xi be its proposed recovered value. Assign a positive weight ai to changing the observed value. For each neighboring pair (i,j), give a nonnegative weight wij to disagreement between their recovered values. The objective is

E(x) = ∑i ai|xi − yi| + ∑(i,j)wij|xi − xj|.

For binary values, |xi − xj| = xi + xj − 2x_ix_j. The data term also has a linear expression because yi is fixed. The entire objective is therefore a QUBO, with one variable per pixel and quadratic terms between neighboring pixels.

The first term rewards agreement with the observed image. The second encourages smooth regions. Increasing the smoothing weight makes it more attractive to remove an isolated pixel, but also more attractive to remove a small genuine feature. Choosing the weights is part of specifying the model, not a question that the optimizer can answer by itself.

A small exact example

Consider a row of observed pixels containing a single white pixel surrounded by black pixels. With a suitable smoothing weight, changing that isolated pixel can reduce the energy. A white region comprising several neighboring pixels may instead survive, because removing the whole region would incur several data penalties while saving relatively few boundary penalties.

The following example searches all binary assignments of a small row. It compares a low and a higher smoothing weight, explicitly checks that the QUBO expansion agrees with the original energy, and reports the minimum. Enumeration is used here because the example is small. It gives a known answer against which any implementation can be checked.

Retain the constant offset from expanding the binary data term when comparing energies between two formulations. It has no effect on the minimizing image.

Illustration: standalone Python calculation.

from itertools import product
y = (0, 0, 1, 0, 0)
def original(x, w):
    return sum(abs(a-b) for a,b in zip(x,y)) + w*sum(abs(a-b) for a,b in zip(x,x[1:]))
def expanded(x, w):
    return sum(b+(1-2*b)*a for a,b in zip(x,y)) + w*sum(a+b-2*a*b for a,b in zip(x,x[1:]))
xs = list(product((0,1), repeat=len(y)))
for w in (0.25, 1):
    assert all(original(x,w)==expanded(x,w) for x in xs)
    e, x = min((original(x,w), x) for x in xs)
    print(w, x, e)
assert min(xs, key=lambda x: original(x,1)) == (0,0,0,0,0)

The example prints:

0.25 (0, 0, 1, 0, 0) 0.5
1 (0, 0, 0, 0, 0) 1

An exact reference for a much larger problem

This particular energy has a valuable mathematical property. With nonnegative pairwise disagreement weights, it is submodular and can be minimized by a suitable source-to-sink minimum cut. Each pixel becomes a graph node. Terminal connections encode the data costs, while connections between pixels encode disagreement costs. A minimum cut separates the nodes into the two colors.

That makes binary image denoising useful for evaluating a general QUBO solver. The same energy can be minimized by a specialized exact algorithm, so an independently computed minimum gives a clear reference for checking the returned objective. More general binary image models, such as those with competing interaction signs, need different methods and may not have that same exact reduction.

Evaluating the recovered image

The energy and the visual quality answer different questions. A solution that minimizes the model has achieved the mathematical objective. If the model oversmooths a particular feature, its optimum may still differ from the true image. When a clean reference image is available, compare pixel errors separately from energy. For other applications, choose an assessment that matches the task.

A reproducible experiment should record the clean image or generator, noise process, neighborhood, weights and exact reference where available. It should distinguish model construction, search and image reconstruction. A useful illustration shows the observed image, the recovered image and the residual errors using the same scale.

This is a natural example of how a sparse binary quadratic model can express a spatial problem. The 4colors Optimizer for QUBO provides a way to explore such models and compare returned energies against an independently computed reference.

Further reading

D. M. Greig, B. T. Porteous and A. H. Seheult, Exact Maximum A Posteriori Estimation for Binary Images.