2017-05-17 21 views
1

グレースケールの2つのバンドスペクトルである与えられた衛星画像から異なる地形/領域を分類しようとしています。私はこれまで、それぞれの地形のピクセルの平均ピクセル強度を計算しました。特定の領域からいくつかのピクセルを無作為に選んで、LinearSVMを使ってSVMを使ってこれらのピクセル群を訓練しようとしています。これを達成するためのステップを探しています。 BTWはこのためにOpenCVでPythonを使用しています。sattelite画像分類Opencv

enter image description here

これは私が喜んで分類するグレースケール画像..です

enter image description here

そして、これは、単にそれらを強調するために異なる領域を着色することにより、異なる地形を分類した後に期待していものです色のイメージのすべての色は、青色の領域が海/川を表し、赤色の色が森林の領域を表し、白い色の領域の他の部分が都市の都市化された領域を表します。

ご協力いただきましてありがとうございます。

+0

あなたは[Superpixels](http://ttic.uchicago.edu/~xren/research/superpixel/)を見たいと思うかもしれませんが、これでグレイ値を分類するための開始ステップが得られると思います。 –

答えて

1

これは、カラーグラディエントマップで実現できます。これは、基本的に、グレー値強度のカラーマップを作成しています。都市部には少し青い色合いがあり、明るい青色の水域と同じピクセル強度に近いことがわかります。この特定の色の勾配は、勾配の終わりに濃い青から中間の勾配の赤、白までの範囲です。

これまでCでグラデーションマップを作成していました:(このコードでは正規化されたイメージが必要です)グレースケールイメージを0(黒)から100(白) 。

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; 
    } 
}; 

勾配マップに関するより詳細な情報については、この記事を参照してください。 http://www.andrewnoske.com/wiki/Code_-_heatmaps_and_color_gradients

私はこれが役に立てば幸い申し訳ありませんが、私は直接Pythonの例を提供することができなかったが、あなたは変換することができるはずです。コードはかなり簡単です。歓迎します。

+0

あなたの助けてくれてありがとう、私はK-nnもこの場合非常に便利であると思いますが、あなたが言うことは理にかなっていますが、k-nnを使い、それに基づいて分類することを計画しています。ありがとうBTW! –

関連する問題