GRASSを用いた地理情報システム入門

 第8回実習です!


 第8回目は,講義で説明したGRASS GISによるリモートセンシングを実習します.実習のためのテスト用データを準備しました.これは,実際のLANDSATのTM画像データで,本インターネット講座用に許可を得て作成したものです(The US government retains ownership of the data. Space Imaging® and NASDA supported V. Raghavan in acquiring the satellite data at marginal cost.).画像の分解能は約30mです.画像は7バンドあります.これらのバンドの詳細は次回に説明します.なお,以下の実習の結果として作成される画像は,基本的に講義で紹介したものと同じです.したがって,ここでは結果を示しません.実行結果は講義の方を参照して下さい.


[データのダウンロードと解凍]

 すでにGRASSのデータベース形式に変換したテストデータをダウンロードします.下記をクリックして,テスト用データをユーザーのホームディレクトリへダウンロードしてください.

     rs.tar.gz(750Kbyte)

(Webのブラウザによっては,名前が自動的に変わる場合があります.名前を変える場合は,mvコマンド等を使って正しく変更して下さい.ここでは,/home/grassにダウンロードしたとして説明します.)

次にダウンロードしたディレクトリに移動します.

 cd /home/grass

データを解凍します.

 tar -zxvf rs.tar.gz

 これで自動的にvuniv2000というディレクトリが/home/grassの下に作成され,GRASSのデータベースが構築されます.

[GRASSの起動]

 下に示したLOCATIONとMAPSET名でGRASSを立ち上げます.なお,DATABASEの/home/grassの部分は,各自で先ほどファイルを解凍したディレクトリ名に変更してください.また,MAPSETは何でもかまいませんが,下の例ではTmとなっています.

 grass5.0beta6

 LOCATION= vuniv2000

 MAPSET = Tm

 DATABASE= /home/grass  (データを解凍したディレクトリのフルパス)

なお,Tmというマップセッとは新しいので,作成します.

 Would you like to create < Tm > as a new mapset? (y/n) y

[画像の表示・確認]

 画像が正しくダウンロード・解凍されているか確認します.d.monコマンドでモニターを開きます.

 GRASS 5.0beta6 > d.mon x1

 GRASS上では,画像もラスター形式であるため表示は,d.rastコマンドを用います(画像名は,tmb1, tmb2, tmb3, tmb4, tmb5, tmb6, tmb7です.これらはPERMANENTの下に入っています).バンド1の画像(tmb1)を表示してみます.

 GRASS 5.0beta6 > d.rast tmb1

[基本演算]

基本統計: 画像のヒストグラムを表示します.このためのコマンドはd.histogramです.

 GRASS 5.0beta6 > d.histogram

 OPTION: Raster map for which histogram will be displayed
   key: map
 required: YES

 Enter the name of an existing raster file
 Enter 'list' for a list of existing raster files
 Hit RETURN to cancel request
 >
tmb1 (画像名を入力する)
 <tmb1>
 以降 
OPTION は全て<Enterキー>を押します.

濃度変換:画像が暗いので,見やすくするために濃度変換を行ないます.ヒストグラム平滑化に相当する処理は,i.grey.scaleコマンドを用います.

 GRASS 5.0beta6 > i.grey.scale

 which layer needs a grey scale?
 Enter 'list' for a list of existing raster files
 Enter 'list -f' for a list with titles
 Hit RETURN to cancel request
 > tmb1 (画像名を入力する)
 <tmb1>
 Reading tmb1 ... 100%
 [tmb1 in PERMANENT] now has a grey scale color table
 
 which layer needs a grey scale?
 Enter 'list' for a list of existing raster files
 Enter 'list -f' for a list with titles
 Hit RETURN to cancel request
 >  <Enterキー> (必要があれば,他の画像も処理する.終了は<Enterキー>を押す.)

ヒストグラム平滑化を行なった結果を表示してみます.

 GRASS 5.0beta6 > d.rast tmb1

空間演算:空間演算処理として,前の説明(地形の処理)では,r.mapcalcを用いましたが,ここでは,r.mfilterコマンドを用いた方法を説明します.こちらの方が,作成したフィルターを何度も利用できるので便利です. まず,フィルターをviあるいはxedit等を用いて,下記のように作成します.

例:空間1次差分フィルター(x方向)

TITLE Gradient X   TITLEの後ろにタイトルを入れます
MATRIX 3        MATRIXの後ろにフィルターのサイズ3(3×3)を入れます
-1 0 1          フィルターの各値
-1 0 1
-1 0 1
DIVISOR 1       DIVISORの後ろに,計算結果を割る値を入れます.
TYPE P         TYPEの後ろに,フィルター処理の形式を指定します.
            (
Pは並行型,Sは逐次型で通常はPを選ぶ.詳細はマニュアルを参照)

例:空間1次差分フィルター(y方向)

TITLE Gradient Y
MATRIX 3
1 1 1
0 0 0
-1 -1 -1
DIVISOR 1
TYPE P

例:ラプラシアンフィルター

TITLE Laplacian Filter
MATRIX 3
1 1 1
1 -8 1
1 1 1
DIVISOR 1
TYPE P

例:ラプラシアンを用いた鮮鋭化フィルター

TITLE Edge Enhancement using Laplacian filter
MATRIX 3
-1 -1 -1
-1 9 -1
-1 -1 -1
DIVISOR 1
TYPE P

例:横線の抽出フィルター

TITLE Line filter (X)
MATRIX 3
-1 -1 -1
2 2 2
-1 -1 -1
DIVISOR 1
TYPE P

例:縦線の抽出フィルター

TITLE Line filter (Y)
MATRIX 3
-1 2 -1
-1 2 -1
-1 2 -1
DIVISOR 1
TYPE P

例:平滑化用フィルター

TITLE Smooth
MATRIX 3
1 1 1
1 1 1
1 1 1
DIVISOR 9
TYPE P

 これらの作成したフィルターを用いて,r.mfilterコマンドにより空間演算処理を行ないます.

 GRASS 5.0beta6 > r.mfilter
 OPTION: Name of the input raster file
 key: input
 required: YES
 
 Enter the name of an existing raster file
 Enter 'list' for a list of existing raster files
 Hit RETURN to cancel request
 > tmb1 (処理する画像名を入力する)
 <tmb1>
 
 OPTION: Name of the output raster file
 key: output
 required: YES
 
 Enter a new raster file name
 Enter 'list' for a list of existing raster files
 Hit RETURN to cancel request
 >
tmb1smth (適当な出力結果の画像名を入力する)
 
<tmb1smth>
 
 OPTION: Name of the filter file
 key: filter
 required: YES
 enter option > smooth (作成したフィルター名を入力する)
 
 You have chosen:
 filter=smooth
 Is this correct? (y/n) [y]  <Enterキー>
 
 OPTION: Number of times to repeat the filter
 key: repeat
 default: 1
 required: NO
 enter option > <Enterキー>(フィルター処理の繰り返し回数を入力する.
            1度で良いならば,<Enterキー>を押す)
 OPTION: Output raster file title
 key: title
 format: "phrase"
 required: NO
 enter option > <Enterキー> (出力結果の画像へのタイトルを入力する.
            必要無ければ,<Enterキー>を押す)
 以降の
FLAGは全て<Enterキー>を押す.
 
 FILTERING [tmb1@PERMANENT] in [PERMANENT] ... 100%
 
 WRITING [tmb1smth]
 CREATING SUPPORT FILES
 
 その結果を
d.rastコマンドで表示します.演算結果を見やすくするために,i.grey.scaleコマンドを用いてヒストグラム平滑化を行い,再度表示してみます.

[画像の表現]

 色々な画像の表現法を行なってみましょう.

擬似カラー:ラスターデータに適当な色を与えるのは,r.supportコマンドです.これ以外に,r.colorsコマンド等でも行なえます.

カラー画像合成:複数のバンドの画像を赤,青,緑の光の3原色にそれぞれ割り当て,新しいラスターを作成するコマンドとして,d.rgbがあります.ここでは,トゥルーカラーの例を示します.

 GRASS 5.0beta6 > d.rgb

 
OPTION: Name of raster map to be used for RED
   key: red
 required: NO

 Enter the name of an existing raster file
 Enter 'list' for a list of existing raster files
 Hit RETURN to cancel request
 > tmb3  (赤色に対応させる画像名を入力します)
 <tmb3>

 OPTION: Name of raster map to be used for GREEN
   key: green
 required: NO

 Enter the name of an existing raster file
 Enter 'list' for a list of existing raster files
 Hit RETURN to cancel request
 > tmb2  (緑色に対応させる画像名を入力します)
 <tmb2>

 OPTION: Name of raster map to be used for BLUE
   key: blue
 required: NO

 Enter the name of an existing raster file
 Enter 'list' for a list of existing raster files
 Hit RETURN to cancel request
 > tmb1  (青色に対応させる画像名を入力します)
 <tmb1>

 OPTION: Name of raster map to contain results
   key: out
 required: NO

 Enter a new raster file name
 Enter 'list' for a list of existing raster files
 Hit RETURN to cancel request
 > tmtruec  (合成結果を出力する画像名を入力します.
         ファイルを作成しない場合は,
<Enterキー>を押します.)
 <tmtruec>

 これで,モニターに合成した画像が表示されるとともに,ファイルが作成されます.色々な組合せがありますので,バンドを変えて試してみて下さい.


 第8回講義に戻る

 大阪市立大学広報のホームページ