KMeansClassification¶
非监督KMeans图像分类
描述¶
无监督KMeans图像分类。这是一个复合应用程序,使用现有的培训和分类应用程序。使用的是SharkKMeans模型。
仅当使用Shark支持(CMake选项)编译OTB时,此应用程序才可用 OTB_USE_SHARK=ON
)。
此复合应用程序的步骤如下:
- ImageEnvelope :创建Shapefile(1个多边形),
- PolygonClassStatistics :计算统计数据,
- SampleSelection :在Shapefile中按常量策略选择样本(最多1000000个样本),
- SampleExtraction :提取样本描述符(更新 SampleSelection 输出文件)、
- ComputeImagesStatistics :计算图像的二阶统计量,
- TrainVectorClassifier :训练SharkKMeans模型,
- ImageClassifier :根据模型文件对输入图像进行分类。
可以选择随机/周期模式 SampleSelection 申请。如果不想保留临时文件(选定样本、模型文件等),请初始化清理参数。有关Shark KMeans算法的更多信息 [1] 。
参数¶
Input Image -in image
Mandatory
Input image filename.
Output Image -out image [dtype]
Mandatory
Output image containing class labels
Number of classes -nc int
Default value: 5
Number of modes, which will be used to generate class membership.
Training set size -ts int
Default value: 100
Size of the training set (in pixels).
Maximum number of iterations -maxit int
Default value: 1000
Maximum number of iterations for the learning step. If this parameter is set to 0, the KMeans algorithm will not stop until convergence
质心IO参数¶
质心IO的参数组。
input centroids text file -centroids.in filename [dtype]
Input text file containing centroid positions used to initialize the algorithm. Each centroid must be described by p parameters, p being the number of bands in the input image, and the number of centroids must be equal to the number of classes (one centroid per line with values separated by spaces).
Output centroids text file -centroids.out filename [dtype]
Output text file containing centroids after the kmean algorithm.
Available RAM (MB) -ram int
Default value: 256
Available memory for processing (in MB).
Sampler type -sampler [periodic|random]
Default value: periodic
Type of sampling (periodic, pattern based, random)
- Periodic sampler
Takes samples regularly spaced - Random sampler
The positions to select are randomly shuffled.
周期性采样器选项¶
Jitter amplitude -sampler.periodic.jitter int
Default value: 0
Jitter amplitude added during sample selection (0 = no jitter)
Validity Mask -vm image
Validity mask, only non-zero pixels will be used to estimate KMeans modes.
Label mask value -nodatalabel int
Default value: 0
By default, hidden pixels will have the assigned label 0 in the output image. It's possible to define the label mask by another value, but be careful to not take a label from another class. This application initializes the labels from 0 to N-1, N is the number of class (defined by 'nc' parameter).
Clean-up of temporary files -cleanup bool
Default value: true
If activated, the application will try to clean all temporary files it created
Random seed -rand int
Set a specific random seed with integer value.
实例¶
从命令行执行以下操作:
otbcli_KMeansClassification -in QB_1_ortho.tif -ts 1000 -nc 5 -maxit 1000 -out ClassificationFilterOutput.tif uint8
来自Python的评论:
import otbApplication
app = otbApplication.Registry.CreateApplication("KMeansClassification")
app.SetParameterString("in", "QB_1_ortho.tif")
app.SetParameterInt("ts", 1000)
app.SetParameterInt("nc", 5)
app.SetParameterInt("maxit", 1000)
app.SetParameterString("out", "ClassificationFilterOutput.tif")
app.SetParameterOutputImagePixelType("out", 1)
app.ExecuteAndWriteOutput()
局限性¶
应用程序不支持输入图像中的NAN