3226 Why are there differences between stretches applied to the display and those applied to the file? This Help Article discusses why there are differences in the pixel values when you apply a stretch to a display and when you apply a stretch to a file in ENVI. The results from using the ENVI routine, stretch_doit, are different than if the stretch is applied to a displayed band and saved to a file. The example used is ENVI's sample dataset, bhtmref.img. If you display band 1 of this file, there is a default 2% stretch applied to the display window. The resulting pixel values are different than if you run the following routine, which performs the same 2% stretch: ---------------------------------------------- pro example_stretch_doit envi, /restore_base_save_files envi_batch_init, log_file='batch.txt' envi_open_file, 'c:\rsi\idl61\products\envi41\data\bhtmref.img', r_fid=fid if (fid eq -1) then begin envi_batch_exit return endif envi_file_query, fid, ns=ns, nl=nl, nb=nb dims = [-1l, 0, ns-1, 0, nl-1] pos = lindgen(nb) out_name = 'test_stretch' envi_doit, 'stretch_doit', $ fid=fid, pos=pos, dims=dims, $ method=1, out_name=out_name, $ i_min=2.0, i_max=98.0, range_by=0, $ out_min=0, out_max=255, out_dt=1, $ r_fid=r_fid envi_batch_exit end ---------------------------------------------- So, what is different about saving from the display here? For percent stretches, ENVI does a special stretch for the display case, which really can't be reproduced. ENVI's default 2% stretch, if the histogram is "normal" looking (i.e. more than three bins), will calculate the left hand percent stretch on hist[1:*] and the right hand percent stretch on hist[0:n_elements(hist)-2]. If the histogram is a normal gaussian shaped curve, then the difference between this and the "full" histogram is negligible. However, if there is a large saturation of min or max values (such as an image with a lot of background), then ENVI's default stretch will ignore the spike and calculate the percent stretch based on the rest of the "real" histogram. This allows ENVI to display, by default, many images which otherwise would not stretch well with a 2% linear stretch since they contain more than 2% background. This is the difference observed in the pixel values and there is not a way for ENVI_STRETCH_DOIT to reproduce the exact same results. Review on 12/31/2013 MM ENVI 4.2 Access the PID of a process spawned by IDL (UNIX / Linux / Mac OS X) before SPAWN returns