Search code examples
image-processingmachine-learningcomputer-visionpost-processing

How to make the labels of superpixels to be locally consistent in a gray-level map?


I have a bunch of gray-scale images decomposed into superpixels. Each superpixel in these images have a label in the rage of [0-1]. You can see one sample of images below.

Here is the challenge: I want the spatially (locally) neighboring superpixels to have consistent labels (close in value).

I'm kind of interested in smoothing local labels but do not want to apply Gaussian smoothing functions or whatever, as some colleagues suggested. I have also heard about Conditional Random Field (CRF). Is it helpful?

Any suggestion would be welcome. enter image description here


Solution

  • I'm kind of interested in smoothing local labels but do not want to apply Gaussian smoothing functions or whatever, as some colleagues suggested.

    And why is that? Why do you not consider helpful advice of your colleagues, which are actually right. Applying smoothing function is the most reasonable way to go.

    I have also heard about Conditional Random Field (CRF). Is it helpful?

    This also suggests, that you should rather go with collegues advice, as CRF has nothing to do with your problem. CRF is a classifier, sequence classifier to be exact, requiring labeled examples to learn from and has nothing to do with the setting presented.

    What are typical approaches?

    • The exact thing proposed by your collegues, you should define a smoothing function and apply it to your function values (I will not use a term "labels" as it is missleading, you do have values in [0,1], continuous values, "label" denotes categorical variable in machine learning) and its neighbourhood.
    • Another approach would be to define some optimization problem, where your current assignment of values is one goal, and the second one is "closeness", for example:

    Let us assume that you have points with values {(x_i, y_i)}_{i=1}^N and that n(x) returns indices of neighbouring points of x.

    Consequently you are trying to find {a_i}_{i=1}^N such that they minimize

    SUM_{i=1}^N (y_i - a_i)^2 + C * SUM_{i=1}^N SUM_{j \in n(x_i)} (a_i - a_j)^2
    -------------------------   -   --------------------------------------------
    closeness to current   constant to      closeness to neighbouring values
           values         weight each part
    

    You can solve the above optimization problem using many techniques, for example through scipy.optimize.minimize module.