IDL中将影像像素存为数组

/ 0评 / 0
;返回浮点型一维数组
function ConvertToOneF, data
; i为行数
; j为列数
columns=n_elements(data[0,*])
rows=n_elements(data[*,0])
result = fltarr(columns*rows)
for i=0L, rows-1 do begin
for j=0L, columns-1 do begin
result[columns*i + j] = float(data[i,j])
endfor
endfor
return, result
end

;返回整型一维数组
function ConvertToOneD, data
; i为行数
; j为列数
columns=n_elements(data[0,*])
rows=n_elements(data[*,0])
result = intarr(columns*rows)
for i=0L, rows-1 do begin
for j=0L, columns-1 do begin
result[columns*i + j] = long(data[i,j])
endfor
endfor
return, result
end

;读取影像,二维浮点型数组
function Get_IMGArrayF2, filepath, map_info
ENVI_OPEN_FILE,filepath,r_fid = fid
IF fid EQ -1 THEN RETURN,-1
ENVI_FILE_QUERY,fid,ns = ns,nl = nl, nb=nb, $
interleave=interleave, dims=dims, xstart=xstart, ystart=ystart
arr = float(envi_get_data(fid=fid,dims=dims,pos=0))
map_info=envi_get_map_info(fid=fid)
ENVI_FILE_MNG, id=fid, /remove 
return, arr
end

;读取影像,二维整型数组
function Get_IMGArrayL2, filepath, map_info
ENVI_OPEN_FILE,filepath,r_fid = fid
IF fid EQ -1 THEN RETURN,-1
ENVI_FILE_QUERY,fid,ns = ns,nl = nl, nb=nb, $
interleave=interleave, dims=dims, xstart=xstart, ystart=ystart
arr = long(envi_get_data(fid=fid,dims=dims,pos=0))
map_info=envi_get_map_info(fid=fid)
ENVI_FILE_MNG, id=fid, /remove 
return, arr
end

;读取影像,一维浮点型数组
function Get_IMGArrayF1, filepath, map_info
ENVI_OPEN_FILE,filepath,r_fid = fid
IF fid EQ -1 THEN RETURN,-1
ENVI_FILE_QUERY,fid,ns = ns,nl = nl, nb=nb, $
interleave=interleave, dims=dims, xstart=xstart, ystart=ystart
arr = float(envi_get_data(fid=fid,dims=dims,pos=0))
map_info=envi_get_map_info(fid=fid)
ENVI_FILE_MNG, id=fid, /remove 
return, ConvertToOneF(arr)
end

;读取影像,一维整型数组
function Get_IMGArrayL1, filepath, map_info
ENVI_OPEN_FILE,filepath,r_fid = fid
IF fid EQ -1 THEN RETURN,-1
ENVI_FILE_QUERY,fid,ns = ns,nl = nl, nb=nb, $
interleave=interleave, dims=dims, xstart=xstart, ystart=ystart
arr = long(envi_get_data(fid=fid,dims=dims,pos=0))
map_info=envi_get_map_info(fid=fid)
ENVI_FILE_MNG, id=fid, /remove 
return, ConvertToOneD(arr)
end

 

发表评论

邮箱地址不会被公开。 必填项已用*标注