Skip to main content
Tweeted twitter.com/StackGIS/status/1507688825103036417
Became Hot Network Question
deleted 931 characters in body
Source Link
Learner
  • 119
  • 2
  • 16

I am trying to classify my study area with a RandomForest classifier, using Sentinel-2 Surface Reflectance images. This classification gave me an accuracy of about 87%. I calculated the misclassified points asand below are its results.

// We use ee.Filter.and() function to create a combined filter
var combinedFilter1Mangrove =Misclassified ee.Filter.and(Points
 FeatureCollection ee.Filter.eq('landcover', 0),303 ee.Filter.neq('classification'elements, 0))
var mMisclassified = test.filter(combinedFilter1columns)
print('MangroveWater Misclassified Points', mMisclassified)
Points
// We useFeatureCollection ee.Filter.and() function to create989 aelements, combined0 filtercolumns)
var combinedFilter2Other =Misclassified ee.Filter.and(Points
 FeatureCollection ee.Filter.eq('landcover',242 1)elements, ee.Filter.neq('classification',0 1)columns)
var wMisclassifiedAll =Misclassified test.filter(combinedFilter2)Points
print('WaterFeatureCollection Misclassified(1534 Points'elements, wMisclassified0 columns)
 
// We use

As you can see, so many points are getting misclassified. It is because of many shadows appearing.

I looked into example, to remove the clouds and their shadows, but I am finding it very difficult to get my head around it.

I applied the below snippet

function ee.Filter.andmaskS2clouds(image) function to create a combined filter
var combinedFilter3 = ee.Filter.and({
  ee.Filter.eq('landcover', 2), ee.Filter.neq('classification', 2))
var oMisclassifiedqa = testimage.filterselect(combinedFilter3'QA60');
print('Other Misclassified 
 Points', oMisclassified)

// We can alsoBits apply10 aand filter11 toare selectclouds alland misclassifiedcirrus, pointsrespectively.
// Since we arevar comparingcloudBitMask 2= properties1 agaist<< each-other,10;
// we need to use a binary filter
var misClassifiedcirrusBitMask = test.filter(ee.Filter.notEquals({
 1 leftField:'classification',<< rightField:'landcover'}))11;
  
print('All Misclassified Points', misClassified)

// DisplayBoth theflags misclassifiedshould pointsbe byset stylingto them
varzero, landcoverindicating =clear eeconditions.List([0, 1, 2])
var palette = ee.List(['green','blue','gray'])
var misclassStyledmask = eeqa.FeatureCollectionbitwiseAnd(
  landcovercloudBitMask).map(functioneq(lc0){
    var feature = misClassified.filterand(ee.Filterqa.eqbitwiseAnd('landcover', lc)cirrusBitMask)
    var color = palette.get(landcover.indexOfeq(lc0));
    var markerStyle = {color:color}
    return feature.map(function(point){
       return pointimage.setupdateMask('style', markerStyle)
       })
    })mask).flattendivide(10000);
      
Map.addLayer(misclassStyled.style({styleProperty:"style"}), {}, 'Misclassified Points')

This gave me the resultmisclassified points as follows:

Mangrove Misclassified Points
FeatureCollection (303282 elements, 0 columns)
Water Misclassified Points
FeatureCollection (989986 elements, 0 columns)
Other Misclassified Points
FeatureCollection (242269 elements, 0 columns)
All Misclassified Points
FeatureCollection (15341551 elements, 0 columns)

As you can see, so many points are gettingThe misclassified. It is because of many shadows appearing.

I looked into example, to remove the clouds and their shadows points increased, but I am findingwhen it very difficultis expected to get my head around itreduce.

I am trying to classify my study area with a RandomForest classifier, using Sentinel-2 Surface Reflectance images. This classification gave me an accuracy of about 87%. I calculated the misclassified points as below

// We use ee.Filter.and() function to create a combined filter
var combinedFilter1 = ee.Filter.and(
  ee.Filter.eq('landcover', 0), ee.Filter.neq('classification', 0))
var mMisclassified = test.filter(combinedFilter1)
print('Mangrove Misclassified Points', mMisclassified)

// We use ee.Filter.and() function to create a combined filter
var combinedFilter2 = ee.Filter.and(
  ee.Filter.eq('landcover', 1), ee.Filter.neq('classification', 1))
var wMisclassified = test.filter(combinedFilter2)
print('Water Misclassified Points', wMisclassified)
 
// We use ee.Filter.and() function to create a combined filter
var combinedFilter3 = ee.Filter.and(
  ee.Filter.eq('landcover', 2), ee.Filter.neq('classification', 2))
var oMisclassified = test.filter(combinedFilter3)
print('Other Misclassified Points', oMisclassified)

// We can also apply a filter to select all misclassified points
// Since we are comparing 2 properties agaist each-other,
// we need to use a binary filter
var misClassified = test.filter(ee.Filter.notEquals({
  leftField:'classification', rightField:'landcover'}))
  
print('All Misclassified Points', misClassified)

// Display the misclassified points by styling them
var landcover = ee.List([0, 1, 2])
var palette = ee.List(['green','blue','gray'])
var misclassStyled = ee.FeatureCollection(
  landcover.map(function(lc){
    var feature = misClassified.filter(ee.Filter.eq('landcover', lc))
    var color = palette.get(landcover.indexOf(lc));
    var markerStyle = {color:color}
    return feature.map(function(point){
       return point.set('style', markerStyle)
       })
    })).flatten();
      
Map.addLayer(misclassStyled.style({styleProperty:"style"}), {}, 'Misclassified Points')

This gave me the result as follows:

Mangrove Misclassified Points
FeatureCollection (303 elements, 0 columns)
Water Misclassified Points
FeatureCollection (989 elements, 0 columns)
Other Misclassified Points
FeatureCollection (242 elements, 0 columns)
All Misclassified Points
FeatureCollection (1534 elements, 0 columns)

As you can see, so many points are getting misclassified. It is because of many shadows appearing.

I looked into example, to remove the clouds and their shadows, but I am finding it very difficult to get my head around it.

I am trying to classify my study area with a RandomForest classifier, using Sentinel-2 Surface Reflectance images. This classification gave me an accuracy of about 87%. I calculated the misclassified points and below are its results.

Mangrove Misclassified Points
FeatureCollection (303 elements, 0 columns)
Water Misclassified Points
FeatureCollection (989 elements, 0 columns)
Other Misclassified Points
FeatureCollection (242 elements, 0 columns)
All Misclassified Points
FeatureCollection (1534 elements, 0 columns)

As you can see, so many points are getting misclassified. It is because of many shadows appearing.

I looked into example, to remove the clouds and their shadows, but I am finding it very difficult to get my head around it.

I applied the below snippet

function maskS2clouds(image) {
  var qa = image.select('QA60');
 
  // Bits 10 and 11 are clouds and cirrus, respectively.
  var cloudBitMask = 1 << 10;
  var cirrusBitMask = 1 << 11;

  // Both flags should be set to zero, indicating clear conditions.
  var mask = qa.bitwiseAnd(cloudBitMask).eq(0)
      .and(qa.bitwiseAnd(cirrusBitMask).eq(0));

  return image.updateMask(mask).divide(10000);
}

This gave the misclassified points as

Mangrove Misclassified Points
FeatureCollection (282 elements, 0 columns)
Water Misclassified Points
FeatureCollection (986 elements, 0 columns)
Other Misclassified Points
FeatureCollection (269 elements, 0 columns)
All Misclassified Points
FeatureCollection (1551 elements)

The misclassified points increased, when it is expected to reduce.

added 2168 characters in body; edited tags
Source Link
Learner
  • 119
  • 2
  • 16

I am trying to classify my study area with a RandomForest classifier, using Sentinel-2 Surface Reflectance images. This classification gave me an accuracy of about 87%. Although the accuracy is okay, I calculated the misclassified points as below

// We use ee.Filter.and() function to create a combined filter
var combinedFilter1 = ee.Filter.and(
  ee.Filter.eq('landcover', 0), ee.Filter.neq('classification', 0))
var mMisclassified = test.filter(combinedFilter1)
print('Mangrove Misclassified Points', mMisclassified)

// We use ee.Filter.and() function to create a combined filter
var combinedFilter2 = ee.Filter.and(
  ee.Filter.eq('landcover', 1), ee.Filter.neq('classification', 1))
var wMisclassified = test.filter(combinedFilter2)
print('Water Misclassified Points', wMisclassified)

// We use ee.Filter.and() function to create a combined filter
var combinedFilter3 = ee.Filter.and(
  ee.Filter.eq('landcover', 2), ee.Filter.neq('classification', 2))
var oMisclassified = test.filter(combinedFilter3)
print('Other Misclassified Points', oMisclassified)

// We can also apply a filter to select all misclassified points
// Since we are comparing 2 properties agaist each-other,
// we need to use a binary filter
var misClassified = test.filter(ee.Filter.notEquals({
  leftField:'classification', rightField:'landcover'}))
  
print('All Misclassified Points', misClassified)

// Display the misclassified points by styling them
var landcover = ee.List([0, 1, 2])
var palette = ee.List(['green','blue','gray'])
var misclassStyled = ee.FeatureCollection(
  landcover.map(function(lc){
    var feature = misClassified.filter(ee.Filter.eq('landcover', lc))
    var color = palette.get(landcover.indexOf(lc));
    var markerStyle = {color:color}
    return feature.map(function(point){
       return point.set('style', markerStyle)
       })
    })).flatten();
      
Map.addLayer(misclassStyled.style({styleProperty:"style"}), {}, 'Misclassified Points')

This gave me the result as follows:

Mangrove Misclassified Points
FeatureCollection (303 elements, 0 columns)
Water Misclassified Points
FeatureCollection (989 elements, 0 columns)
Other Misclassified Points
FeatureCollection (242 elements, 0 columns)
All Misclassified Points
FeatureCollection (1534 elements, 0 columns)

As you can see that there are many cloud shadows present, andso many pixel valuespoints are getting misclassified. ThisIt is affecting my area calculationbecause of many shadows appearing. 

I looked into example, to remove the clouds and their shadows, but I am finding it very difficult to get my head around it. 

Please guide me in understanding how I can incorporate it into my code., to improve the accuracy and minimize the misclassification points

Here is it,my implementation code.GEE

I am trying to classify my study area with a RandomForest classifier, using Sentinel-2 Surface Reflectance images. This classification gave me an accuracy of about 87%. Although the accuracy is okay, I can see that there are many cloud shadows present, and many pixel values are getting misclassified. This is affecting my area calculation. I looked into example, to remove the clouds and their shadows, but I am finding it very difficult to get my head around it. Please guide me in understanding how I can incorporate it into my code.

Here is it, code.

I am trying to classify my study area with a RandomForest classifier, using Sentinel-2 Surface Reflectance images. This classification gave me an accuracy of about 87%. I calculated the misclassified points as below

// We use ee.Filter.and() function to create a combined filter
var combinedFilter1 = ee.Filter.and(
  ee.Filter.eq('landcover', 0), ee.Filter.neq('classification', 0))
var mMisclassified = test.filter(combinedFilter1)
print('Mangrove Misclassified Points', mMisclassified)

// We use ee.Filter.and() function to create a combined filter
var combinedFilter2 = ee.Filter.and(
  ee.Filter.eq('landcover', 1), ee.Filter.neq('classification', 1))
var wMisclassified = test.filter(combinedFilter2)
print('Water Misclassified Points', wMisclassified)

// We use ee.Filter.and() function to create a combined filter
var combinedFilter3 = ee.Filter.and(
  ee.Filter.eq('landcover', 2), ee.Filter.neq('classification', 2))
var oMisclassified = test.filter(combinedFilter3)
print('Other Misclassified Points', oMisclassified)

// We can also apply a filter to select all misclassified points
// Since we are comparing 2 properties agaist each-other,
// we need to use a binary filter
var misClassified = test.filter(ee.Filter.notEquals({
  leftField:'classification', rightField:'landcover'}))
  
print('All Misclassified Points', misClassified)

// Display the misclassified points by styling them
var landcover = ee.List([0, 1, 2])
var palette = ee.List(['green','blue','gray'])
var misclassStyled = ee.FeatureCollection(
  landcover.map(function(lc){
    var feature = misClassified.filter(ee.Filter.eq('landcover', lc))
    var color = palette.get(landcover.indexOf(lc));
    var markerStyle = {color:color}
    return feature.map(function(point){
       return point.set('style', markerStyle)
       })
    })).flatten();
      
Map.addLayer(misclassStyled.style({styleProperty:"style"}), {}, 'Misclassified Points')

This gave me the result as follows:

Mangrove Misclassified Points
FeatureCollection (303 elements, 0 columns)
Water Misclassified Points
FeatureCollection (989 elements, 0 columns)
Other Misclassified Points
FeatureCollection (242 elements, 0 columns)
All Misclassified Points
FeatureCollection (1534 elements, 0 columns)

As you can see, so many points are getting misclassified. It is because of many shadows appearing. 

I looked into example, to remove the clouds and their shadows, but I am finding it very difficult to get my head around it. 

Please guide me in understanding how I can incorporate it into my code, to improve the accuracy and minimize the misclassification points

Here is my implementation GEE

added 44 characters in body
Source Link
Learner
  • 119
  • 2
  • 16

I am trying to classify my study area with a RandomForest classifier, using Sentinel-2 Surface Reflectance images. This classification gave me an accuracy of about 87%. Although the accuracy is okay,I I can see that there are many cloud shadows present, and many pixel values are getting misclassified. This is affecting my area calculation. I looked into example, to remove the clouds and itstheir shadows, but I am finding it very difficult to get my head around it. Please guide me in understanding how I can incorporate it into my code.

Here is it, code.

I am trying to classify my study area with RandomForest classifier, using Sentinel-2 Surface Reflectance images. This classification gave me an accuracy of about 87%. Although the accuracy is okay,I can see that there are many cloud shadows present, and many pixel values are getting misclassified. I looked into example, to remove the clouds and its shadows, but I am finding it very difficult to get my head around it. Please guide me in understanding how I can incorporate it into my code.

Here is it, code.

I am trying to classify my study area with a RandomForest classifier, using Sentinel-2 Surface Reflectance images. This classification gave me an accuracy of about 87%. Although the accuracy is okay, I can see that there are many cloud shadows present, and many pixel values are getting misclassified. This is affecting my area calculation. I looked into example, to remove the clouds and their shadows, but I am finding it very difficult to get my head around it. Please guide me in understanding how I can incorporate it into my code.

Here is it, code.

Source Link
Learner
  • 119
  • 2
  • 16
Loading