2

I have been trying to export this classified image. I want my GeoTIFF file to show this view...

enter image description here

But every time I export, my image turns out Black. after some digging i got to learn that I need to attach the image with some rgb visual parameters with the export command, but i'm not sure how to do that. I have done this classification following a YouTube video as I'm learning. I'm a beginner in GEE.

The code I used is:

//CART classification and Accuracy Assessment
var image = ee.ImageCollection('LANDSAT/LC08/C02/T1_L2')
.filterDate('2016-01-01', '2020-12-31')
.filterBounds(roi)
.sort('CLOUD_COVER')
.first()
.clip(roi)


//Visualize
var visparamsTrue = {bands: ['SR_B4', 'SR_B3', 'SR_B2'], min:0, max:65455, gamma:1.4}
Map.addLayer(image, visparamsTrue, 'landsat_2017-2019')
Map.centerObject(roi)

//Create training data
var label = 'Class';
var bands = ['SR_B1', 'SR_B2', 'SR_B3', 'SR_B4', 'SR_B5', 'SR_B6', 'SR_B7']
var input = image.select(bands);

//merge
var training = urban.merge(water).merge(forest).merge(cropland).merge(barren)
print(training)

//overlay the points to get the training
var trainImage = input.sampleRegions({
  collection: training,
  properties: [label],
  scale: 30
})
print(trainImage)

//now we define how much(%) data we use for training
var trainingData = trainImage.randomColumn();
var trainSet = trainingData.filter(ee.Filter.lessThan('random', 0.8))
var testSet = trainingData.filter(ee.Filter.greaterThan('random', 0.8))

//create classification model
var classifier = ee.Classifier.smileCart().train(trainSet, label, bands)

//classify the image using upper created model
var classified = input.classify(classifier)
print(classified.getInfo())


//nown its to visulalize the data. first define a pallete color
var landcoverPalette = [
  '#253494', //For water(0)
  '#eff3ff', //for urban(1)
  '#31a354', //for forest(2)
  '#bae4b3', //for cropland(3)
  '#ffffd4', //for barren(4)];
];

//Add to maplayer
Map.addLayer(classified, {palette: landcoverPalette, min:0, max:4}, 'Classification')

// accuracy assessment
//classify the testset created earlier and get a confusin matrix
var confusionMatrix = ee.ConfusionMatrix(testSet.classify(classifier)
.errorMatrix({
  actual:'Class',
  predicted:'classification'
}));



print('confusionMatrix:', confusionMatrix)
//generate overall accuracy from confusionmatric
print('OverallAccuracy:', confusionMatrix.accuracy())

//Export
Export.image.toDrive({
  image: image,
  description: 'Classified_visualize_visparams',
  folder: 'CP2',  
  region: roi, scale: 30,
  maxPixels: 1e13,
}); 

I have tried exporting with this too, which gives me only the TRUE COLOR COMPOSITE view of this area, not the CLASSIFIED image which I'm looking for.

  Export.image.toDrive({
    image: image.visualize(visparamsTrue),
    description: 'Classified_visualize_visparams',
    folder: 'CP2',  
    region: roi, 
    scale: 30,
    maxPixels: 1e13,
    }); 

1 Answer 1

2

Because you are using true color in export visualization. Instead, use a classification palette.

var viz = { min:0, max:4, palette: landcoverPalette}

Export.image.toDrive({
    image: image.visualize(viz),
    description: 'Classified_visualize_visparams',
    folder: 'CP2',  
    region: roi, 
    scale: 30,
    maxPixels: 1e13,
    }); 

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.