前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >Google Earth Engine——无人机影像进行分类处理

Google Earth Engine——无人机影像进行分类处理

作者头像
此星光明
发布2024-02-02 13:30:52
1510
发布2024-02-02 13:30:52
举报

本次我们是利用无人机影像采集的影像数据,对特征点的一些特征进行提取分析,然后再加载的矢量转化的过程中出现了以下问题,主要是超限,另外还有几个函数可以

ee.Algorithms.Image.Segmentation.seedGrid(size, gridType) 选择用于聚类的种子像素。

参数。 size(整数,默认:5)。 超级像素的种子位置间距,单位是像素。

gridType(字符串,默认为 "方形")。 网格的类型。正方形 "或 "六角形 "之一。

返回。图像

ee.Algorithms.Image.Segmentation.SNIC(image, size, compactness, connectivity, neighborhoodSize, seeds) 基于SNIC(简单非迭代聚类)的超级像素聚类。输出一个群集ID的频段和每个输入频段的每一个群集的平均数。如果没有提供 "种子 "图像作为输入,输出将包括一个包含生成的种子位置的 "种子 "带。见。Achanta, Radhakrishna和Susstrunk, Sabine,"使用简单非迭代聚类的超级像素和多边形",CVPR,2017。

参数。 image(图像)。 用于聚类的输入图像。

size(整数,默认:5)。 超级像素种子位置的间隔,单位是像素。如果提供 "种子 "图像,则不产生网格。

compactness(浮点数,默认为1)。 紧凑度系数。较大的数值会使集群更加紧凑(方形)。将此设置为0会使空间距离加权失效。

connectivity(整数,默认:8)。 连通性。4或8都可以。

neighborhoodSize(整数,默认为空)。 瓦片邻域大小(避免瓦片边界伪影)。默认为2*大小。

seeds(图像,默认为空)。 如果提供,任何非零值的像素都被用作种子位置。相互接触的像素(由 "连通性 "指定)被认为属于同一个集群。

返回。图像

ee.Reducer.countEvery()

Returns a Reducer that computes the number of inputs.

No arguments.
Returns: Reducer

返回一个计算输入数的Reducer。

代码:

代码语言:javascript
复制
var image = ee.Image("users/carloseduardotpa/20220524_120405_70_2420_3B_AnalyticMS_SR_harmonized_clip"),
    image2 = ee.Image("users/carloseduardotpa/20220524_123706_08_247a_3B_AnalyticMS_SR_harmonized_clip"),
    geometry = /* color: #d63000 */ee.Geometry.Point([-40.54259265059659, -6.016601660731103]),
    imageVisParam = {"opacity":1,"bands":["b3","b2","b1"],"min":128.03750796620568,"max":1076.3051816022903,"gamma":1},
    imageVisParam3 = {"opacity":1,"bands":["NDVI"],"min":0.6314883263385151,"max":0.7761275808135806,"palette":["ffaf36","e4ff00","e4ff00","3fff00","0d5200"]},
    imageVisParam2 = {"opacity":1,"bands":["NDWI"],"palette":["0014ff","0008ff","ffffff","ffffff","ffffff"]},
    geometry2 = /* color: #98ff00 */ee.Geometry.Polygon(
        [[[-40.734193066483385, -5.88076230086368],
          [-40.74655282540109, -5.949061950684604],
          [-40.76852572839501, -6.041935853033961],
          [-40.73556793142542, -6.069248829219161],
          [-40.69608514238394, -6.077783746890778],
          [-40.70398003077222, -6.098608282157076],
          [-40.7067267731158, -6.201013709903857],
          [-40.53643718870099, -6.245383017974462],
          [-40.42657275574691, -6.26722502184506],
          [-40.40871980972078, -6.186678054545768],
          [-40.42468449271024, -6.149813484456435],
          [-40.494551398971105, -6.09519462520748],
          [-40.506573168915246, -5.967153831615714],
          [-40.557036784806705, -5.915596194510558]]]),
    caa_arb = /* color: #007727 */ee.FeatureCollection(
        [ee.Feature(
            ee.Geometry.Point([-40.61472878477397, -5.999477179310845]),
            {
              "class": 1,
              "system:index": "0"
            }),
        ee.Feature(
            ee.Geometry.Point([-40.593743181441454, -6.000202743765224]),
            {
              "class": 1,
              "system:index": "1"
            }),
        ee.Feature(
            ee.Geometry.Point([-40.60811982176128, -6.000373464672966]),
            {
              "class": 1,
              "system:index": "2"
            }),
        ee.Feature(
            ee.Geometry.Point([-40.577190098673604, -6.001875373780318]),
            {
              "class": 1,
              "system:index": "3"
            }),
        ee.Feature(
            ee.Geometry.Point([-40.58461445322683, -6.0072658374835015]),
            {
              "class": 1,
              "system:index": "4"
            }),
        ee.Feature(
            ee.Geometry.Point([-40.55150596948877, -6.01029978014366]),
            {
              "class": 1,
              "system:index": "5"
            }),
        ee.Feature(
            ee.Geometry.Point([-40.55034725519434, -6.00769632793069]),
            {
              "class": 1,
              "system:index": "6"
            }),
        ee.Feature(
            ee.Geometry.Point([-40.544467853033694, -6.006928093751045]),
            {
              "class": 1,
              "system:index": "7"
            }),
        ee.Feature(
            ee.Geometry.Point([-40.54154960962549, -6.0032303532113795]),
            {
              "class": 1,
              "system:index": "8"
            }),
        ee.Feature(
            ee.Geometry.Point([-40.56099831199146, -5.995566946720059]),
            {
              "class": 1,
              "system:index": "9"
            }),
        ee.Feature(
            ee.Geometry.Point([-40.569655926048405, -5.987183934104295]),
            {
              "class": 1,
              "system:index": "10"
            }),
        ee.Feature(
            ee.Geometry.Point([-40.58163888245139, -5.982012631158508]),
            {
              "class": 1,
              "system:index": "11"
            }),
        ee.Feature(
            ee.Geometry.Point([-40.5962300994924, -5.981329724241203]),
            {
              "class": 1,
              "system:index": "12"
            }),
        ee.Feature(
            ee.Geometry.Point([-40.594743753807954, -5.978198419467451]),
            {
              "class": 1,
              "system:index": "13"
            }),
        ee.Feature(
            ee.Geometry.Point([-40.558571907061, -5.972833484321754]),
            {
              "class": 1,
              "system:index": "14"
            }),
        ee.Feature(
            ee.Geometry.Point([-40.562747854044915, -5.979799814659621]),
            {
              "class": 1,
              "system:index": "15"
            }),
        ee.Feature(
            ee.Geometry.Point([-40.55548757574285, -5.982676242602119]),
            {
              "class": 1,
              "system:index": "16"
            }),
        ee.Feature(
            ee.Geometry.Point([-40.539282822268035, -5.987507044661501]),
            {
              "class": 1,
              "system:index": "17"
            }),
        ee.Feature(
            ee.Geometry.Point([-40.52296993660863, -6.013106640673962]),
            {
              "class": 1,
              "system:index": "18"
            }),
        ee.Feature(
            ee.Geometry.Point([-40.52657482552465, -6.014130941042587]),
            {
              "class": 1,
              "system:index": "19"
            }),
        ee.Feature(
            ee.Geometry.Point([-40.513791741604955, -6.000380384356329]),
            {
              "class": 1,
              "system:index": "20"
            }),
        ee.Feature(
            ee.Geometry.Point([-40.50655334808754, -5.990581624070123]),
            {
              "class": 1,
              "system:index": "21"
            }),
        ee.Feature(
            ee.Geometry.Point([-40.52696833509857, -5.985594671183795]),
            {
              "class": 1,
              "system:index": "22"
            }),
        ee.Feature(
            ee.Geometry.Point([-40.5382857486324, -5.97151929875015]),
            {
              "class": 1,
              "system:index": "23"
            }),
        ee.Feature(
            ee.Geometry.Point([-40.53597624830496, -5.972502083379403]),
            {
              "class": 1,
              "system:index": "24"
            }),
        ee.Feature(
            ee.Geometry.Point([-40.5429714494158, -5.961746013654573]),
            {
              "class": 1,
              "system:index": "25"
            }),
        ee.Feature(
            ee.Geometry.Point([-40.57045216596371, -5.962153475508229]),
            {
              "class": 1,
              "system:index": "26"
            }),
        ee.Feature(
            ee.Geometry.Point([-40.57357344827358, -5.948277811806232]),
            {
              "class": 1,
              "system:index": "27"
            }),
        ee.Feature(
            ee.Geometry.Point([-40.59519031448845, -5.9552281472769035]),
            {
              "class": 1,
              "system:index": "28"
            }),
        ee.Feature(
            ee.Geometry.Point([-40.59467533035759, -5.951600017243889]),
            {
              "class": 1,
              "system:index": "29"
            }),
        ee.Feature(
            ee.Geometry.Point([-40.611278222786375, -5.948883380657802]),
            {
              "class": 1,
              "system:index": "30"
            }),
        ee.Feature(
            ee.Geometry.Point([-40.620004606531914, -5.940290626698926]),
            {
              "class": 1,
              "system:index": "31"
            }),
        ee.Feature(
            ee.Geometry.Point([-40.62893099813348, -5.9381136924372555]),
            {
              "class": 1,
              "system:index": "32"
            }),
        ee.Feature(
            ee.Geometry.Point([-40.643802767922345, -5.934406499158915]),
            {
              "class": 1,
              "system:index": "33"
            }),
        ee.Feature(
            ee.Geometry.Point([-40.63875415034747, -5.924111561319655]),
            {
              "class": 1,
              "system:index": "34"
            }),
        ee.Feature(
            ee.Geometry.Point([-40.62173635970382, -5.913982454402268]),
            {
              "class": 1,
              "system:index": "35"
            }),
        ee.Feature(
            ee.Geometry.Point([-40.61555050355231, -5.927437751477383]),
            {
              "class": 1,
              "system:index": "36"
            }),
        ee.Feature(
            ee.Geometry.Point([-40.63903570504281, -5.9452794312102615]),
            {
              "class": 1,
              "system:index": "37"
            }),
        ee.Feature(
            ee.Geometry.Point([-40.657014335166714, -5.940980368040971]),
            {
              "class": 1,
              "system:index": "38"
            }),
        ee.Feature(
            ee.Geometry.Point([-40.66791483260324, -5.943029236917424]),
            {
              "class": 1,
              "system:index": "39"
            }),
        ee.Feature(
            ee.Geometry.Point([-40.65795382499389, -5.948893149771122]),
            {
              "class": 1,
              "system:index": "40"
            }),
        ee.Feature(
            ee.Geometry.Point([-40.6871645160036, -5.964980567695203]),
            {
              "class": 1,
              "system:index": "41"
            }),
        ee.Feature(
            ee.Geometry.Point([-40.6941168017702, -5.965450080310566]),
            {
              "class": 1,
              "system:index": "42"
            }),
        ee.Feature(
            ee.Geometry.Point([-40.68865082772158, -5.984318822002688]),
            {
              "class": 1,
              "system:index": "43"
            }),
        ee.Feature(
            ee.Geometry.Point([-40.67550660091188, -5.993237668573697]),
            {
              "class": 1,
              "system:index": "44"
            }),
        ee.Feature(
            ee.Geometry.Point([-40.605201674393065, -6.155015332827855]),
            {
              "class": 1,
              "system:index": "45"
            }),
        ee.Feature(
            ee.Geometry.Point([-40.58935895610669, -6.155071070739989]),
            {
              "class": 1,
              "system:index": "46"
            }),
        ee.Feature(
            ee.Geometry.Point([-40.61301463744657, -6.145305292893435]),
            {
              "class": 1,
              "system:index": "47"
            }),
        ee.Feature(
            ee.Geometry.Point([-40.597917208382015, -6.1628019903175995]),
            {
              "class": 1,
              "system:index": "48"
            }),
        ee.Feature(
            ee.Geometry.Point([-40.57569778324729, -6.160751668321601]),
            {
              "class": 1,
              "system:index": "49"
            }),
        ee.Feature(
            ee.Geometry.Point([-40.56886661247233, -6.164686021914153]),
            {
              "class": 1,
              "system:index": "50"
            }),
        ee.Feature(
            ee.Geometry.Point([-40.5530347140701, -6.152084547966948]),
            {
              "class": 1,
              "system:index": "51"
            }),
        ee.Feature(
            ee.Geometry.Point([-40.55778117296199, -6.151352118604018]),
            {
              "class": 1,
              "system:index": "52"
            }),
        ee.Feature(
            ee.Geometry.Point([-40.54073221839268, -6.13300095557247]),
            {
              "class": 1,
              "system:index": "53"
            }),
        ee.Feature(
            ee.Geometry.Point([-40.54900931191731, -6.134071220472289]),
            {
              "class": 1,
              "system:index": "54"
            }),
        ee.Feature(
            ee.Geometry.Point([-40.56499703183946, -6.136010377476307]),
            {
              "class": 1,
              "system:index": "55"
            }),
        ee.Feature(
            ee.Geometry.Point([-40.52958469735488, -6.152986867381293]),
            {
              "class": 1,
              "system:index": "56"
            }),
        ee.Feature(
            ee.Geometry.Point([-40.52874044203274, -6.158260665183752]),
            {
              "class": 1,
              "system:index": "57"
            }),
        ee.Feature(
            ee.Geometry.Point([-40.53038111923358, -6.160965118181293]),
            {
              "class": 1,
              "system:index": "58"
            }),
        ee.Feature(
            ee.Geometry.Point([-40.5525953354724, -6.154916357750047]),
            {
              "class": 1,
              "system:index": "59"
            }),
        ee.Feature(
            ee.Geometry.Point([-40.54672334487697, -6.171550158702447]),
            {
              "class": 1,
              "system:index": "60"
            }),
        ee.Feature(
            ee.Geometry.Point([-40.526496899290755, -6.172037534788285]),
            {
              "class": 1,
              "system:index": "61"
            })]),
    mata_ciliar = /* color: #a3ff00 */ee.FeatureCollection(
        [ee.Feature(
            ee.Geometry.Point([-40.584654259767525, -6.04465190072895]),
            {
              "class": 2,
              "system:index": "0"
            }),
        ee.Feature(
            ee.Geometry.Point([-40.577444481935494, -6.047212499104433]),
            {
              "class": 2,
              "system:index": "1"
            }),
        ee.Feature(
            ee.Geometry.Point([-40.58984701642036, -6.050029143315277]),
            {
              "class": 2,
              "system:index": "2"
            }),
        ee.Feature(
            ee.Geometry.Point([-40.599249832345414, -6.036520567038078]),
            {
              "class": 2,
              "system:index": "3"
            }),
        ee.Feature(
            ee.Geometry.Point([-40.60734290248241, -6.03432332756454]),
            {
              "class": 2,
              "system:index": "4"
            }),
        ee.Feature(
            ee.Geometry.Point([-40.62531274309408, -6.030671928934875]),
            {
              "class": 2,
              "system:index": "5"
            }),
        ee.Feature(
            ee.Geometry.Point([-40.630848822500816, -6.031482807326099]),
            {
              "class": 2,
              "system:index": "6"
            }),
        ee.Feature(
            ee.Geometry.Point([-40.63166421404134, -6.034427566021885]),
            {
              "class": 2,
              "system:index": "7"
            }),
        ee.Feature(
            ee.Geometry.Point([-40.619526024168955, -6.021222462769743]),
            {
              "class": 2,
              "system:index": "8"
            }),
        ee.Feature(
            ee.Geometry.Point([-40.72808609360753, -5.908257251095358]),
            {
              "class": 2,
              "system:index": "9"
            })]),
    estrada = /* color: #7f7f7f */ee.FeatureCollection(
        [ee.Feature(
            ee.Geometry.Point([-40.738776469671876, -5.931005189311238]),
            {
              "class": 3,
              "system:index": "0"
            }),
        ee.Feature(
            ee.Geometry.Point([-40.74067173094256, -5.937474503952196]),
            {
              "class": 3,
              "system:index": "1"
            }),
        ee.Feature(
            ee.Geometry.Point([-40.743232662801056, -5.94374429648246]),
            {
              "class": 3,
              "system:index": "2"
            }),
        ee.Feature(
            ee.Geometry.Point([-40.74460595381668, -5.950445743102636]),
            {
              "class": 3,
              "system:index": "3"
            }),
        ee.Feature(
            ee.Geometry.Point([-40.74346557703663, -5.954910080887217]),
            {
              "class": 3,
              "system:index": "4"
            }),
        ee.Feature(
            ee.Geometry.Point([-40.73943420444502, -5.970151132477453]),
            {
              "class": 3,
              "system:index": "5"
            }),
        ee.Feature(
            ee.Geometry.Point([-40.73834337746799, -5.980823701691958]),
            {
              "class": 3,
              "system:index": "6"
            }),
        ee.Feature(
            ee.Geometry.Point([-40.73740070425976, -5.988022344994524]),
            {
              "class": 3,
              "system:index": "7"
            }),
        ee.Feature(
            ee.Geometry.Point([-40.73508303241837, -5.998362520472057]),
            {
              "class": 3,
              "system:index": "8"
            }),
        ee.Feature(
            ee.Geometry.Point([-40.72993720448144, -6.003987311574017]),
            {
              "class": 3,
              "system:index": "9"
            }),
        ee.Feature(
            ee.Geometry.Point([-40.72959388172753, -6.0108160587113]),
            {
              "class": 3,
              "system:index": "10"
            }),
        ee.Feature(
            ee.Geometry.Point([-40.72083915150292, -5.9995485800255715]),
            {
              "class": 3,
              "system:index": "11"
            }),
        ee.Feature(
            ee.Geometry.Point([-40.69775364326642, -5.997282678653309]),
            {
              "class": 3,
              "system:index": "12"
            }),
        ee.Feature(
            ee.Geometry.Point([-40.663232012537286, -5.989981337911669]),
            {
              "class": 3,
              "system:index": "13"
            }),
        ee.Feature(
            ee.Geometry.Point([-40.66889683797674, -5.9935665329312995]),
            {
              "class": 3,
              "system:index": "14"
            }),
        ee.Feature(
            ee.Geometry.Point([-40.67735116079168, -5.996468816411097]),
            {
              "class": 3,
              "system:index": "15"
            }),
        ee.Feature(
            ee.Geometry.Point([-40.647618179900185, -5.988640678376411]),
            {
              "class": 3,
              "system:index": "16"
            }),
        ee.Feature(
            ee.Geometry.Point([-40.64012257034011, -5.9956230547416]),
            {
              "class": 3,
              "system:index": "17"
            }),
        ee.Feature(
            ee.Geometry.Point([-40.61840740615554, -5.988239262367536]),
            {
              "class": 3,
              "system:index": "18"
            }),
        ee.Feature(
            ee.Geometry.Point([-40.63394725440646, -6.007377867896078]),
            {
              "class": 3,
              "system:index": "19"
            }),
        ee.Feature(
            ee.Geometry.Point([-40.690975186055546, -6.159311596077813]),
            {
              "class": 3,
              "system:index": "20"
            }),
        ee.Feature(
            ee.Geometry.Point([-40.694494244283085, -6.172197058274691]),
            {
              "class": 3,
              "system:index": "21"
            }),
        ee.Feature(
            ee.Geometry.Point([-40.693142830566835, -6.135375016533586]),
            {
              "class": 3,
              "system:index": "22"
            }),
        ee.Feature(
            ee.Geometry.Point([-40.68571223317025, -6.110495424119384]),
            {
              "class": 3,
              "system:index": "23"
            })]),
    caa_narb = /* color: #99c23f */ee.FeatureCollection(
        [ee.Feature(
            ee.Geometry.Point([-40.677721834963634, -6.105904797496201]),
            {
              "class": 4,
              "system:index": "0"
            }),
        ee.Feature(
            ee.Geometry.Point([-40.68276207198586, -6.107489442787329]),
            {
              "class": 4,
              "system:index": "1"
            }),
        ee.Feature(
            ee.Geometry.Point([-40.673993924984906, -6.106720501474657]),
            {
              "class": 4,
              "system:index": "2"
            }),
        ee.Feature(
            ee.Geometry.Point([-40.66525565439147, -6.105755330674494]),
            {
              "class": 4,
              "system:index": "3"
            }),
        ee.Feature(
            ee.Geometry.Point([-40.66588778294663, -6.10097821531835]),
            {
              "class": 4,
              "system:index": "4"
            }),
        ee.Feature(
            ee.Geometry.Point([-40.64697283912891, -6.093843782995205]),
            {
              "class": 4,
              "system:index": "5"
            }),
        ee.Feature(
            ee.Geometry.Point([-40.63853475465266, -6.087038711992771]),
            {
              "class": 4,
              "system:index": "6"
            }),
        ee.Feature(
            ee.Geometry.Point([-40.65625205195235, -6.0757298785103195]),
            {
              "class": 4,
              "system:index": "7"
            }),
        ee.Feature(
            ee.Geometry.Point([-40.656638290050495, -6.073766857910057]),
            {
              "class": 4,
              "system:index": "8"
            }),
        ee.Feature(
            ee.Geometry.Point([-40.69581055988175, -6.087816729053837]),
            {
              "class": 4,
              "system:index": "9"
            }),
        ee.Feature(
            ee.Geometry.Point([-40.670016258802036, -6.103730555961079]),
            {
              "class": 4,
              "system:index": "10"
            }),
        ee.Feature(
            ee.Geometry.Point([-40.67178666360218, -6.108033188765104]),
            {
              "class": 4,
              "system:index": "11"
            }),
        ee.Feature(
            ee.Geometry.Point([-40.66481864067174, -6.110067353218701]),
            {
              "class": 4,
              "system:index": "12"
            }),
        ee.Feature(
            ee.Geometry.Point([-40.65786771283369, -6.10914774608051]),
            {
              "class": 4,
              "system:index": "13"
            }),
        ee.Feature(
            ee.Geometry.Point([-40.63110697890369, -6.10318101958551]),
            {
              "class": 4,
              "system:index": "14"
            }),
        ee.Feature(
            ee.Geometry.Point([-40.619533092633255, -6.09774083526971]),
            {
              "class": 4,
              "system:index": "15"
            }),
        ee.Feature(
            ee.Geometry.Point([-40.61976742126547, -6.093608574824873]),
            {
              "class": 4,
              "system:index": "16"
            }),
        ee.Feature(
            ee.Geometry.Point([-40.61107966069137, -6.083863835381248]),
            {
              "class": 4,
              "system:index": "17"
            }),
        ee.Feature(
            ee.Geometry.Point([-40.608150278098506, -6.077634741608891]),
            {
              "class": 4,
              "system:index": "18"
            }),
        ee.Feature(
            ee.Geometry.Point([-40.622349773770324, -6.077109793369719]),
            {
              "class": 4,
              "system:index": "19"
            }),
        ee.Feature(
            ee.Geometry.Point([-40.62952530678497, -6.074837167193002]),
            {
              "class": 4,
              "system:index": "20"
            }),
        ee.Feature(
            ee.Geometry.Point([-40.64221356466414, -6.0325723432037055]),
            {
              "class": 4,
              "system:index": "21"
            }),
        ee.Feature(
            ee.Geometry.Point([-40.628079640957445, -6.004731107426568]),
            {
              "class": 4,
              "system:index": "22"
            }),
        ee.Feature(
            ee.Geometry.Point([-40.63027444394244, -5.9939057701203176]),
            {
              "class": 4,
              "system:index": "23"
            }),
        ee.Feature(
            ee.Geometry.Point([-40.622613109612374, -5.985162643862548]),
            {
              "class": 4,
              "system:index": "24"
            }),
        ee.Feature(
            ee.Geometry.Point([-40.659973201387636, -5.993286702601335]),
            {
              "class": 4,
              "system:index": "25"
            }),
        ee.Feature(
            ee.Geometry.Point([-40.67662478565886, -5.984669555134509]),
            {
              "class": 4,
              "system:index": "26"
            }),
        ee.Feature(
            ee.Geometry.Point([-40.697375971572264, -5.988212103854728]),
            {
              "class": 4,
              "system:index": "27"
            })]),
    Solo_expost = /* color: #ffcfd2 */ee.FeatureCollection(
        [ee.Feature(
            ee.Geometry.Point([-40.63058065732151, -6.0672033863063675]),
            {
              "class": 5,
              "system:index": "0"
            }),
        ee.Feature(
            ee.Geometry.Point([-40.62577413876682, -6.0691664308253825]),
            {
              "class": 5,
              "system:index": "1"
            }),
        ee.Feature(
            ee.Geometry.Point([-40.61441859064429, -6.075988309029962]),
            {
              "class": 5,
              "system:index": "2"
            }),
        ee.Feature(
            ee.Geometry.Point([-40.587112034395204, -6.06553775512769]),
            {
              "class": 5,
              "system:index": "3"
            }),
        ee.Feature(
            ee.Geometry.Point([-40.5489595590289, -6.051752653631657]),
            {
              "class": 5,
              "system:index": "4"
            }),
        ee.Feature(
            ee.Geometry.Point([-40.58689179536657, -6.013346549938661]),
            {
              "class": 5,
              "system:index": "5"
            }),
        ee.Feature(
            ee.Geometry.Point([-40.578480387895866, -6.0032741647299614]),
            {
              "class": 5,
              "system:index": "6"
            }),
        ee.Feature(
            ee.Geometry.Point([-40.5709886399716, -5.992601658961506]),
            {
              "class": 5,
              "system:index": "7"
            }),
        ee.Feature(
            ee.Geometry.Point([-40.571932777544845, -5.996101475665525]),
            {
              "class": 5,
              "system:index": "8"
            }),
        ee.Feature(
            ee.Geometry.Point([-40.58449638405155, -5.9885072640404475]),
            {
              "class": 5,
              "system:index": "9"
            }),
        ee.Feature(
            ee.Geometry.Point([-40.57922560317252, -5.985313878866977]),
            {
              "class": 5,
              "system:index": "10"
            }),
        ee.Feature(
            ee.Geometry.Point([-40.522105140765795, -5.980571482965502]),
            {
              "class": 5,
              "system:index": "11"
            }),
        ee.Feature(
            ee.Geometry.Point([-40.512148780902514, -5.980998300480549]),
            {
              "class": 5,
              "system:index": "12"
            }),
        ee.Feature(
            ee.Geometry.Point([-40.61170588559919, -5.944094657456611]),
            {
              "class": 5,
              "system:index": "13"
            }),
        ee.Feature(
            ee.Geometry.Point([-40.67304725623989, -5.976807689237552]),
            {
              "class": 5,
              "system:index": "14"
            }),
        ee.Feature(
            ee.Geometry.Point([-40.6777679441061, -5.972795560724939]),
            {
              "class": 5,
              "system:index": "15"
            }),
        ee.Feature(
            ee.Geometry.Point([-40.65086540264994, -5.9805439190284435]),
            {
              "class": 5,
              "system:index": "16"
            }),
        ee.Feature(
            ee.Geometry.Point([-40.56635997488986, -6.084730165293431]),
            {
              "class": 5,
              "system:index": "17"
            }),
        ee.Feature(
            ee.Geometry.Point([-40.58528319154404, -6.077164290059906]),
            {
              "class": 5,
              "system:index": "18"
            }),
        ee.Feature(
            ee.Geometry.Point([-40.663569843017775, -6.086256272565045]),
            {
              "class": 5,
              "system:index": "19"
            }),
        ee.Feature(
            ee.Geometry.Point([-40.685218495803994, -6.0982900500198545]),
            {
              "class": 5,
              "system:index": "20"
            }),
        ee.Feature(
            ee.Geometry.Point([-40.65347817723243, -6.116093842435042]),
            {
              "class": 5,
              "system:index": "21"
            }),
        ee.Feature(
            ee.Geometry.Point([-40.629520341834564, -6.1561493068238615]),
            {
              "class": 5,
              "system:index": "22"
            }),
        ee.Feature(
            ee.Geometry.Point([-40.63312523075058, -6.157344005716098]),
            {
              "class": 5,
              "system:index": "23"
            }),
        ee.Feature(
            ee.Geometry.Point([-40.67839320701393, -6.159765697845539]),
            {
              "class": 5,
              "system:index": "24"
            }),
        ee.Feature(
            ee.Geometry.Point([-40.70171202525059, -6.141569805397965]),
            {
              "class": 5,
              "system:index": "25"
            })]);
Map.setCenter(-40.54259265059659,-6.016601660731103,14);
var amostras = caa_arb.merge(mata_ciliar).merge(estrada).merge(caa_narb).merge(Solo_expost);
var planetscope = ee.ImageCollection([image, image2]).mosaic();
var planetscope = planetscope.clip(geometry2);

var trueColorVis = {
  min: 0.0,
  max: 2000.0, 
  bands:"b3,b2,b1"
};
Map.addLayer(planetscope, trueColorVis, 'True Color');
Map.addLayer(geometry2, {}, 'AOI');

//1red
//2green
//3blue
//4nir

var ndvi = planetscope.normalizedDifference(['b4','b1']).rename('NDVI');
var nwvi = planetscope.normalizedDifference(['b4','b2']).rename('NDWI');

var planetscope = planetscope.addBands(ndvi);
var planetscope = planetscope.addBands(nwvi);

var square = ee.Kernel.square({radius: 4});
var entropy = planetscope.select('b4').toByte().entropy(square);
var glcm = planetscope.select('b4').toByte().glcmTexture({size: 4});
var contrast = glcm.select('b4_contrast');
var asm = glcm.select('b4_asm');

var img_planetscope = planetscope.float().divide(10000);

// 分割 -----------------------------------------------------------------------------

var seeds = ee.Algorithms.Image.Segmentation.seedGrid(10);
var snic = ee.Algorithms.Image.Segmentation.SNIC({
  image: img_planetscope,
  compactness: 0,
  connectivity: 8,
  neighborhoodSize: 64,
  size: 2,
  seeds: seeds
});

var clusters_snic = snic.select("clusters")

var vectors = clusters_snic.reduceToVectors({
  geometryType: 'polygon',
  reducer: ee.Reducer.countEvery(),
  scale: 10,
  maxPixels: 1e13,
  geometry: geometry2,
  bestEffort:true
});

var empty = ee.Image().byte();


var outline = empty.paint({
  featureCollection: vectors,
  color: 1,
  width: 1
});

Map.addLayer(outline, {palette: 'FF0000'}, 'segments');

//var img_planetscope = img_planetscope.addBands(glcm.select(['b4_contrast','b4_asm',"b4_corr"]).float()).addBands(entropy);

var train_polys = vectors.map(function(feat){
  feat = ee.Feature(feat);
  var point = feat.geometry();

  var mappedPolys = amostras.map(function(poly){
    var cls = poly.get("class")
    var intersects = poly.intersects(point, ee.ErrorMargin(1));
    var property = ee.String(ee.Algorithms.If(intersects, 'TRUE', 'FALSE'));
    return feat.set('belongsTo',  property).set('class', cls);
  });
  return mappedPolys;
}).flatten().filter(ee.Filter.neq('belongsTo', 'FALSE'));


//提取特征 --------------------------------------------- 
var train_areas = train_polys
  .reduceToImage({
    properties: ['class'],
    reducer: ee.Reducer.first()
}).rename('class').toInt();



// 提取矢量边界从影像中------------------------------------------------------------------------------------------
var predict_image = vectors
  .reduceToImage({
    properties: ['label'],
    reducer: ee.Reducer.first()
}).rename('id').toInt();


img_planetscope = img_planetscope.addBands(predict_image)


var FullImage_mean = img_planetscope.reduceConnectedComponents({
  reducer: ee.Reducer.mean(),
  labelBand: 'id'
});


/*var FullImage_std = img_planetscope.reduceConnectedComponents({
  reducer: ee.Reducer.stdDev(),
  labelBand: 'id'
});

var FullImage_median = img_planetscope.reduceConnectedComponents({
  reducer: ee.Reducer.median(),
  labelBand: 'id'
});

var FullImage_area = ee.Image.pixelArea().addBands(img_planetscope.select('id')).reduceConnectedComponents(ee.Reducer.sum(), 'id')
var FullImage_sizes = ee.Image.pixelLonLat().addBands(img_planetscope.select('id')).reduceConnectedComponents(ee.Reducer.minMax(), 'id')
var FullImage_width = FullImage_sizes.select('longitude_max').subtract(FullImage_sizes.select('longitude_min')).rename('width')
var FullImage_height = FullImage_sizes.select('latitude_max').subtract(FullImage_sizes.select('latitude_min')).rename('height')
*/
// 加入矢量

var Pred_bands = ee.Image.cat([
  FullImage_mean,
  //FullImage_std,
  //FullImage_median,
  //FullImage_area,
  //FullImage_width,
  //FullImage_height
]).float();

var clip_Image = Pred_bands.clip(train_polys);
var train_areas = train_areas.addBands(clip_Image);
var predictionBands = Pred_bands.bandNames();
var classifierTraining = train_areas.select(predictionBands).sampleRegions({collection: train_polys, properties: ['class'], scale: 10 });
var RF = ee.Classifier.smileRandomForest(50).train({features:classifierTraining, classProperty:'class', inputProperties: predictionBands});

var classified_RF = Pred_bands.select(predictionBands).classify(RF);
// print(classified_RF);
Map.addLayer(classified_RF);
// Map.addLayer(planetscope, imageVisParam,'img');
// Map.addLayer(planetscope, imageVisParam3,'ndvi');
// Map.addLayer(planetscope, imageVisParam2, "ndwi");

//影像导出
Export.image.toDrive({
  image: classified_RF,
  description: 'teste_classif',
  scale: 3,
  maxPixels: 1e13,
  region: geometry
});

结果:

 黄色细线部分为分割区域

影像分辨率3米 

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2024-02-01,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • No arguments.
  • Returns: Reducer
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档