Supervised classification with only one class with Google Earth Engine












0















I am a beginner with geospatial analysis and Google Earth Engine. I am trying to classify only one class of Landsat 5 image (swimming pool). I got several training sites and applied the classifier. As a result my classified image appeared totally red (so the classification did not give me the expected results). Is that because I should classify several classes and not just one? And how to ask to classify my defined class by my training sites and create another class that gather all the pixels that does not belong to the class previously defined? Below the code I used:



var bands = ['B1', 'B2', 'B3', 'B4', 'B5', 'B6', 'B7']

var image= ee.Image('LANDSAT/LT05/C01/T1_TOA/LT05_015036_20111025')
.select(bands)

// Train is the feature collection containing my training sites (points)
var training = image.sampleRegions({
collection: train,
properties: ['class'],
scale: 30
});

var trained = ee.Classifier.cart().train(training, 'class', bands);

// Classify the image with the same bands used for training.
var classified = image.select(bands).classify(trained);









share|improve this question


















  • 2





    In a normal classification example you will always need more than just your target class. The minimum is a binary classification, where one class is swimming pool and the second one everything else.

    – Val
    Nov 26 '18 at 8:32
















0















I am a beginner with geospatial analysis and Google Earth Engine. I am trying to classify only one class of Landsat 5 image (swimming pool). I got several training sites and applied the classifier. As a result my classified image appeared totally red (so the classification did not give me the expected results). Is that because I should classify several classes and not just one? And how to ask to classify my defined class by my training sites and create another class that gather all the pixels that does not belong to the class previously defined? Below the code I used:



var bands = ['B1', 'B2', 'B3', 'B4', 'B5', 'B6', 'B7']

var image= ee.Image('LANDSAT/LT05/C01/T1_TOA/LT05_015036_20111025')
.select(bands)

// Train is the feature collection containing my training sites (points)
var training = image.sampleRegions({
collection: train,
properties: ['class'],
scale: 30
});

var trained = ee.Classifier.cart().train(training, 'class', bands);

// Classify the image with the same bands used for training.
var classified = image.select(bands).classify(trained);









share|improve this question


















  • 2





    In a normal classification example you will always need more than just your target class. The minimum is a binary classification, where one class is swimming pool and the second one everything else.

    – Val
    Nov 26 '18 at 8:32














0












0








0








I am a beginner with geospatial analysis and Google Earth Engine. I am trying to classify only one class of Landsat 5 image (swimming pool). I got several training sites and applied the classifier. As a result my classified image appeared totally red (so the classification did not give me the expected results). Is that because I should classify several classes and not just one? And how to ask to classify my defined class by my training sites and create another class that gather all the pixels that does not belong to the class previously defined? Below the code I used:



var bands = ['B1', 'B2', 'B3', 'B4', 'B5', 'B6', 'B7']

var image= ee.Image('LANDSAT/LT05/C01/T1_TOA/LT05_015036_20111025')
.select(bands)

// Train is the feature collection containing my training sites (points)
var training = image.sampleRegions({
collection: train,
properties: ['class'],
scale: 30
});

var trained = ee.Classifier.cart().train(training, 'class', bands);

// Classify the image with the same bands used for training.
var classified = image.select(bands).classify(trained);









share|improve this question














I am a beginner with geospatial analysis and Google Earth Engine. I am trying to classify only one class of Landsat 5 image (swimming pool). I got several training sites and applied the classifier. As a result my classified image appeared totally red (so the classification did not give me the expected results). Is that because I should classify several classes and not just one? And how to ask to classify my defined class by my training sites and create another class that gather all the pixels that does not belong to the class previously defined? Below the code I used:



var bands = ['B1', 'B2', 'B3', 'B4', 'B5', 'B6', 'B7']

var image= ee.Image('LANDSAT/LT05/C01/T1_TOA/LT05_015036_20111025')
.select(bands)

// Train is the feature collection containing my training sites (points)
var training = image.sampleRegions({
collection: train,
properties: ['class'],
scale: 30
});

var trained = ee.Classifier.cart().train(training, 'class', bands);

// Classify the image with the same bands used for training.
var classified = image.select(bands).classify(trained);






classification raster supervised-learning google-earth-engine landsat






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 25 '18 at 4:01









arminarmin

286




286








  • 2





    In a normal classification example you will always need more than just your target class. The minimum is a binary classification, where one class is swimming pool and the second one everything else.

    – Val
    Nov 26 '18 at 8:32














  • 2





    In a normal classification example you will always need more than just your target class. The minimum is a binary classification, where one class is swimming pool and the second one everything else.

    – Val
    Nov 26 '18 at 8:32








2




2





In a normal classification example you will always need more than just your target class. The minimum is a binary classification, where one class is swimming pool and the second one everything else.

– Val
Nov 26 '18 at 8:32





In a normal classification example you will always need more than just your target class. The minimum is a binary classification, where one class is swimming pool and the second one everything else.

– Val
Nov 26 '18 at 8:32












1 Answer
1






active

oldest

votes


















0














Just as @Val said, you will need to have at least two classes. That means you will either have to bring a dataset that is the "everything else" class or you can create a pseudo-nonoccurrence dataset in Earth Engine. The pseudo-nonoccurrence sampling assumes that you have a perfect occurrence sample of the first class because it will select regions that are not near the first sample to create the other sample (if that makes any sense at all...). It might look something like this in code:



var bands = ['B1', 'B2', 'B3', 'B4', 'B5', 'B6', 'B7']

var image= ee.Image('LANDSAT/LT05/C01/T1_TOA/LT05_015036_20111025')
.select(bands)

// Train is the feature collection containing my training sites (points)
var occurrence = image.sampleRegions({
collection: train,
properties: ['class'],
scale: 30
}).map(function(feature){
return feature.set('class',ee.Number(1))
});

// Create geometry where there is no occurrence data
var nonarea = image.geometry().difference(train.buffer(100))

// Sample from region where there is no occurrence data
var nonoccurrence = image.sample({
region: nonarea,
scale: 30
}).map(function(feature){
return feature.set('class',ee.Number(0))
});

// Merge the occurrence and non-occurrence feature collections
var training = ee.FeatureCollection(occurrence.merge(nonoccurrence))

var trained = ee.Classifier.cart().train(training, 'class', bands);

// Classify the image with the same bands used for training.
var classified = image.select(bands).classify(trained);


(You may have to fix some of the data types in the above code, it was hard to test without sample data...). This is a commonly used approach in species distribution and disaster hazard modeling and hopefully is helpful for your use case!






share|improve this answer























    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53464543%2fsupervised-classification-with-only-one-class-with-google-earth-engine%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    Just as @Val said, you will need to have at least two classes. That means you will either have to bring a dataset that is the "everything else" class or you can create a pseudo-nonoccurrence dataset in Earth Engine. The pseudo-nonoccurrence sampling assumes that you have a perfect occurrence sample of the first class because it will select regions that are not near the first sample to create the other sample (if that makes any sense at all...). It might look something like this in code:



    var bands = ['B1', 'B2', 'B3', 'B4', 'B5', 'B6', 'B7']

    var image= ee.Image('LANDSAT/LT05/C01/T1_TOA/LT05_015036_20111025')
    .select(bands)

    // Train is the feature collection containing my training sites (points)
    var occurrence = image.sampleRegions({
    collection: train,
    properties: ['class'],
    scale: 30
    }).map(function(feature){
    return feature.set('class',ee.Number(1))
    });

    // Create geometry where there is no occurrence data
    var nonarea = image.geometry().difference(train.buffer(100))

    // Sample from region where there is no occurrence data
    var nonoccurrence = image.sample({
    region: nonarea,
    scale: 30
    }).map(function(feature){
    return feature.set('class',ee.Number(0))
    });

    // Merge the occurrence and non-occurrence feature collections
    var training = ee.FeatureCollection(occurrence.merge(nonoccurrence))

    var trained = ee.Classifier.cart().train(training, 'class', bands);

    // Classify the image with the same bands used for training.
    var classified = image.select(bands).classify(trained);


    (You may have to fix some of the data types in the above code, it was hard to test without sample data...). This is a commonly used approach in species distribution and disaster hazard modeling and hopefully is helpful for your use case!






    share|improve this answer




























      0














      Just as @Val said, you will need to have at least two classes. That means you will either have to bring a dataset that is the "everything else" class or you can create a pseudo-nonoccurrence dataset in Earth Engine. The pseudo-nonoccurrence sampling assumes that you have a perfect occurrence sample of the first class because it will select regions that are not near the first sample to create the other sample (if that makes any sense at all...). It might look something like this in code:



      var bands = ['B1', 'B2', 'B3', 'B4', 'B5', 'B6', 'B7']

      var image= ee.Image('LANDSAT/LT05/C01/T1_TOA/LT05_015036_20111025')
      .select(bands)

      // Train is the feature collection containing my training sites (points)
      var occurrence = image.sampleRegions({
      collection: train,
      properties: ['class'],
      scale: 30
      }).map(function(feature){
      return feature.set('class',ee.Number(1))
      });

      // Create geometry where there is no occurrence data
      var nonarea = image.geometry().difference(train.buffer(100))

      // Sample from region where there is no occurrence data
      var nonoccurrence = image.sample({
      region: nonarea,
      scale: 30
      }).map(function(feature){
      return feature.set('class',ee.Number(0))
      });

      // Merge the occurrence and non-occurrence feature collections
      var training = ee.FeatureCollection(occurrence.merge(nonoccurrence))

      var trained = ee.Classifier.cart().train(training, 'class', bands);

      // Classify the image with the same bands used for training.
      var classified = image.select(bands).classify(trained);


      (You may have to fix some of the data types in the above code, it was hard to test without sample data...). This is a commonly used approach in species distribution and disaster hazard modeling and hopefully is helpful for your use case!






      share|improve this answer


























        0












        0








        0







        Just as @Val said, you will need to have at least two classes. That means you will either have to bring a dataset that is the "everything else" class or you can create a pseudo-nonoccurrence dataset in Earth Engine. The pseudo-nonoccurrence sampling assumes that you have a perfect occurrence sample of the first class because it will select regions that are not near the first sample to create the other sample (if that makes any sense at all...). It might look something like this in code:



        var bands = ['B1', 'B2', 'B3', 'B4', 'B5', 'B6', 'B7']

        var image= ee.Image('LANDSAT/LT05/C01/T1_TOA/LT05_015036_20111025')
        .select(bands)

        // Train is the feature collection containing my training sites (points)
        var occurrence = image.sampleRegions({
        collection: train,
        properties: ['class'],
        scale: 30
        }).map(function(feature){
        return feature.set('class',ee.Number(1))
        });

        // Create geometry where there is no occurrence data
        var nonarea = image.geometry().difference(train.buffer(100))

        // Sample from region where there is no occurrence data
        var nonoccurrence = image.sample({
        region: nonarea,
        scale: 30
        }).map(function(feature){
        return feature.set('class',ee.Number(0))
        });

        // Merge the occurrence and non-occurrence feature collections
        var training = ee.FeatureCollection(occurrence.merge(nonoccurrence))

        var trained = ee.Classifier.cart().train(training, 'class', bands);

        // Classify the image with the same bands used for training.
        var classified = image.select(bands).classify(trained);


        (You may have to fix some of the data types in the above code, it was hard to test without sample data...). This is a commonly used approach in species distribution and disaster hazard modeling and hopefully is helpful for your use case!






        share|improve this answer













        Just as @Val said, you will need to have at least two classes. That means you will either have to bring a dataset that is the "everything else" class or you can create a pseudo-nonoccurrence dataset in Earth Engine. The pseudo-nonoccurrence sampling assumes that you have a perfect occurrence sample of the first class because it will select regions that are not near the first sample to create the other sample (if that makes any sense at all...). It might look something like this in code:



        var bands = ['B1', 'B2', 'B3', 'B4', 'B5', 'B6', 'B7']

        var image= ee.Image('LANDSAT/LT05/C01/T1_TOA/LT05_015036_20111025')
        .select(bands)

        // Train is the feature collection containing my training sites (points)
        var occurrence = image.sampleRegions({
        collection: train,
        properties: ['class'],
        scale: 30
        }).map(function(feature){
        return feature.set('class',ee.Number(1))
        });

        // Create geometry where there is no occurrence data
        var nonarea = image.geometry().difference(train.buffer(100))

        // Sample from region where there is no occurrence data
        var nonoccurrence = image.sample({
        region: nonarea,
        scale: 30
        }).map(function(feature){
        return feature.set('class',ee.Number(0))
        });

        // Merge the occurrence and non-occurrence feature collections
        var training = ee.FeatureCollection(occurrence.merge(nonoccurrence))

        var trained = ee.Classifier.cart().train(training, 'class', bands);

        // Classify the image with the same bands used for training.
        var classified = image.select(bands).classify(trained);


        (You may have to fix some of the data types in the above code, it was hard to test without sample data...). This is a commonly used approach in species distribution and disaster hazard modeling and hopefully is helpful for your use case!







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Dec 5 '18 at 3:41









        Kel MarkertKel Markert

        1163




        1163






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53464543%2fsupervised-classification-with-only-one-class-with-google-earth-engine%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Contact image not getting when fetch all contact list from iPhone by CNContact

            count number of partitions of a set with n elements into k subsets

            A CLEAN and SIMPLE way to add appendices to Table of Contents and bookmarks