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.



3652 Rate this article:
No rating

How to programmatically convert EVF files to ROIs

Topic:

Currently there is no established function or procedure to convert an ENVI Vector File (EVF) to a Region of Interest (ROI) programmatically. However, it can be accomplished using a small number of established routines. This Help Article discusses how to go about the conversion and provides a working example program.

Discussion:

 The following steps are recommended to programmatically convert an EVF file to an ROI:

1) Have an image available that you would like to associate with the ROI since ROIs are created based on available image dimensions. You can provide specific values for the number of samples and lines for the ROI if an image is unavailable.

2) Have all of your EVF files in the same directory, or at least be able to programmatically specify their locations if you are converting multiple files in batch mode.

3) Take each record in an EVF (polygon in this example), retrieve its defining vertices in map coordinates, convert the map coordinates to image coordinates, and then use the image-based vertices to build the ROI.

4) To differentiate ROIs from one another, retrieve the EVF layer name (one per file) and assign it to the ROI, along with a unique color starting with ENVI's default color index of 2 (Red).

pro evf_to_roi 
compile_opt idl2

;Prompt user to select an image to associated with the ROIs

base_file = dialog_pickfile(title='Select image file for ROI generation')

;Prompt user to provide directory containing all EVF files to convert
evf_files = file_search(dialog_pickfile(title='Select folder with EVF files', /directory), '*.evf')

;Prompt user to select output directory for ROI file
output_path = dialog_pickfile(title='Select output path for ROI file', /directory)

;Open the image, retrieve number of samples and lines
envi_open_file, base_file, r_fid=base_fid
    envi_file_query, base_fid, ns=ns, nl=nl 

;Removes any existing ROIs from the current ENVI session so ;that they are not included in the output .roi file
roi_cleanup = envi_get_roi_ids()
     envi_delete_rois, roi_cleanup 

;Loop through each record in an EVF file and use the records to
;build ROIs vertex by vertex
for i = 0, n_elements(evf_files)-1 do begin
evf_id = envi_evf_open(evf_files[i])
  ;Use original layer name as ROI name, when present
envi_evf_info, evf_id, num_recs=num_recs, layer_name=name
;Start ROI color assignment with Red
roi_color = 2 + i
roi_id = envi_create_roi(color=roi_color, ns=ns, nl=nl, name=name)
for j = 0, (num_recs - 1) do begin
rec = envi_evf_read_record(evf_id, j)
xmap = transpose(rec[0,*])
ymap = transpose(rec[1,*])
;Convert EVF map coordinates for each vertex to image
;coordinates for use in the ROI
envi_convert_file_coordinates, base_fid, xpts, ypts, xmap, ymap
envi_define_roi, roi_id, /polygon, xpts=xpts, ypts=ypts
endfor
envi_evf_close, evf_id
endfor

;Retrieve all generated ROIs and output a file that preserves associated
;colors and names
roi_ids = envi_get_roi_ids(roi_names=roi_names, /short_name, roi_colors=colors)
envi_save_rois, output_path+path_sep()+file_basename(base_file)+'.roi', roi_ids

end

Review 9/11/20104 by CS
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 »