X

Help Articles are product support tips and information straight from the NV5 Geospatial Technical Support team developed to help you use our products to their fullest potential.



2886 Rate this article:
No rating

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

Please login or register to post comments.
Featured

End-of-Life Policy Enforcement for ENVI 5.3 / IDL 8.5 and Earlier Versions

5/6/2024

April 1, 2024 Dear ENVI/IDL Customer,  We are reaching out to notify you of our supported... more »

How to Upgrade licenses to ENVI 6.x / IDL 9.x

12/5/2023

What is the new Upgrade function? Starting with ENVI 6.0 and IDL 9.0, we have implemented an... more »

What to do if the 'License Administrator - License Server' for the Next-Generation License Server does not start?

6/13/2023

Background: With the release of ENVI 5.7 & IDL 8.9 and the corresponding Next-Generation licensing... more »

Next-Generation Licensing FAQ

4/28/2023

  NV5 Geospatial has adopted a new licensing technology for all future releases of our ENVI, IDL... more »

The IDL Virtual Machine

6/6/2013

What is the IDL Virtual Machine? An IDL Virtual Machine is a runtime version of IDL that can... more »