Hi!
I have problem with applying RESIZE_DOIT procedure with bilinear resampling
on georeferenced images. It seems to me that resulting image is shifted for
half size of pixel of original image to right and down, for any rfact<1. Is
it by design or there is a bug or am i doing something wrong.
I wrote small test routine to demonstrate this. If someone can just look at
it ...
Thanks,
Code:
PRO TEST_RESIZE_DOIT
compile_opt IDL2
envi, /restore_base_save_files
envi_batch_init, log_file='batch_log.txt'
imgName = 'C:\RSI\IDL63\products\envi43\data\bhtmref.img'
RFACT = REPLICATE(1.0/3.0, 2)
ENVI_OPEN_FILE, imgName, R_FID=fidOrig
mapInfo = ENVI_GET_MAP_INFO(FID=fidOrig)
; bound rect of some region
xCImg=[100, 110]
yCImg=[300, 310]
dimsC = [-1L, xCImg[0], xCImg[1]-1, yCImg[0], yCImg[1]-1]
ENVI_CONVERT_FILE_COORDINATES, fidOrig, xCImg, yCImg, $
xCMap, yCMap, /TO_MAP
;INTERP =0
ENVI_DOIT, 'RESIZE_DOIT', FID=fidOrig, DIMS=dimsC, $
POS=0, INTERP=0, RFACT=rfact, R_FID=fidRes, /IN_MEMORY
ENVI_FILE_QUERY, fidRes, NS=ns, NL=nl
;bound rect of whole image
; as i understand: center of UL pixel is [0.5, 0.5],
; and BR is [ns-0.5, nl-0.5]
xC1Img = [0, ns]
yC1Img = [0, nl]
dimsRes=[-1L, 0, ns-1, 0, nl-1]
ENVI_CONVERT_FILE_COORDINATES, fidRes, xC1Img, yC1Img, $
xC1Map, yC1Map, /TO_MAP
dataOrig = ENVI_GET_DATA(FID=fidOrig, DIMS=dimsC, POS=0)
dataRes0 = ENVI_GET_DATA(FID=fidRes, DIMS=dimsRes, POS=0)
ENVI_FILE_MNG, ID=fidRes, /REMOVE
PRINT, '*************** NEAREST NEIGHBOURHOOD (INTERPOL=0) *******
PRINT, 'Original pixel size: ', mapInfo.PS
PRINT, 'Resized pixel size; ', mapInfo.PS * rfact
PRINT, 'delta X: ', xC1Map - xCMap
PRINT, 'delta Y: ', yC1Map - yCMap
PRINT, 'Orig. data: ', SIZE(dataOrig, /DIMENSIONS)
PRINT, dataOrig
PRINT, 'Resized data:', SIZE(dataRes, /DIMENSIONS)
PRINT, dataRes0
;INTERP = 1
ENVI_DOIT, 'RESIZE_DOIT', FID=fidOrig, DIMS=dimsC, $
POS=0, INTERP=1, RFACT=rfact, R_FID=fidRes, /IN_MEMORY
ENVI_FILE_QUERY, fidRes, NS=ns, NL=nl
;bound rect of whole image
; as i understand: center of UL pixel is [0.5, 0.5],
; and BR is [ns-0.5, nl-0.5]
xC1Img = [0, ns]
yC1Img = [0, nl]
dimsRes=[-1L, 0, ns-1, 0, nl-1]
ENVI_CONVERT_FILE_COORDINATES, fidRes, xC1Img, yC1Img, $
xC1Map, yC1Map, /TO_MAP
dataOrig = ENVI_GET_DATA(FID=fidOrig, DIMS=dimsC, POS=0)
dataRes1 = ENVI_GET_DATA(FID=fidRes, DIMS=dimsRes, POS=0)
PRINT, '*************** BILINEAR (INTERPOL=1) *************
PRINT, 'Original pixel size: ', mapInfo.PS
PRINT, 'Resized pixel size; ', mapInfo.PS * rfact
PRINT, 'delta X: ', xC1Map - xCMap
PRINT, 'delta Y: ', yC1Map - yCMap
PRINT, 'Orig. data: ', SIZE(dataOrig, /DIMENSIONS)
PRINT, dataOrig
PRINT, 'Resized data:', SIZE(dataRes, /DIMENSIONS)
PRINT, dataRes1
PRINT, 'Difference: '
PRINT, BYTE((LONG(dataRes1) - dataRes0)+20)
ENVI_BATCH_EXIT
END
|