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

在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

 

 

 

 

以下是使用IDL进行批量重采样改变图像空间分辨率的代码: ``` ;打开文件对话框,选择要重采样的图像文件 filelist = file_dialog('*.tif', /read, title='Select Files to Resample') ;设置输出目录和输出分辨率 output_dir = 'resampled_images/' new_res = [0.5, 0.5] ;新空间分辨率为0.5米/像素 ;循环处理每个选择的文件 for i=0, n_elements(filelist)-1 do begin ;读取原始图像文件 image = read_tiff(filelist[i], /silent) ;获取原始图像的空间分辨率和范围 old_res = [image.geo[0].dx, image.geo[0].dy] old_range = [image.geo[0].xmin, image.geo[0].ymin, $ image.geo[0].xmax, image.geo[0].ymax] ;计算新的图像大小和范围 new_size = round([(old_range[2]-old_range[0]) / new_res[0], $ (old_range[3]-old_range[1]) / new_res[1]]) new_range = [old_range[0], old_range[1], $ old_range[0]+new_res[0]*new_size[0]-new_res[0], $ old_range[1]+new_res[1]*new_size[1]-new_res[1]] ;创建新的图像文件 new_image = create_image(new_size[0], new_size[1], /unsigned) new_image.geo = {dx:new_res[0], dy:new_res[1], $ xmin:new_range[0], ymin:new_range[1], $ xmax:new_range[2], ymax:new_range[3]} ;执行重采样 resample, image, new_image ;保存重采样后的图像文件 filename = strmid(filelist[i], strlen(filelist[i])-7, 8) + '_resampled.tif' write_tiff, output_dir+filename, new_image, /silent endfor ``` 上述代码使用了IDL自带的`resample`函数进行重采样,并使用了`create_image`函数创建新的图像文件。注意,在读取原始图像文件时,使用了`/silent`选项来禁止输出读取信息,以避免干扰代码输出结果。如果需要更改重采样方法或参数,请查阅IDL帮助文档。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值