| 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
 
 
 |