Thanks to Peg and the wonders of google, I was able to put together a script that uses 3 bands (NIR,Blue,Green) to unsupervise class via isodata on a small subset of my study area. i still need to test it on my big area but that will take many hours, so i will report back when that is fully done!
This script will look into a folder where all your input images are and process them all using the isodata method. i am only concerned with land and water so this scripts works fine me. i
I figured i would share in case someone else needs something like this. there is a few extra lines of code that are not really needed but i left it in as it taught me how to do things a bit better. documentation for later you can call it.
the only thing i need now is to figure out how to apply a mask to my big images...
cheers.
nola
;---------------------------------------------------------------------------
forward_function ENVI_OPEN_FILE, ENVI_BATCH_INIT
; script to batch classify using isodata to create land masks
;
;---------------------------------------------------------------------------
;NEED THIS OR CODE WONT WORK
;First restore all the base save files.
envi, /restore_base_save_files
; Initialize ENVI and send all errors and warnings to the file batch.txt
envi_batch_init, log_file= 'G:\casi\00idlTest\batch.txt'
;---------------------------------------------------------------------------
;hardcode input and output folders for data and mask files
datin = 'G:\casi\00idlTest\dat'
maskin = 'G:\casi\00idlTest\mask'
datout = 'G:\casi\00idlTest\results'
;input data extension and output name
datext = '*.pix'
out_name=datout+'\test.pix'
;returns all the filenames into an array
datfiles = file_search(datin, datext)
;maskfiles = file_search(maskin, datext)
;print, datfiles
;print, maskfiles
;2 methods to return the number of files in the array
;q=n_elements(datfiles) ;elegant method
;not so elegent method
z=size(datfiles)
numFiles = z[1]
;print,'There are ', numFiles, ' files in the input folder.'
;opens, reads and isodata class all the data images in ENVI
for i = 0, n_elements(datfiles)-1 do begin
filename = datfiles[i,0]
; Open the input file in ENVI
envi_open_file, filename, r_fid=fid
if (fid eq -1) then begin
envi_batch_exit
return
endif
; Get the spatial dimensions and # of bands for the input file.
envi_file_query, fid, dims=dims, nb=nb
;ENVI ISODATA classification
ENVI_DOIT, 'class_doit', fid=fid, pos=[24,13,8], dims=dims,$
out_bname='ISOData_test', out_name=out_name, method=4, $
r_fid=r_fid, iterations=1, change_thresh = 0, iso_merge_dist= 1, $
iso_merge_pairs=3, iso_min_pixels=50, iso_split_smult=1, $
iso_split_std=0, min_classes=5, num_classes=7, in_memory=0
endfor
;envi_batch_exit
end
|