Using Isodata in Batch Mode ENVI: An Example
Help Article Update 2
Anonym
Unsupervised classification techniques are excellent ways to first see what kinds of categories or groups might be distinguishable in a given dataset. Isodata is a very popular unsupervised classification technique. It is a clustering algorithm that iteratively examines a dataset, attempting to place pixels in to categories according to some basic rules and parameters specified ahead of time by the user.
Isodata unsupervised classification calculates class means evenly distributed in the data space and then iteratively clusters the remaining pixels using minimum distance techniques. Each iteration recalculates means and reclassifies pixels with respect to the new means. Iterative class splitting, merging, and deleting is done based on input threshold parameters. All pixels are classified to the nearest class unless a standard deviation or distance threshold is specified, in which case some pixels may be unclassified if they do not meet the selected criteria. This process continues until the number of pixels in each class changes by less than the selected pixel change threshold or until the maximum number of iterations is reached. For technical details, see the following reference:
Tou, J. T. and R. C. Gonzalez, 1974. Pattern Recognition Principles, Addison-Wesley Publishing Company, Reading, Massachusetts.
Because of Isodata's usefulness in examining datasets, it is often used when large amounts of data are involved which might prohibit more labor-intensive supervised procedures. Batch mode ENVI programming is perfect for this demand. The CLASS_DOIT routine is used to call Isodata in batch mode, as well as to call other classification algorithms. Following is an example of how to use CLASS_DOIT in ENVI batch mode. For the purpose of demonstration, the dataset used is the sample bhtmref.img which comes with the ENVI distribution. In actual use, users could call CLASS_DOIT in a FOR loop to process a large number of images which could be selected programmatically or with DIALOG_PICKFILE.Solution:
pro example_isodata_batch
; Always include the following line when programming in ENVI.
compile_opt strictarr
; Tell your IDL session about ENVI
envi, /restore_base_save_files
; Initialize ENVI Batch Mode and send all errors
; and warnings to the log file batchlog.txt
envi_batch_init, log_file='batchlog.txt', /no_status_window
; Open the input file
envi_open_file, 'C:\RSI\IDL55\products\envi35\data\bhtmref.img', r_fid=input_fid, /no_realize
; Error checking. If the file doesn't open then you should exit the program.
; Note that "print" statements will go into your log file, batchlog.txt.
if (input_fid eq -1) then begin
print, 'Failure to open input file, exiting.'
envi_batch_exit
return
endif
; Get the samples, lines and # bands
; for the input file.
envi_file_query, input_fid, ns=ns, nl=nl, nb=nb
; Here, we'll set the dims and pos to classify all data (spatially and spectrally)
; in the file. You could optionally subset it if you wanted.
dims = [-1l, 0, ns-1, 0, nl-1]
pos = lindgen(nb)
; Now let's set up the required keyword inputs for classification.
out_name = 'isodata_result'
num_classes = nb + 1
out_bname='Isodata bhtmref'
iterations = 5
iso_merge_dist = 4.3
iso_merge_pairs = 2
iso_min_pixels = 50
iso_split_std = 35
min_classes = fix(nb/2)
; Here let's set some keywords that are optional for Isodata, for demonstration.
std_mult = 2.5
thresh = 25.0
iso_split_smult = 2.5
; Run the Isodata classification.
envi_doit, 'class_doit', fid = input_fid, pos = pos, dims = dims, $
out_bname = out_bname, out_name = out_name, method = 4, $
mean=mean, stdv=stdv, std_mult = std_mult, r_fid = result_fid, $
thresh = thresh, cov=cov, num_classes=num_classes, iterations = iterations, $
iso_merge_dist = iso_merge_dist, iso_merge_pairs = iso_merge_pairs, $
iso_min_pixels = iso_min_pixels, iso_split_std = iso_split_std, $
iso_split_smult = iso_split_smult, min_classes = fix(nb/2)
; Check to see that your result was produced.
if (result_fid eq -1) then begin
print, 'Isodata did not produce a valid result, exiting.'
envi_batch_exit
endif
; Exit the ENVI batch mode.
envi_batch_exit
; Don't forget to end your program.
end