Hello,
I have a question about calculating class statistics. My current code performs an unsupervised classification on a batch of 25 images. I would now like to add the ability to calculate class statistics for the outputs but have so far been unsuccessful in getting this additional step to run. I believe I need to add another foreach command but am not sure how to pull my new classified images back in without having to somehow list them as I have for the initial batchfiles. In addition to this BIG issue, I have a couple of subsequent questions which I below. Following these questions is a copy of my current code.
I recognize this is probably not the most elegant way to have performed this procedure, but for my experience and IDL skill level it is what has been working for me.
Any input would be greatly appreciated.
QUESTIONS:
1.) Do I have my new fid and dims correctly labeled as being based on my classification output (i.e. CLASS_FID=classifi01_fid) where classifi01 is the R_fid from the classification run?
2.) Do I need the line for the "envi_file_query"?
CODE:
pro ISODATA_classification_and_ClassStats_batch25
compile_opt idl2
on_error, 2
; General error handler
Catch, error
if (error ne 0) then begin
Catch, /CANCEL
if obj_valid(envi) then $
envi.ReportError, "Error: " + !error_state.msg
message, /RESET
return
endif
envi=ENVI()
batchfiles = ["C:\Users\ahudson-dunn\Desktop\CLASSIFICATION\Input Files\25_image RGB\2012-10-12_38383C.JPG", $
"C:\Users\ahudson-dunn\Desktop\CLASSIFICATION\Input Files\25_image RGB\2012-10-12_39390A.JPG", $
"C:\Users\ahudson-dunn\Desktop\CLASSIFICATION\Input Files\25_image RGB\2012-10-12_40392D.JPG", $
"C:\Users\ahudson-dunn\Desktop\CLASSIFICATION\Input Files\25_image RGB\2012-10-19_36078C.JPG", $
"C:\Users\ahudson-dunn\Desktop\CLASSIFICATION\Input Files\25_image RGB\2012-10-19_36079A.JPG", $
"C:\Users\ahudson-dunn\Desktop\CLASSIFICATION\Input Files\25_image RGB\2012-10-19_40392A.JPG", $
"C:\Users\ahudson-dunn\Desktop\CLASSIFICATION\Input Files\25_image RGB\2012-10-19_BARED.JPG", $
"C:\Users\ahudson-dunn\Desktop\CLASSIFICATION\Input Files\25_image RGB\2012-10-26_38785C.JPG", $
"C:\Users\ahudson-dunn\Desktop\CLASSIFICATION\Input Files\25_image RGB\2012-11-04_28043C.JPG", $
"C:\Users\ahudson-dunn\Desktop\CLASSIFICATION\Input Files\25_image RGB\2012-11-16_35275C.JPG", $
"C:\Users\ahudson-dunn\Desktop\CLASSIFICATION\Input Files\25_image RGB\2012-11-16_38382E.JPG", $
"C:\Users\ahudson-dunn\Desktop\CLASSIFICATION\Input Files\25_image RGB\2012-11-16_39990C.JPG", $
"C:\Users\ahudson-dunn\Desktop\CLASSIFICATION\Input Files\25_image RGB\2012-11-30_36078B.JPG", $
"C:\Users\ahudson-dunn\Desktop\CLASSIFICATION\Input Files\25_image RGB\2012-12-06_25631A.JPG", $
"C:\Users\ahudson-dunn\Desktop\CLASSIFICATION\Input Files\25_image RGB\2012-12-06_27233B.JPG", $
"C:\Users\ahudson-dunn\Desktop\CLASSIFICATION\Input Files\25_image RGB\2013-01-23_26837C.JPG", $
"C:\Users\ahudson-dunn\Desktop\CLASSIFICATION\Input Files\25_image RGB\2013-01-23_27234A.JPG", $
"C:\Users\ahudson-dunn\Desktop\CLASSIFICATION\Input Files\25_image RGB\2013-01-23_38785B.JPG", $
"C:\Users\ahudson-dunn\Desktop\CLASSIFICATION\Input Files\25_image RGB\2013-02-21_25631A.JPG", $
"C:\Users\ahudson-dunn\Desktop\CLASSIFICATION\Input Files\25_image RGB\2013-04-01_27233B.JPG", $
"C:\Users\ahudson-dunn\Desktop\CLASSIFICATION\Input Files\25_image RGB\2013-04-01_36078A.JPG", $
"C:\Users\ahudson-dunn\Desktop\CLASSIFICATION\Input Files\25_image RGB\2013-04-01_38782C.JPG", $
"C:\Users\ahudson-dunn\Desktop\CLASSIFICATION\Input Files\25_image RGB\2013-04-01_40389C.JPG", $
"C:\Users\ahudson-dunn\Desktop\CLASSIFICATION\Input Files\25_image RGB\2013-04-26_26430A.JPG", $
"C:\Users\ahudson-dunn\Desktop\CLASSIFICATION\Input Files\25_image RGB\2013-04-26_36078C.JPG"]
foreach file, batchfiles do begin
rasterloop = envi.OpenRaster(file)
rasterloop_fid = ENVIRasterToFID(rasterLoop)
envi_file_query, rasterloop_fid, DIMS=rasterloop_dims, NB=rasterloop_nb, BNAMES=rasterloop_bnames, FNAME=rasterloop_fname
; Perform unsupervised classification.
envi_doit, 'class_doit', FID=rasterloop_fid, DIMS=rasterloop_dims, POS=Lindgen(rasterloop_nb), $
METHOD=4, NUM_CLASSES=10, MIN_CLASSES=10, ITERATIONS=10, $
ISO_MERGE_DIST=5.0, ISO_SPLIT_STD=1, ISO_MIN_PIXELS=30, ISO_MERGE_PAIRS=2, CHANGE_THRESH=5.0, $
OUT_BNAME='Classification ('+File_basename(rasterloop_fname)+')', $
R_FID=classif01_fid, OUT_NAME=envi.getTemporaryFilename()
envi_file_query, classif01_fid, DIMS=classif01_dims, NB=classif01_nb, BNAMES=classif01_bnames, FNAME=classif01_fname
; Output image classification to ENVI format.
basename = (strsplit(file_basename(file), '.', /extract))[0]
envi_output_to_external_format, FID=classif01_fid, DIMS=classif01_dims, POS=Lindgen(classif01_nb), $
/ENVI, OUT_NAME='C:\Users\ahudson-dunn\Desktop\CLASSIFICATION\ENVI\IDL\Batch\RGB\25 image\10 Classes\'+basename+'_ISO_10.dat'
endforeach
for each file, ?????????? do begin
; Perform class statistics calculation.
ENVI_Doit, 'Class_Stats_Doit', CLASS_FID=classif01_fid, CLASS_DIMS=classifi01_dims, CLASS_PTR = [0,1,2,3,4,5,6,7,8,9,10], $
COMP_FLAG = 0, FID=stats01_fid, REPORT_FLAG = 0, POS = Lindgen(classif01_nb), $
REP_BNAME='Class Statistics ('+File_basename(rasterloop_fname)+')', $
envi_file_query, stats01_fid, DIMS=stats01_dims, NB=stats01_nb, BNAMES=stats01_bnames, FNAME=stats01_fname
; Output image statistics to .txt format.
basename = (strsplit(file_basename(file), '.', /extract))[0]
envi_output_to_external_format, FID=stats01_fid, DIMS=stats01_dims, POS=Lindgen(stats01_nb), $
/ENVI, OUT_NAME='C:\Users\ahudson-dunn\Desktop\CLASSIFICATION\ENVI\IDL\Batch\RGB\25 image\10 Classes\'+basename+'_ISO_10_class_report.txt'
endforeach
end
|