|
|
(15 intermediate revisions by 3 users not shown) |
Line 1: |
Line 1: |
− | :''In this article, you will learn how to classify a landscape raster via k-means clustering''
| + | ==Unsupervised K-Means classification== |
| + | * In the search engine of the Processing Toolbox, type {{typed|text=kmeans}} and double click '''KMeansClassification''' of OTB. |
| + | * Specify a multispectral image as Input Image. |
| + | * Specify directory and name for the Output image. Select the output data type {{button|text=uint 8}} from the pull-down list. |
| + | * Set the {{button|text=Number of classes}} to {{typed|text=20}} |
| + | * Check the {{button|text=Training set size}} to {{typed|text=10000}} |
| + | * Output pixel type: {{typed|text=uint8}} |
| + | * Click on {{button|text=Run}}. |
| + | [[File:qgis_otb_kmeans.png|400px]] |
| | | |
− | {| class='wikitable floatright'
| + | * Load the resulting image into QGIS. It is single band file with 20 grey levels labeled from 0 to 19. |
− | |+Table A
| + | * {{mitem|text=Layer Properties --> Symbology --> Render type}}. Switch to {{button|text=Singleband pseudocolor}} and select a '''Color ramp''' (e.g. Spectral). Select the '''Mode''' {{button|text=Equal interval}} and set the number of classes to {{typed|text=20}} |
− | |-
| + | |
− | !Code
| + | |
− | !Name
| + | |
− | !Cluster number
| + | |
− | !RGB color
| + | |
− | |-
| + | |
− | |1
| + | |
− | |Urban area
| + | |
− | |10,9,15
| + | |
− | |230-000-077
| + | |
− | |-
| + | |
− | |2
| + | |
− | |Cropland
| + | |
− | |16,0,13,3,7,17,18
| + | |
− | |255-255-268
| + | |
− | |-
| + | |
− | |3
| + | |
− | |Pastures/grassland
| + | |
− | |12,8
| + | |
− | |230-230-077
| + | |
− | |-
| + | |
− | |4
| + | |
− | |Broadleave forest
| + | |
− | |6,2,5,4
| + | |
− | |128-255-000
| + | |
− | |-
| + | |
− | |5
| + | |
− | |Coniferous forest
| + | |
− | |11,19
| + | |
− | |000-166-000
| + | |
− | |-
| + | |
− | |6
| + | |
− | |Water bodies
| + | |
− | |14
| + | |
− | |128-242-230
| + | |
− | |-
| + | |
− | |7
| + | |
− | |Cloud
| + | |
− | |1
| + | |
− | |255-255-255
| + | |
− | |}
| + | |
− | # Classifying an image
| + | |
− | ## Add the raster layer ''188_pca_indices.tif'' into a [[QGIS]] project. It should be available in the [[Course data|course data]] (see [[Exercise 06: Digitizing training and test areas|previous exercise]]).
| + | |
− | ## Open the k-means classification algorithm provided by the Orfeo toolbox. It can be found in the processing toolbar under {{mitem|text=Toolbox --> Orfeo Toolbox --> Learning --> Unsupervised KMeans image classification}} (see figure '''A''').
| + | |
− | ##* Set the ''188_pca_indices'' layer as {{button|text=Input image}}
| + | |
− | ##* Set the {{button|text=Number of classes}} to 20 and the {{button|text=Number of iterations}} to 1000.
| + | |
− | ##* The {{button|text=Convergence threshold}} should be set at 0.0001.
| + | |
− | ##* Leave all other configurations as they are and click {{button|text=Run}}. The resulting image has 20 classes, labeled from 0 to 19.
| + | |
− | # Image symbology
| + | |
− | ## Right-click the classified layer in the [[TOC]] and select {{mitem|text=Properties --> Style}} (see figure '''B''').
| + | |
− | ## Set the {{button|text=Render type}} to {{button|text=Singleband pseudocolor}}.
| + | |
− | ## Set {{button|text=Color interpolation}} to {{button|text=Discrete}}.
| + | |
− | ## Set the {{button|text=Mode}} to {{button|text=Equal interval}} with 20 classes and confirm with {{button|text=Classify}}.
| + | |
− | ## In the {{button|text=Load min/max}} section, select tbe {{button|text=Min/max}} radio button and click {{button|text=Load}} to update the range for classification.
| + | |
− | ## Confirm with {{button|text=Apply}} or click {{button|text=OK}} if you are content with your settings.
| + | |
− | # Create a land use/cover classification scheme table as in table '''A'''.
| + | |
− | ## As a reference, you may add a google layer to the project:<br/> {{mitem|text=Plugins --> ObenLayers plugin --> Add Google Satellite layer}}.
| + | |
− | ## Set the coordinate reference system
| + | |
− | ## Open {{mitem|text=Project --> Project properties}}.
| + | |
− | ## Set {{button|text=WGS 84 Pseudo Mercator}} ({{button|text=EPSG 3857}}) as coordinate system
| + | |
− | ## Check the {{button|text=Enable on the fly transformation}} box
| + | |
− | ## Right click {{button|text=188_pca_indices}} in the [[TOC]] and select {{button|text=Set Project CRS from layer}}.
| + | |
− | ## Order the maps in the [[TOC]] so that the classified layer lies above the Google Maps layer.
| + | |
− | ## Now, zoom in to some section of the classified layer where the classes can easily be distinguished.
| + | |
− | ## Activate and de-activate the layer in the [[TOC]] and compare to the Google layer in order to get an idea of the classes.
| + | |
− | ## While doing so, create a table displaying which classes in the classified layer may represent the classes in table '''A'''. You can write it down on a sheet of paper or save it as a text file on your computer.
| + | |
− | # Change the grid values
| + | |
− | ## Select {{mitem|text=Saga --> Grid-Tools --> Change grid values}} from the {{button|text=Processing}} toolbox.
| + | |
− | ##* As {{button|text=Grid}}, select the output map from the previous step.
| + | |
− | ##* From the {{button|text=Replace condition}} pulldown menu, select {{button|text=[2] Low value <= grid value < high value}}.
| + | |
− | ##* Now, open the lookup menu table ({{button|text=...}}) and enter the values you have written down in the previous step.
| + | |
− | ##* Set path and name of the output file and launch the algorithm with {{button|text=Run}}.
| + | |
− | # Assign discrete colors to the land cover layer (figure '''C''').
| + | |
− | ## Right click the layer in the [[TOC]] or double click to open the layer {{button|text=Properties}}.
| + | |
− | ## Select the {{button|text=Style}} tab and set the following options:
| + | |
− | ##* For {{button|text=Render type}} select {{button|text=Singleband pseudocolor}}
| + | |
− | ##* For {{button|text=Color interpolation}}, select {{button|text=Discrete}}
| + | |
− | ##* Set {{button|text=Mode}} to {{button|text=Equal interval}} and {{button|text=Classes}} to 7.
| + | |
− | ##* Set {{button|text=Load min/max values}} to {{button|text=Min/max}}.
| + | |
− | ##* For better interpretation, you can edit the {{button|text=Label}} column in the classes section according to the class names in table '''A'''.
| + | |
− | ##* Don't forget to click {{button|text=Classify}} for adding the classes.
| + | |
− | ## Click {{button|text=Load}} and confirm with {{button|text=Apply}} or {{button|text=OK}}.
| + | |
− | | + | |
− | ==Figures==
| + | |
− | {| class="wikitable" style="border:0pt"
| + | |
− | |style="border:0pt"|[[Image:RemSens_Exercise07_01.png|thumb|450px|'''Figure A:''' Dialogue of the ''Unsupervised K-Means image classification'' plugin from the Orfeo toolbox in [[QGIS]].]]
| + | |
− | |style="border:0pt"|[[Image:RemSens_Exercise07_02.png|thumb|450px|'''Figure B:''' Land cover map produced by the k-means clustering algorithm.]]
| + | |
− | |-
| + | |
− | |style="border:0pt"|[[Image:RemSens_Exercise07_03.png|thumb|450px|'''Figure C:''' Land cover map produced by the k-means clustering algorithm in discrete colors.]]
| + | |
− | |}
| + | |
− | | + | |
− | [[Category:Image classification]]
| + | |