1
votes

Am trying to classify different terrains/regions from the given satellite image which is in grayscale , 2 band spectrums.. By far i have computed the average pixel intensities of the pixels in the respective terrains. and randomly selected some pixels from specific regions , and now am looking to train these group of pixels using SVM possibly using LinearSVM, so what would be the appropriate approach to classify different terrains in the image, any algorithmic steps are much appreciated and that exactly what am looking for, steps to achieve this. BTW am using python with OpenCV for this.

enter image description here

This is the gray scale image that i willing to classify..

enter image description here

And this is what am expecting after classifying different terrains , by simply coloring different regions to highlight them, every color in the colored image signify highlighted region like blue colored region represents sea/river , the color in red represents forest region , also the rest of terrain in white color represents urbanized area in the city.

Any help is appreciated!

1
You might want to look at Superpixels, I believe with this you can get the starting steps for classifying gray values. - Rick M.

1 Answers

1
votes

This can be achieved with a color gradient map. It's basically creating a color map of gray value intensities. You'll notice the urban sections have slight blue tinges to them, which indicates that they are close to the same pixel intensity as the lighter blue water areas. This particular color gradient ranges from dark blue, to red in the middle gradient, to white in the end of the gradient.

Here is what I've used in the past to create a gradient map in C++: (keep in mind that this code expects a normalized image. I have scaled my grayscale images from 0 (black) to 100 (white).

class ColorGradient
{
private:
    struct ColorPoint  // Internal class used to store colors at different points in the gradient.
    {
        float r, g, b;      // Red, green and blue values of our color.
        float val;        // Position of our color along the gradient (between 0 and 1).
        ColorPoint(float red, float green, float blue, float value)
            : r(red), g(green), b(blue), val(value) {}
    };
    std::vector<ColorPoint> color;      // An array of color points in ascending value.

public:
    ColorGradient() { createDefaultHeatMapGradient(); }

    void addColorPoint(float red, float green, float blue, float value)
    {
        for (int i = 0; i<color.size(); i++) {
            if (value < color[i].val) {
                color.insert(color.begin() + i, ColorPoint(red, green, blue, value));
                return;
            }
        }
        color.push_back(ColorPoint(red, green, blue, value));
    }

    //-- Inserts a new color point into its correct position:
    void clearGradient() { color.clear(); }

    //-- Places a 5 color heapmap gradient into the "color" vector:
    void createDefaultHeatMapGradient()
    {
        color.clear();
        color.push_back(ColorPoint(0, 0, 1, 0.0f));      // Blue.
        color.push_back(ColorPoint(0, 1, 1, 0.25f));     // Cyan.
        color.push_back(ColorPoint(0, 1, 0, 0.5f));      // Green.
        color.push_back(ColorPoint(1, 1, 0, 0.75f));     // Yellow.
        color.push_back(ColorPoint(1, 0, 0, 1.0f));      // Red.
    }

    // Inputs a (value) between 0 and 1 and outputs the (red), (green) and (blue)
    // values representing that position in the gradient.
    void getColorAtValue(const float value, float &red, float &green, float &blue)
    {
        if (color.size() == 0)
            return;

        for (int i = 0; i<color.size(); i++)
        {
            ColorPoint &currC = color[i];
            if (value < currC.val)
            {
                ColorPoint &prevC = color[max(0, i - 1)];
                float valueDiff = (prevC.val - currC.val);
                float fractBetween = (valueDiff == 0) ? 0 : (value - currC.val) / valueDiff;
                red = (prevC.r - currC.r)*fractBetween + currC.r;
                green = (prevC.g - currC.g)*fractBetween + currC.g;
                blue = (prevC.b - currC.b)*fractBetween + currC.b;
                return;
            }
        }
        red = color.back().r;
        green = color.back().g;
        blue = color.back().b;
        return;
    }
};

Please see this article for more detailed information regarding gradient maps: http://www.andrewnoske.com/wiki/Code_-_heatmaps_and_color_gradients

I hope this helps. Sorry I couldn't provide a direct python example, but you should be able to convert the code fairly easily. Cheers mate.