您的位置:首页 > 其它

ENVI\IDL 重采样 栅格单元大小设置

2017-07-13 17:32 393 查看
转载自:http://www.cnblogs.com/myyouthlife/archive/2012/07/01/2571785.html

在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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息