由庞大的遥感影像(全色或多光谱的GeoTiff文件或ENVI文件)生成10MB以下的jpg格式图片,便于对遥感影像有初步的认知,RGBBands为RGB组合波段(全色可忽略),Resample用于调整是否进行重采样至256大小,使结果更加精简。源码:
PRO QULK
COMPILE_OPT IDL2
Inputfile = 'D:\IDL_Workspace\IMG_QB\MS.tif'
Outputfile = 'D:\MS.jpg'
RGBBands = [4,3,2] ;If Imagery Is One-band, Ignore It
Resample = 1 ;1 Stands for Resample to size 256, and 0 Stands for NOT
GetQULK, Inputfile, Outputfile, RGBBands, Resample
END
PRO GetQULK, Inputfile, Outputfile, Bands, Resample
e = ENVI(/Headless)
Pos = STRSPLIT(Inputfile, '\')
R = STRMID(Inputfile, Pos[-1], STRLEN(Inputfile)-1)
CASE STRPOS(R, '.tif') OF
-1: BEGIN ;ENVI Format Image File
ENVI_OPEN_FILE, Inputfile, r_fid = fid
ENVI_FILE_QUERY, fid, ns = ns, nl = nl,$
nb = nb, dims = dims, data_type = data_type
IF nb EQ 1 THEN BEGIN ;One-band
Arr = ENVI_GET_DATA(fid = fid, dims = dims, pos = 0)
IF Resample EQ 1 THEN Arr = CONGRID_TO_256(Arr)
GRACPHIC_SAVE, Arr, Outputfile
ENDIF ELSE BEGIN ;Multi-band
TempArr = MAKE_ARRAY(3, ns, nl, Type = data_type)
FOR i=0,2,1 DO BEGIN
Pstn = Bands[i] - 1
TempArr[i, *, *] = ENVI_GET_DATA(fid = fid,$
dims = dims, pos = Pstn)
ENDFOR
IF Resample EQ 1 THEN TempArr = CONGRID_TO_256(TempArr)
GRACPHIC_SAVE, TempArr, Outputfile
ENDELSE
END
ELSE: BEGIN ;GeoTiff Format
Arr = READ_TIFF(Inputfile)
ArrSize = SIZE(Arr, /Dimensions)
Dimensions = SIZE(ArrSize, /N_Elements)
IF Dimensions EQ 2 THEN BEGIN ;One-band
IF Resample EQ 1 THEN Arr = CONGRID_TO_256(Arr)
GRACPHIC_SAVE, Arr, Outputfile
ENDIF ELSE BEGIN ;Multi-band
ArrType = SIZE(Arr, /Type)
TempArr = MAKE_ARRAY(3, ArrSize[1], ArrSize[2], Type = ArrType)
FOR i=0, 2, 1 DO BEGIN
Pstn = Bands[i] - 1
TempArr[i, *, *] = Arr[Pstn, *, *]
ENDFOR
IF Resample EQ 1 THEN TempArr = CONGRID_TO_256(TempArr)
GRACPHIC_SAVE, TempArr, Outputfile
ENDELSE
END
ENDCASE
END
PRO GRACPHIC_SAVE, Arr, Outputfile
Graphic = IMAGE(Arr, /Buffer, /Order)
Graphic.SAVE, Outputfile
END
FUNCTION CONGRID_TO_256, Arr
ArrSize = SIZE(Arr, /Dimensions)
Dimensions = N_ELEMENTS(ArrSize)
IF Dimensions EQ 2 THEN BEGIN ;One-band
Maxnum = MAX([ArrSize[0], ArrSize[1]])
Factor = FIX(Maxnum / 256)
Arr = CONGRID(Arr, ArrSize[0] / Factor, ArrSize[1] / Factor, /Center)
ENDIF ELSE BEGIN ;Multi-band
Maxnum = MAX([ArrSize[1], ArrSize[2]])
Factor = FIX(Maxnum / 256)
Arr = CONGRID(Arr, ArrSize[0], ArrSize[1] / Factor, ArrSize[2] / Factor, /Center)
ENDELSE
RETURN, Arr
END