0

I am trying to perform an OBIA classification and followed a tutorial but I get the following error : Image.select: Pattern 'B8' did not match any bands which I don't understand because I am selecting bands. Here is the code below.

I am new to coding and did not find much info on OBIA on GEE.

//Object-based classification
// Segmentation -----------------------------------------------------------------------------
var bands = ['B8', 'B4', 'B3','B2'];
var seeds = ee.Algorithms.Image.Segmentation.seedGrid(35);

var snic = ee.Algorithms.Image.Segmentation.SNIC({
  image: maskedcomposite, 
  compactness: 0,
  connectivity: 4,
  neighborhoodSize: 128,
  size: 20,
  seeds: seeds
}).select(['B8_mean','B4_mean','B3_mean','B2_mean',"clusters"],['B8', 'B4', 'B3', 'B2', "clusters"]);

var clusters_snic = snic.select("clusters");

Map.addLayer(clusters_snic.randomVisualizer(),{}, 'clusters')

print(clusters_snic,"clusters_snic")

var objectPropertiesImage = ee.Image.cat([
  clusters_snic.select(bands),
]).float();

print(objectPropertiesImage,'oPI')

var newfc = geometry.merge(nonfracking)//.merge(roads).merge(Agriculture);
  var bands = objectPropertiesImage.bandNames();
    var training = maskedcomposite.select(bands).updateMask(seeds).sampleRegions({
    collection: newfc, 
    properties: ['landcover'], 
    scale: 20,
    geometries:true
    });
    

//var training = objectPropertiesImage.addBands(cdl2016.select('cropland'))
  //  .updateMask(seeds)
    //.sample(geometry, 5);
var classifier = ee.Classifier.smileRandomForest(50).train(training, 'OBIA_classification');
Map.addLayer(objectPropertiesImage.classify(classifier), {min:0, max:254}, 'OBIA_classification');

maskedcomposite bands

I've checked by printing "masked composite" and it shows 24 bands with the names I am then using. However, it seems like I lose them when I select clusters, how can I solve this because all the obia tutorials I saw used clusters at this stage.

snic

1
  • What tutorial do you follow?
    – user30184
    Commented Nov 28, 2022 at 21:05

1 Answer 1

0

Your error is likely occurring in two places. You have:

var bands = ['B8', 'B4', 'B3','B2'];

and then further down you have:

.select(['B8_mean','B4_mean','B3_mean','B2_mean',"clusters"],['B8', 'B4', 'B3', 'B2', "clusters"]);

My assumption is that B8 (and others) does not actually occur in your dataset - or is at least called something else. Firstly, do this at the top of your script:

print(maskedcomposite)

and look in the right hand console for the output of this. You should be able to see what the band names are if you look in the image properties. Replace the names in these two places with the band names you see there.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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