3

I'm currently performing a pixel-based classification of an image using simple supervised classifiers implemented in Scikit-learn. The image is first reshaped into a vector of single pixel intensities, then the training and the classification are carried out as in the following:

from sklearn.linear_model import SGDClassifier

classifier = SGDClassifier(verbose=True)
classifier.fit(training_data, training_target)
predictions = classifier.predict(test_data)

The problem with pixel-based classification is the noisy nature of the resulting classified image. To prevent it, I wanted to use Graph Cut (e.g. Boykov-Kolmogorov implementation) to take into account the spatial context between pixels. But, the implmentations I found in Python (NetworkX, Graph-tool) and in C++ (OpenGM and the original implementation: [1] and [2]) don't show how to go from an image to a Graph, except for [2] which is in matlab, and I'm not really enough familiar with either of Graph Cut and matlab.

So my question is basically how can graph cuts be integrated into the previous classification (e.g. before the training or as a post-processing)?

I had a look at the graph algorithms in Scikit-image (here), but these work only on RGB images with discreet values, whereas my pixel values are continuous.

Hakim
  • 3,225
  • 5
  • 37
  • 75
  • By "my pixel values are continuous", do you mean the color information is stored in a three dimensional vector with floating-point values between 0 and 1? If so, multiply the vector by 255 and truncate them into Integers. This will give you a RGB image with "discreet values" that can be used with the graph algorithms in Scikit-image. –  Jan 31 '19 at 23:20
  • Yes my pixel values are floats but my the image is a single-band not an RGB. I've found a Python library that implements Graph cuts (wrapper of the C++ one), and this [image restoration](http://pmneila.github.io/PyMaxflow/tutorial.html#binary-image-restoration) example seems to look like what I'm trying to achieve, except that the image to be post-processed is binary in my case. Another think left to do is maybe to adjust the parameters. What do you think of this solution? – Hakim Feb 01 '19 at 08:05

1 Answers1

0

I found this image restoration tutorial which does more or less what I was looking for. Besides, you use a Python library wrapper (PyMaxflow) to call the maxflow algorithm to partition the graph.

It starts from the noisy image on the left, and takes into account the spatial constraint between pixels, to obtain the binary image on the right.

enter image description here enter image description here

Hakim
  • 3,225
  • 5
  • 37
  • 75