User Tools

Site Tools


wikistud:mat2017_mariannestoesel

Biotope Mapping from Orthophoto

Some steps to produce a grayscale product, an NDVI product. Then how to stack bands together to finally perform segmentation on Orfeotoolbox.

#!/bin/bash
#Set up the directory
DIR=~/ost4sem/Selection_Stockholm/Raw
cd $DIR
 
#Let's do a subset of an ortho-photo
gdal_translate  -srcwin 0 0 1000 1000 -co ZLEVEL=9 -co COMPRESS=DEFLATE   $DIR/ortoIr025_3006_6564469_648766.tif  $DIR/ortoIr025_3006_6564469_648766_subset.tif
 
#Grayscale production
gdal_calc.py -A $DIR/ortoIr025_3006_6564469_648766_subset.tif \\
--A_band=1 -B $DIR/ortoIr025_3006_6564469_648766_subset.tif  \\
--B_band=2 -C $DIR/ortoIr025_3006_6564469_648766_subset.tif \\
--C_band=3   --outfile=$DIR/ortoIr025_3006_6564469_648766_grayscale.tif \\
--calc="(A.astype(float)+B.astype(float)+C.astype(float))/3"  \\
--co=ZLEVEL=9 --co=COMPRESS=DEFLATE   --overwrite --type=Float32
 
#This is for NDVI
gdal_calc.py -A $DIR/ortoIr025_3006_6564469_648766_subset.tif --A_band=2 -B $DIR/ortoIr025_3006_6564469_648766_subset.tif --B_band=1 --outfile=$DIR/ortoIr025_3006_6564469_648766_ndvi.tif --calc="((B.astype(float)-A.astype(float))/(B.astype(float)+A.astype(float)+0.00000001))" --co=ZLEVEL=9 --co=COMPRESS=DEFLATE --overwrite --type=Float32
 
#Stack the bands into a vrt
gdalbuildvrt -separate -overwrite $DIR/ortoIr025_3006_6564469_648766_compo.vrt $DIR/ortoIr025_3006_6564469_648766_subset.tif $DIR/ortoIr025_3006_6564469_648766_ndvi.tif
 
#Produce a segmentation
otbcli_Segmentation -in $DIR/ortoIr025_3006_6564469_648766_compo.vrt -mode vector -mode.vector.out SegmentationVector.shp  -filter meanshift -mode.vector.tilesize 2667
wikistud/mat2017_mariannestoesel.txt · Last modified: 2017/06/23 10:55 by new_ost4sem_admin