X
PrevPrev Go to previous topic
NextNext Go to next topic
Last Post 11 May 2018 10:47 AM by  Prabha Rupasinghe
SVM classification for multiple scenes with one set of ROIs
 6 Replies
Sort:
You are not authorized to post a reply.
Author Messages

Prabha Rupasinghe



New Member


Posts:22
New Member


--
08 May 2018 10:06 AM
    I am trying to classify Sentinel 2 images for a very large area using the SVM classification. Currently, I can only process an area about 25 sq km at a time to get the desired accuracy. I also explored other classification methods but only SVM gives me good accuracy for my purpose. As my area is very large, it takes me ever to define ROIs for small pieces of images. Is there a way I can use a single set on ROIs for all my pieces? Or is there any other method to make this process easier and faster?
    Any help is greatly appreciated. Thank you.

    MariM



    Veteran Member


    Posts:2396
    Veteran Member


    --
    08 May 2018 10:12 AM
    You can use the newer Classification Framework which also uses the SVM algorithm but you can supply one set of training data for multiple images after you generate the classifier:
    http://www.harrisgeospati...VISVMClassifier.html

    Prabha Rupasinghe



    New Member


    Posts:22
    New Member


    --
    08 May 2018 05:39 PM
    Thank you for the suggestion. I tried to edit the code but I keep on getting error messages. I am very poor with programming. Is there any tools I can use other than using the IDL codes?

    MariM



    Veteran Member


    Posts:2396
    Veteran Member


    --
    10 May 2018 07:05 AM
    I am afraid that the classification framework is available through the API only. What sort of errors are you receiving? Can you run the sample code with the sample data?

    Prabha Rupasinghe



    New Member


    Posts:22
    New Member


    --
    10 May 2018 04:30 PM
    I did not try with the given images. I managed to get rod of my error messages and run both SVMClassificationusingObjects and ApplySVMTrainedClassifier. First out put comes as I expect but the second output only have two classes (I am trying to classify into 8 classes). I tried with both sentinel 2 and landsat 8 data and got similar results. I have several questions about applying the classifier.
    1. In the example, it asks to update the code as ROIfile = 'TrainingDataROIs.xml' for the ApplySVMTrainedClassifier. But I do not see where to change this. So I added this command from the classification using obects. Is this ok?
    2. When updating the gains and offsets, I used the the gain and offset values for the second image that I am trying to classify. Is this correct.?
    3. Most of the area in my image are masked. Could this be a problem?

    Prabha Rupasinghe



    New Member


    Posts:22
    New Member


    --
    10 May 2018 08:39 PM
    I think I figured out what's wrong. I used the gains and offsets generated from the first set of codes and it worked! Thank you!

    Prabha Rupasinghe



    New Member


    Posts:22
    New Member


    --
    11 May 2018 10:47 AM
    I am trying to loop the ApplySVMTrainedClassifier to multiple files. I included some additional codes to do this. I am getting error at line 61 ( raster = e.OpenRaster(file)) saying;

    % Invalid input for filename, must be a scalar string
    % Execution halted at: APPLYSVMTRAINEDCLASSIFIER 61 C:\Users\ChowFras\AppData\Local\Temp\applysvmtrainedclassifier.pro
    % $MAIN$



    Below is the code I am using now. I have added a line of stars at the start of the new codes to loop the files and before the line I am getting error. Can you please help me to get this fixed?

    PRO ApplySVMTrainedClassifier
    COMPILE_OPT IDL2
    ; Start the application
    e = ENVI()

    ; Open an attribute raster to classify
    file = 'FLAASH.hdr'
    raster = e.OpenRaster(file)

    ; Open training data ROIs
    ROIfile = 'TrainingDataROIs.xml'
    rois = e.OpenROI(ROIfile)

    ; Normalize the attribute image using the
    ; previously recorded gains and offsets
    gain = [0.00028893383, 0.00027631943,0.00025608195, 0.00016105653, 0.00021829295, 0.00019872814, 0.00018508236, 0.00016900456, 0.00021376657, 0.00029515939]
    offset = [-0.24537576, -0.30148087, -0.33031915, -0.48204199, -0.36862689 , -0.50192095, -0.52861240, -0.53657914, -0.53154062, -0.48786404]
    normalizedRaster = ENVIGainOffsetRaster(raster, gain, offset)

    ; Get the trained classifier. This is a persistable object
    ; in the form of an IDL save file that needs to be restored
    ; from disk
    trainedClassifierURI = 'C:\Users\ChowFras\AppData\Local\Temp\TrainedSVMClassifier.epo'
    trainedClassifier = ENVIRestoreObject(trainedClassifierURI)

    ; Classify a different attribute image
    classRaster = ENVIClassifyRaster(normalizedRaster, trainedClassifier)

    ; Get the classification raster metadata
    numClasses = classRaster.Metadata['Classes']
    classNames = classRaster.Metadata['Class Names']

    ; Display the result
    view = e.GetView()
    layer = view.CreateLayer(raster)
    layer2 = view.CreateLayer(classRaster)
    view.Zoom, /FULL_EXTENT

    ******************************************************************************
    ;Find all the files with .dat extensions in a directory.

    search_dir = 'I:\idl'

    filelist = file_search(search_dir + '*.hdr')

    ;Set a base for your output files that will be appended to.

    outbase = 'I:\idl\SVM_'



    ;Loop over every file.

    ;Open the raster, set parameters, and execute the task.

    foreach file, filelist, index do begin
    *********************************************
    raster = e.OpenRaster(file)

    task.input_raster = raster

    task.output_raster_uri = outbase + strtrim(index, 2)

    task.Execute

    endforeach

    END

    You are not authorized to post a reply.