Hello,
I'm trying to run an unsupervised classification (ISODATA) with the same mask image on jpg files in a folder through a loop and put the output files in another folder. I get the classification running ok, using a code for batch generating NDVI images that I found some time ago on the ITT website. I tried to modify this code to do the ISODATA classification that generates two classes and should apply a mask also. However, the outputs I get don't have the mask applied but instead the mask is loaded only into ENVI.
There's also a few issues with the output file names, but that's not a big problem, as long as the output files have the mask applied.
If there's anyone out there who can help me fix the code (see below), I'd appreciate it.
Thanks,
Mike
pro ml_batch_01
compile_opt idl2
;set up path to input and output files
input_path = 'C:\B_Working\__ML_test\ml_in01\'
;change to output directory where I want the processed files to be placed
cd, 'C:\B_Working\__ML_test\ml_out01\'
; search for data files in the specified directory
files = FILE_SEARCH(input_path + '*.jpg', count=count)
IF (count EQ 0) THEN BEGIN
PrintF, 'No files were found to process'
ENDIF
for i=0, count-1 do begin
envi_open_file, files[i], r_fid=fid
if (fid eq -1) then begin
envi_batch_exit
return
endif
envi_file_query, fid, dims=dims, ns=ns, nl=nl, fname=filename
;; ML: setting up the mask file
maskfile = 'C:\B_Working\Niina_data_16May2011\__ML_test\temp\ml_mask42'
ENVI_OPEN_FILE, maskfile, r_fid=m_fid
if (m_fid eq -1) then return
envi_file_query, m_fid, dims=dims, nb=nb
;set pos array for calculating ISODATA (CLASS_DOIT method=4)
pos = [1,2,3] - 1
;set the output file names by stripping out the base name and appending '_unsup.tif'
out_name = file_basename(filename, '.jpg') + '_unsup.tif'
;call the doit for the unsupervised ISODATA classification
envi_doit, 'class_doit', $
fid=fid, pos=pos, dims=dims, $
/check, o_min=0, o_max=255, $
out_name=out_name, r_fid=r_fid, mfid=mfid, mpos=mpos, value=0, $
method=4, change_thresh=0.05, iso_merge_dist=5, $ ; method 4 is isodata
iso_min_pixels=10, min_classes=2, max_classes=2, num_classes=2, iterations=5, $
iso_split_std=1.0, iso_merge_pairs=2
endfor
end
|