How to 'unrotate' an image programmatically
This Help Article discusses how to 'unrotate' an image programmatically within ENVI. This applies when you are dealing with an image that has an arbitrary map rotation, resulting in north not being "up" in a visualization. This is a common occurence with data from sensors like ASTER. "Unrotating" the image ensures that north is always up.
ENVI's ROTATE_DOIT routine is based on IDL's ROTATE function and can only rotate an image by increments of 90 degrees. In some cases, it is desireable to 'unrotate' an image by an arbitrary amount so that the image is oriented north up. When this is performed in ENVI's Rotate/Flip Data tool, a separate code path is taken that essentially reprojects the data. To perform this programmatically, you have a couple of options. You can save your data to an IDL variable and use IDL's ROT function to rotate the data an arbitrary amount or you can use ENVI's ENVI_CONVERT_FILE_MAP_PROJECTION routine which will automatically orient the data north up via reprojection. ENVI_CONVERT_FILE_MAP_PROJECTION will allow the input projection to also be used as the output projection so that the only change will be a rotation to north. This is a quick and easy way to programmatically rotate ASTER images to a north up orientation. If you instead wish to rotate an image by an arbitrary amount that is not north up, IDL's ROT function should be used instead.
The following piece of code is an example of how to use ENVI's routine to unrotate a user-selected image. In this example, a rigorous warp method is used which can take significantly longer to process. You can select to use another warp method such as triangulation to reduce processing time.
pro example_envi_convert_file_map_projection
; Select the input file
envi_select, fid=fid, pos=pos, dims=dims
if (fid[0] eq -1) then return
;
; Setup the projection which is the same as the input projection
out_name = 'test.img'
o_proj = envi_get_projection (fid=fid, pixel_size=o_pixel_size)
;
; Call the doit
envi_convert_file_map_projection, fid=fid, $
pos=pos, dims=dims, o_proj=o_proj, $
o_pixel_size=o_pixel_size, $
out_name=out_name, warp_method=3, $
resampling=0, background=0
;
end
Review on 12/31/2013 MM