{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# 6.1 算法原理"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
""
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
""
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
""
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
""
]
},
{
"cell_type": "markdown",
"metadata": {
"collapsed": true
},
"source": [
""
]
},
{
"cell_type": "markdown",
"metadata": {
"collapsed": true
},
"source": [
""
]
},
{
"cell_type": "markdown",
"metadata": {
"collapsed": true
},
"source": [
""
]
},
{
"cell_type": "markdown",
"metadata": {
"collapsed": true
},
"source": [
""
]
},
{
"cell_type": "markdown",
"metadata": {
"collapsed": true
},
"source": [
""
]
},
{
"cell_type": "markdown",
"metadata": {
"collapsed": true
},
"source": [
""
]
},
{
"cell_type": "markdown",
"metadata": {
"collapsed": true
},
"source": [
""
]
},
{
"cell_type": "markdown",
"metadata": {
"collapsed": true
},
"source": [
""
]
},
{
"cell_type": "markdown",
"metadata": {
"collapsed": true
},
"source": [
""
]
},
{
"cell_type": "markdown",
"metadata": {
"collapsed": true
},
"source": [
""
]
},
{
"cell_type": "markdown",
"metadata": {
"collapsed": true
},
"source": [
""
]
},
{
"cell_type": "markdown",
"metadata": {
"collapsed": true
},
"source": [
""
]
},
{
"cell_type": "markdown",
"metadata": {
"collapsed": true
},
"source": [
""
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
""
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
""
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
""
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
""
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
""
]
},
{
"cell_type": "markdown",
"metadata": {
"collapsed": true
},
"source": [
"# 6.2 实验要求"
]
},
{
"cell_type": "markdown",
"metadata": {
"collapsed": true
},
"source": [
"(1)理解非监督聚类的基本原理和主要的算法。\n",
"\n",
"(2)能够利用python的sklearn中的聚类模块实现对遥感影像的非监督分类。"
]
},
{
"cell_type": "markdown",
"metadata": {
"collapsed": true
},
"source": [
"# 6.3 思考探索"
]
},
{
"cell_type": "markdown",
"metadata": {
"collapsed": true
},
"source": [
"(1)思考Kmean聚类算法和GMM聚类算法之间的异同?\n",
"\n",
"(2)比较在给定不同聚类类别数的情况下,分类效果之间的差异? 并分析原因。"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# 6.4 案例展示"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## 6.4.1 K-Mean聚类"
]
},
{
"cell_type": "markdown",
"metadata": {
"collapsed": true
},
"source": [
"(1)全色影像和GroundTruth"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
""
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"原始全色影像"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
""
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
" 地物类别图(GroundTruth)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"(2)K-Means聚类算法简介"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"K-Means算法思想简单,效果却很好,是最有名的聚类算法。聚类算法的步骤如下:\n",
"\n",
"1:初始化K个样本作为初始聚类中心;\n",
"\n",
"2:计算每个样本点到K个中心的距离,选择最近的中心作为其分类,直到所有样本点分类完毕;\n",
"\n",
"3:分别计算K个类中所有样本的质心,作为新的中心点,完成一轮迭代。\n",
"\n",
"通常的迭代结束条件为新的质心与之前的质心偏移值小于一个给定阈值。"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"(3)python实现关键代码"
]
},
{
"cell_type": "markdown",
"metadata": {
"ExecuteTime": {
"end_time": "2017-09-08T12:58:44.167019Z",
"start_time": "2017-09-08T12:58:35.408290Z"
}
},
"source": [
"导入所需要的主要库\n",
"\n",
"import numpy as np 数据分析处理
\n",
"import skimage.io as SKimg 读取遥感影像
\n",
"import matplotlib.pyplot as plt 绘图制图
\n",
"from sklearn.cluster import KMeans K-Means算法模块"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"读取tiff影像
\n",
"Tpan =SKimg.imread(\"F:/pythontestdata/MyTiff/tianhui1200pan.tif\")\n",
"\n",
"调用K-Means算法,设置聚类的目标类别数
\n",
"KMS = KMeans(n_clusters=6, random_state=0).fit(NewTpan);\n",
"\n",
"每个像素值的类别号,每个类别的聚类中心
\n",
"Labels=KMS.labels_; clus_centers=KMS.cluster_centers_; \n",
"\n",
"\n",
"Kwars=dict(histtype='stepfilled',alpha=0.4,normed=True,bins=np.arange(0,255));
\n",
"intervals=plt.hist(X,color=cor[S],**Kwars); 绘制灰度值的频率直方图"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"(4) 聚类效果"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"设置K-Means的聚类个数分别为4、5、6、7、8,得到五次聚类的结果。距离中心的个数等于聚类的类别数,对于全色影像,聚类后的类别中心,
\n",
"为像素灰度值,如下的频率直方图中,灰度值呈现分段聚集,每一段代表一个聚类后的类别。随着聚类个数的增多,频率直方图的分段数也增多。"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
""
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
" K=4 K=5 K=6 K=7 K=8"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"聚类结果比较:从下图可知,整体上分类效果较好,但随着聚类个数的增大,分出的类别数增多,同种地物内可能出现多个类别,导致误分错分。
\n",
"因此有必要设置较为合理的聚类数,并进行聚类后的类别合并,以及平滑等处理。"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
""
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
" K=4 K=5 K=6 K=7 K=8"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## 6.4.2 GMM聚类"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"(1) 全色影像和GroundTruth"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
""
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"原始全色影像"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
""
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"地物类别图(GroundTruth)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"(2) GMM聚类算法原理"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"混合高斯模型(Gaussian Mixture Model,简称GMM)是用高斯概率密度函数(正态分布曲线)精确地量化事物,
\n",
"将一个事物分解为若干的基于高斯概率密度函数(正态分布曲线)形成的模型。"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
""
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
""
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
""
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"(3)python实现关键代码"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"导入所需要的主要库\n",
"\n",
"import numpy as np 数据分析处理
\n",
"import skimage.io as SKimg 读取遥感影像
\n",
"import matplotlib.pyplot as plt 绘图制图
\n",
"from sklearn import mixture 高斯模型\n",
"\n",
"\n",
"\n",
"读取tiff影像
\n",
"Tpan =SKimg.imread(\"F:/pythontestdata/MyTiff/tianhui1200pan.tif\")\n",
"\n",
"调用GMM算法,设置聚类的目标类别数
\n",
"GMMmy = mixture.GaussianMixture(n_components=6,covariance_type='full').fit(NewTpan);\n",
"\n",
"每个像素值的类别号,每个类别的聚类中心
\n",
"Labels=GMMmy.predict(NewTpan); Clus_Centers=GMMmy.means_;\n",
"\n",
"\n",
"Kwars=dict(histtype='stepfilled',alpha=0.4,normed=True,bins=np.arange(0,255));
\n",
"intervals=plt.hist(X,color=cor[S],**Kwars); 绘制灰度值的频率直方图"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"(4)聚类效果"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"设置K-Means的聚类个数分别为4、5、6、7、8,得到五次聚类的结果。距离中心的个数等于聚类的类别数,对于全色影像,聚类后的类别中心,
\n",
"为像素灰度值,如下的频率直方图中,灰度值呈现分段聚集,每一段代表一个聚类后的类别。随着聚类个数的增多,频率直方图的分段数也增多。"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
""
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
" K=4 K=5 K=6 K=7 K=8"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"GMM聚类的效果与K-Means的效果相似,也是整体上分类效果较好,但随着聚类个数的增大,分出的类别数增多,同种地物内可能出现多个类别,导致误分错分。"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
""
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
" K=4 K=5 K=6 K=7 K=8"
]
}
],
"metadata": {
"anaconda-cloud": {},
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.4"
},
"toc": {
"colors": {
"hover_highlight": "#DAA520",
"navigate_num": "#000000",
"navigate_text": "#333333",
"running_highlight": "#FF0000",
"selected_highlight": "#FFD700",
"sidebar_border": "#EEEEEE",
"wrapper_background": "#FFFFFF"
},
"moveMenuLeft": true,
"nav_menu": {
"height": "12px",
"width": "252px"
},
"navigate_menu": true,
"number_sections": true,
"sideBar": true,
"threshold": 4,
"toc_cell": false,
"toc_position": {
"height": "530px",
"left": "0px",
"right": "1148px",
"top": "106px",
"width": "212px"
},
"toc_section_display": "block",
"toc_window_display": true,
"widenNotebook": false
}
},
"nbformat": 4,
"nbformat_minor": 2
}