2883
How to parse the class statistics text file to get class distribution of classes with no pixels
Currently, ENVI's CLASS_STATS_DOIT returns a statistic report to the screen that includes the Class Distribution Summary but not in the output ENVI statistics file. This information is included in the text file if you choose to output to a text file. This Help Article is an example of how to parse the text file to extract the class distribution information and create a plot of the data.
====================
pro parse_class_stats_file
envi_select, title = 'select class image', fid=cfid
envi_select, title = 'select stats image', fid=fid
envi_file_query, cfid, num_classes=num_classes
print, 'num_classes is', num_classes
class_ptr = indgen(num_classes)
envi_file_query, fid, dims=dims, ns=ns, nl=nl, nb=nb
pos = lindgen(nb)
out_name = 'class_stats.txt'
envi_doit, 'class_stats_doit', fid=fid, pos=pos, $
dims=dims, comp_flag=1, report_flag=1, $
rep_name=out_name, class_fid=cfid, hist=hist, $
class_ptr=class_ptr
nlines = file_lines('class_stats.txt')
stat_text= strarr(nlines)
openr, unit, 'class_stats.txt', /get_lun
readf, unit, stat_text
free_lun, unit
class_line_nums = where (strmid(stat_text, 0, 5) eq 'Class', nmatches)
unclass_line_num = where(strmid(stat_text, 0, 5) eq 'Uncla', n_matches2)
points_arr = lonarr(nmatches+n_matches2-1, 2)
i = 0
if n_matches2 gt 0 then begin
points_arr[0, 0] = 0
tmp = strsplit(stat_text[unclass_line_num[0]], /extract)
points_arr[0, 1] = long(strjoin(strsplit(tmp[1], ',', /extract)))
i++
endif
while i lt nmatches do begin
tmp = strsplit(stat_text[class_line_nums[i]], /extract)
points_arr[i, 0] = long( (strsplit(tmp[1], ':', /extract))[0] )
points_arr[i, 1] = long(strjoin(strsplit(tmp[2], ',', /extract)))
i++
endwhile
x = points_arr[*, 0]
y = points_arr[*, 1]
envi_plot_data, x, y, xtitle = 'Class', ytitle = '# Pixels', plot_title = 'Class histogram'
end
Review on 12/31/2013 MM