A Practical Guide of Mean-Shift Segmentation using OTB

Introduction

TBD

Data

In order to have a consistent scale for the radiometric radius, better use a PCA transform with linear stretching
to the 0 - 255 interval (saved as INT1U) and keeping 0 for NA.
In this example we use ROI_7.tif, which is subscene of BertMICA20190531v2PCATrescS.tif

Naming convention

In order to record the choice of radii in the result name itself, use:
inputname_r*_s*_R*_S*.*
r: MS rannger
s: MS spatialr
R: LSMSS ranger
S: LSMSS spatialr

Mean Shift filter

Test a range of radiometric (ranger) and spatial (spatialr) radii

Keep spatialr = 5
Vary ranger = 5, 10, 25

otbcli_MeanShiftSmoothing -in ROI_7.tif -fout ROI_7_r5_s5.tif uint8 -foutpos ROI_7_r5_s5_spat.tif  -ranger 5 -spatialr 5 -maxiter 100 -modesearch 0
otbcli_MeanShiftSmoothing -in ROI_7.tif -fout ROI_7_r10_s5.tif uint8 -foutpos ROI_7_r10_s5_spat.tif  -ranger 10 -spatialr 5 -maxiter 100 -modesearch 0
otbcli_MeanShiftSmoothing -in ROI_7.tif -fout ROI_7_r25_s5.tif uint8 -foutpos ROI_7_r25_s5_spat.tif  -ranger 25 -spatialr 5 -maxiter 100 -modesearch 0

Keep spatialr = 10
Vary ranger = 5, 10, 25

otbcli_MeanShiftSmoothing -in ROI_7.tif -fout ROI_7_r5_s10.tif uint8 -foutpos ROI_7_r5_s10_spat.tif  -ranger 5 -spatialr 10 -maxiter 100 -modesearch 0
otbcli_MeanShiftSmoothing -in ROI_7.tif -fout ROI_7_r10_s10.tif uint8 -foutpos ROI_7_r10_s10_spat.tif  -ranger 10 -spatialr 10 -maxiter 100 -modesearch 0
otbcli_MeanShiftSmoothing -in ROI_7.tif -fout ROI_7_r25_s10.tif uint8 -foutpos ROI_7_r25_s10_spat.tif  -ranger 25 -spatialr 10 -maxiter 100 -modesearch 0

Keep spatialr=30
Vary ranger = 5, 10, 25

otbcli_MeanShiftSmoothing -in ROI_7.tif -fout ROI_7_r5_s30.tif uint8 -foutpos ROI_7_r5_s30_spat.tif  -ranger 5 -spatialr 30 -maxiter 100 -modesearch 0
otbcli_MeanShiftSmoothing -in ROI_7.tif -fout ROI_7_r10_30.tif uint8 -foutpos ROI_7_r10_s30_spat.tif  -ranger 10 -spatialr 30 -maxiter 100 -modesearch 0
otbcli_MeanShiftSmoothing -in ROI_7.tif -fout ROI_7_r25_s30.tif uint8 -foutpos ROI_7_r25_s30_spat.tif  -ranger 25 -spatialr 30 -maxiter 100 -modesearch 0

Display and visually compare the fout images (not the foutpos) in QGIS, fist by groups and then among groups.
Note that while spatialr has a notorius effect in processing time, the result is mucho more sensitive to ranger


LMSSegmentation

In this step, another pair of radii must be specified. According to the manual, half the value of those used in MeanShift filter is a good start, but a range must be explored.
Assuming the previous step has narrowed the options to ROI_7_r25_s5.tif and ROI_7_r25_s10.tif, we can try:

r25_s5_R13_S2
r25_s5_R13_S5
r25_s5_R25_S2
r25_s5_R25_S5

and

r25_s10_R13_S5
r25_s10_R13_S10
r25_s10_R25_S5
r25_s10_R25_S10

As the number of 1-pixel final segments is an indicator of poor segmentation, we initially keep minsize=0, so that we can assess the quality. Once one or few options have been selected, we can repeat with minsize>0
for only those options

We run both the LMSS and the vectorization and the vectorization, and display the vector on top of the original image.
For the first option (r25_s5_R13_S2):

#r25_s5_R13_S2
otbcli_LSMSSegmentation -in ROI_7_r25_s5.tif -inpos ROI_7_r25_s5_spat.tif \
	-out  segmentation.tif uint32 \
	-ranger 13 \
	-spatialr 5 \
	-minsize 0 
otbcli_LSMSVectorization -in ROI_7_r25_s5.tif -inseg segmentation.tif -out ROI_7_r25_s5_R13_S2_m0.shp

and equivalently for the rest of options.
Display the vector layers as unfilled polygons on top of the input ROI_7
Once one or few options have been selected, re-run with -minsize=5 (at least) for only those options.

Evaluation

(To Be Completed)
Visual inspection cannot be the only criterium. We define the following quantitative metrics:

Average Euclidean distance between result and original image


Size distribution of segments


HooverCompareSegmentation

$ otbcli_HooverCompareSegmentation -ingt maur_GT.tif -inms maur_labelled.tif -th 0.75 -outgt maur_colored_GT.tif uint8 -outms maur_colored_seg.tif uint8
Output parameters value:

rc green Correct detection score : 0.5116558075
rf magenta Over-segmentation score: 0.1068047211
ra cyan Under-segmentation score: 0.03841182217
rm red Missed detection score : 0.1943036467

//Test data://



Backlinks: Home:Work:08ClasesySeminarios:MASTER CREAF:2021:TFMs:LeonardoTorijano