- 积分
- 3638
- 贡献
-
- 精华
- 在线时间
- 小时
- 注册时间
- 2014-10-21
- 最后登录
- 1970-1-1
|
楼主 |
发表于 2020-6-9 15:19:14
|
显示全部楼层
四、输出gif
IDL代码
PRO create_gif_animation
COMPILE_OPT IDL2
;gif的间隔时间,50大约是0.5秒:
delay_time=50
;输出gif文件路径:
outfname='C:\Users\Administrator\Desktop\aaa.gif'
;用于制作gif的多图文件夹:
figpath='C:\Users\Administrator\Desktop\XXX\word\media\**.png'
;读取图路径:
in_filenamelist=file_search(figpath)
;由于IDL是按字符串大小排序的,image10会排在image9前面,所以我要重新调整
;(IDL是按字符串大小排序的:1,10,11,...,19,2,20,21,...)
;读取图的文件名(可以批量哟):
names=file_basename(in_filenamelist)
book=-99;存放image叙述的向量
foreach i,names do begin
cut=strsplit(i,'.',/extract)
cut=strsplit(cut[0],'image',/extract)
book=[book,long(cut[0])];序数追加到数组
endforeach
book=book[1:-1];切除起始值
p=sort(book);对序数进行排序
in_filenamelist=in_filenamelist[p];对图名进行重新排序
;以下代码不用动!!!
file_nums = N_ELEMENTS(in_filenamelist)
IF (file_nums GT 0) AND ~STRCMP(in_filenamelist[0], '') THEN BEGIN
FOR i = 0, file_nums - 1 DO BEGIN
img = READ_IMAGE(in_filenamelist, red, green, blue)
img_s = SIZE(img)
;If the dimension of the img is 3-D, then convert it to a index image first.
IF (img_s[0] EQ 3) THEN BEGIN
img_idx = COLOR_QUAN(img[0, *, *], img[1, *, *], img[2, *, *], tbl_r, tbl_g, tbl_b)
;Reverse array in the second dimension.
img_idx = REFORM(img_idx)
WRITE_GIF, outfname, img_idx, tbl_r, tbl_g, tbl_b, $
DELAY_TIME = delay_time, /MULTIPLE, REPEAT_COUNT = 0
ENDIF
;If the dimension of the img is 2-D, then write it to the gif file directly.
IF (img_s[0] EQ 2) THEN BEGIN
img = REFORM(img)
IF (N_ELEMENTS(red) GT 0) AND (N_ELEMENTS(green) GT 0) AND (N_ELEMENTS(blue) GT 0) THEN BEGIN
WRITE_GIF, outfname, img, red, green, blue, DELAY_TIME = delay_time, /MULTIPLE, REPEAT_COUNT = 0
ENDIF
ENDIF
ENDFOR
WRITE_GIF, outfname, /CLOSE
ENDIF
END
|
|