[GRASS-user] Re: Writing a script for image classification

Martin Brandt martin.brandt at univie.ac.at
Tue Jun 7 08:31:56 EDT 2011


Hi, 
this is a script I use for automatic smap classification for landsat images.
You only have to set the variables for the mapset, the rasters for the group
and the shapefile with training areas (and the colum to use). It's in
German, but maybe it can give you some hints...




#############################################
# überwachte SMAP Klassifikation                          #
#############################################


maps="31_10_2009"


# Eingangsraster: welche Raster kommen in die Klassifikation

raster="REF_$maps.2,REF_$maps.3,REF_$maps.4,REF_$maps.5,REF_$maps.7"



# Untergruppe

sub="sub1"




# Gruppenname der Eingangsraster
gruppe="GruppeTest_pca"

# Eingangsshape
ein="/home/martin/Dissertation/Feldaufnahmen/trainingsflaechen_linguere_utm.shp"
shape="traningsf"


# Outputraster der Trainingsflächen, damit wird weitergearbeitet
aus="trainingsflaechen"


# Ausgabeklassifikationsraster
klassifikation="TESTsmap"






g.mapset $maps


# Gruppieren der für die Klassifikation zu verwendenden Raster
i.group --verbose --o group=$gruppe subgroup=$sub input=$raster --o
i.group -l -g group=$gruppe sub=$sub


# Shape importieren
v.in.ogr dsn=$ein output=$shape --o


# Welche Klasse (Spalte) soll ausgewählt werden? 

klasse="KLASSE1"



# eine neue Spalte "id" wird angelegt und jeder Klasse eine numerische Zahl
zugewiesen
 
 v.db.select $shape
 v.db.addcol $shape col="id integer"
 v.db.select $shape
 v.db.update $shape col=id where="$klasse = 'Acker'" val=1
 v.db.update $shape col=id where="$klasse = 'Weide'" val=2
 v.db.update $shape col=id where="$klasse = 'Siedlung'" val=0
 v.db.update $shape col=id where="$klasse = 'Wasser'" val=3
 v.db.select $shape



# Vektor wird in Raster umgewandelt:
 
v.to.rast in=$shape out=$aus use=attr column=id labelcol=$klasse --o
r.stats -cpla $aus




#Generate statistics from training areas
 
i.gensigset group=$gruppe subgroup=$sub sig=Signatur maxsig=15
trainingmap=$aus --v --o



#Perform supervised SMAP classification
i.smap --o group=$gruppe subgroup=$sub sig=Signatur  out=$klassifikation



# Filter um Salt&Pepper Effekt etwas einzudämmen
r.neighbors --o method=median input=$klassifikation
output=${klassifikation}_filtered 



# Kappatest (idealerweise mit neuen Trainingsfächen)

r.kappa -w classification=$klassifikation reference=$aus


-----
Department of Geography and
Regional Research
UZA II, Althanstr. 14
1090 Wien, AUSTRIA
http://geooekologie.univie.ac.at
--
View this message in context: http://osgeo-org.1803224.n2.nabble.com/Writing-a-script-for-image-classification-tp6448874p6449330.html
Sent from the Grass - Users mailing list archive at Nabble.com.


More information about the grass-user mailing list