在ENVI\IDL 下圖像重采用是用Resize_doit 函數。該函數能用來改變圖像的大小和對圖像重采樣。
該函數有個參數RFACT。
RFACT
Use this keyword to specify a two-element array holding the rebin factors for x and y. The values of RFACT reflect the IDL convention for resizing data. A value of 1 does not change the size of the data. Values less than 1 cause the size to increase; values greater than 1 cause the size to decrease.
從以上可以看出,當Refact的Value大於1 到時候就是 放大圖像,小與1就是縮小圖像。
通過官方給出的實例:
PRO EXAMPLE_RESIZE_DOIT compile_opt IDL2 ; First restore all the base save files. envi, /restore_base_save_files ; Initialize ENVI and send all errors ; and warnings to the file batch.txt envi_batch_init, log_file='batch.txt' ; Open the input file envi_open_file, 'can_tmr.img', r_fid=fid if (fid eq -1) then begin envi_batch_exit return endif ; Set the POS keyword to process all ; spectral data. Output the result ; to disk. envi_file_query, fid, dims=dims, nb=nb pos = lindgen(nb) out_name = 'testimg' ; Perform the resize calculation. ; Make the output image twice as ; large in both X and Y. Use ; bilinear interpolation. envi_doit, 'resize_doit', $ fid=fid, pos=pos, dims=dims, $ interp=1, rfact=[.5,.5], $ out_name=out_name, r_fid=r_fid END
由於RFACT=[*,*]是浮點數表示,其重采樣比率的計算方法是:采樣后分辨率/采樣前分辨率。如果原圖像是20m,要采樣成100m分辨率,RFACT=[100/20,100/20],即RFACT=[5,5],這個好理解。
但是個問題: 1. 如果在不知道原始圖像的分辨率的基礎上,要定量的設置重采樣到30m的時候怎么設置倍數。
問題的解決辦法就是在代碼中加入獲取原始圖像的像元大小的代碼!
proj=envi_get_projection(fid=fid,PIXEL_SIZE=ps,units=units)
其中ps 為原圖像的像元大小。
則可以將幫助中的程序更改如下:
PRO EXAMPLE_RESIZE_DOIT, pixelSizeAfterResample compile_opt IDL2 ; First restore all the base save files. envi, /restore_base_save_files ; Initialize ENVI and send all errors ; and warnings to the file batch.txt envi_batch_init, log_file='batch.txt' ; Open the input file envi_open_file, 'can_tmr.img', r_fid=fid if (fid eq -1) then begin envi_batch_exit return endif ; Set the POS keyword to process all ; spectral data. Output the result ; to disk. envi_file_query, fid, dims=dims, nb=nb pos = lindgen(nb) out_name = 'testimg' ; Perform the resize calculation. ;Make the output image twice as ; large in both X and Y. Use ; bilinear interpolation. envi_doit, 'resize_doit', $ fid=fid, pos=pos, dims=dims, $ interp=1, rfact=[pixelSizeAfterResample/ps,pixelSizeAfterResample/ps], $ out_name=out_name, r_fid=r_fid END