5

I try to apply k-means clustering in qgis console like below shown in this site.Unsupervised KMeans image classification

processing.runalg('otb:unsupervisedkmeansimageclassification', 'D:\data\sub_66', 128,100, 5, 1000, 0.0001, 'D:\data\sub_66kmeans')

but it gives error like this. error screenshot

3

Your error is probably due to OTB not being installed. You can check this by going to:

Processing > Options... > Providers 

And look for Orfeo Toolbox (Image analysis). If no paths are set then you may need to install it. A recent question was asked on how to install this: How to configure Orfeo toolbox in QGIS 2.18 on Windows 7 32-Bit?


Once it is installed, you could then run your code. However, there are some things to notice:

  • Use either forward slashes or double-back slashes when defining paths.
  • You may also need to include the extension of the file (e.g. 'D:/data/sub_66.tif').
  • Optional parameters (e.g. Validity Mask) need to be defined. But if you don't want to include it in the analysis, use None.
  • There are two outputs: an image and a file (I specified it as a .txt file). These also should be included.

This is the code I used to produce the two outputs:

import processing
processing.runalg("otb:unsupervisedkmeansimageclassification",'D:/data/sub_66.tif', 128, None, 100, 5, 1000, 0.0001, 'D:/data/sub_66k_means.tif', 'D:/data/sub_66k_centroid.txt')

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.