首页 > 其他分享 >多光谱遥感分类(四):使用GLCM+RF

多光谱遥感分类(四):使用GLCM+RF

时间:2022-10-26 21:34:05浏览次数:50  
标签:__ res print 遥感 GLCM RF test import dir


所用数据:​​多光谱遥感分类:使用CNN1(一)​

提取纹理特征。


import numpy as np
import cv2
import os
from skimage.feature import greycomatrix, greycoprops
import pandas as pd


def get_inputs(s):
res=[]
input = cv2.imread(s,cv2.IMREAD_GRAYSCALE)
glcm = greycomatrix(input, [1,2,8,16], [0,np.pi/4,np.pi/2,np.pi*3/4], 256, symmetric=True, normed=True)

for prop in {'contrast', 'dissimilarity', 'homogeneity', 'energy', 'correlation', 'ASM'}:
temp=greycoprops(glcm, prop)
# temp=np.array(temp).reshape(-1)
# print(prop,temp)
res.append(temp)

res=np.array(res).reshape(-1)
return res#feather

def ext():
res=[]
org_dir="data/org/"

for dir in os.listdir(org_dir):
for d in os.listdir(org_dir + dir):
print("dealing %s" % (org_dir+dir+"/"+d))
feather=get_inputs(org_dir+dir+"/"+d)
res.append(np.concatenate((feather,[dir])))

df=pd.DataFrame(res)
df.to_csv("data/feather.txt",header=False,index=None)

if __name__ == '__main__':
ext()

RF分类。

from osgeo import gdal
import numpy as np
import shapefile
import cv2
import matplotlib.pyplot as plt
import pandas as pd
from sklearn.ensemble import RandomForestClassifier
from sklearn.metrics import confusion_matrix
from sklearn.model_selection import train_test_split
from sklearn.preprocessing import LabelEncoder


def rf_classify():
data = pd.read_csv("data/feather.txt", header=None)

x=data.iloc[:, :-1]
print(x[:5])

y = data.iloc[:, -1].values
y = LabelEncoder().fit_transform(y).reshape(-1, 1)
print(y[:5])
# print(LabelEncoder().fit(y).inverse_transform([0, 1,2]))

X_train, X_test, y_train, y_test = train_test_split(x, y, test_size=0.33, random_state=2018)
clf = RandomForestClassifier(n_estimators=10, )
clf.fit(X_train, y_train)

score = clf.score(X_test, y_test)
print(score)
m = clf.predict(X_test)
print(confusion_matrix(y_test, m))
# joblib.dump(clf, "output/rf_model.pkl")


if __name__ == '__main__':

rf_classify()


标签:__,res,print,遥感,GLCM,RF,test,import,dir
From: https://blog.51cto.com/u_15847885/5798583

相关文章

  • nrf52840 设置128bit服务uuid
    sdk版本:nRF5_SDK_17.1.0_ddde560主要更改以下函数:uint32_tble_nus_init(ble_nus_t*p_nus,ble_nus_init_tconst*p_nus_init){ret_code_terr_code;b......
  • hyperf/go/springboot通过jsonrpc通信
    一、背景随着用户的增长和业务的增多,单节点服务已经满足不了需求,用hyperf对主业务进行了重构。hyperf是一个后现代的php框架,基于php+swoole,支持协程,解决了php让人诟病的......
  • cmake 设置属性INTERFACE_INCLUDE_DIRECTORIES,则其它库可以直接 target_link_librarie
    rs项目改为cpm下载项目 leveldb和basiccache,basiccache依赖leveldb,下载都是在主项目中,设置 INTERFACE_INCLUDE_DIRECTORIES后,在basiccache中都不需要find_packa......
  • drf--ViewSet -第二波 进阶版
    https://www.bilibili.com/video/BV1z5411D7BQ?p=19&vd_source=caabcbd2a759a67e2a3de8acbaaf08eaview.pyfromsers.modelsimportBookfromrest_frameworkimportse......
  • 前端性能优化——Performance的使用攻略
    博客地址:https://blog.51cto.com/u_15091652/2603170Performance是Chrome浏览器自带的性能监测工具。根据我的使用,简单理解就是我们可以通过它录制一段时间的浏览器活动,通......
  • 【2022.10.25】尝试自写一个Dockerfile
    前言用了别人这么多的docker,因为mirai的旧版本登不上了这次要自写一个docker了因为mirai运行在openjdk环境下运行,所以首先最开始的内容便是FROMopenjdk:17-slim-buster......
  • tensorflow中session的用法,莫烦的例子(2)
    importtensorflowastf#创建两个矩阵maxtrix,然后输出两个矩阵相乘的结果matrix1=tf.constant([[3,3]])#constant表示maxtrix1是一个常数,[3,3]表示是一个一行两列的......
  • Django drf 排序
    Djangodrf排序18.1全局配置配置排序类REST_FRAMEWORK={......'DEFAULT_FILTER_BACKENDS':('rest_framework.filters.OrderingFilte......
  • Django drf 分页
    Djangodrf分页19.1全局配置配置分页类REST_FRAMEWORK={......#分页#'DEFAULT_PAGINATION_CLASS':'rest_framework.pagination.LimitOf......
  • drf 异常处理
    异常处理20.1异常示例视图classExceptionView(APIView):defget(self,request):a=1/0returnResponse({"message":"ok"})路由fromdja......