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.



8692 Rate this article:
4.0

How to calculate image RMSE between two images

This Help Article contains a small user function that can be used to calculate and return the RMSE statistic between two images.

pro calculate_image_RMSE_define_buttons, buttonInfo
    compile_opt idl2
  
    ;Create button so that the program can be called from within ENVI.
    ;Button will appear under File->Basic Tools->Statistics ->Calculate Image RMSE.
  
    envi_define_menu_button, buttonInfo, value = 'Calculate Image RMSE', $
        event_pro='calculate_image_RMSE', POSITION='last', ref_value = 'Statistics', $
        uvalue='Calculate Image RMSE'
  
end
;==============================================
  
pro calculate_image_RMSE, event
    compile_opt idl2
  
    ;select the first input band
    envi_select, fid=fid1, /band_only, dims=dims1, pos=pos1, title='Select first band'
    if (fid1[0] eq -1) then return
  
    ;select the second input band
    envi_select, fid=fid2, /band_only, dims=dims2, pos=pos2, title='Select second band'
    if (fid2[0] eq -1) then return
  
    envi_file_query, fid1, ns=ns, nl=nl, nb=nb
  
    ;Create output file
    output_file = dialog_pickfile(title='Select Output File Name and Location')
    if output_file eq '' then return
  
    ;calculate the total number of pixels for the equation
    total_pixels = ns*nl
  
    ;open a file for writing
    openw, lun, output_file, /get_lun
  
    ;this sets up a status report while the calculation runs
    envi_report_init, title='RMSE calculation', $
        ['Accessing data from original file...','Creating RMSE Image...'], $
        base=base, /interrupt
    envi_report_inc, base, nl-1
  
        ;Set up for loop to grab data slices line by line
        for i=0, nl-1 do begin
            envi_report_stat, base, i, nl-1, cancel=cancel
            if cancel eq 1 then begin
                envi_report_init, base=base, /finish
                free_lun, lun
                file_delete, output_file
                return
            endif
                slice1 = envi_get_slice(fid=fid1, line=i, pos=pos1, xs=0, xe=ns-1)
                slice2 = envi_get_slice(fid=fid2, line=i, pos=pos2, xs=0, xe=ns-1)
                result = sqrt(((float(slice1) - float(slice2))^2)/total_pixels)
                writeu, lun, result
        endfor
  
        envi_report_init, base=base, /finish
        ;set up the header for the new data file
        envi_setup_head, nb=1, data_type=4, fname=output_file, $
            interleave=0, ns=ns, nl=nl, offset=0, /write
  
    free_lun, lun
  
    ;open the file in ENVI's ABL
    envi_open_file, output_file
  

    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 »