[IDL] 아이디엘 지구물리 원격탐사 실습 자료 : JPG 형식인 Skyview RGB 영상을 이용한 이미지 처리

 정보

  • 업무명    : 지구물리 원격탐사 실습 자료 : JPG 형식인 Skyview RGB 영상을 이용한 이미지 처리

  • 작성자    : 이상호

  • 작성일    : 2020-03-25

  • 설   명    :

  • 수정이력 :

 

 내용

[개요]

  • 안녕하세요? 기상 연구 및 웹 개발을 담당하고 있는 해솔입니다.

  • 대학원 석사 1학기에 배운 지구물리 원격탐사에 대한 실습 내용을 다루고자 합니다.

  • 오늘 포스팅에서는 JPG 형식인 Skyview RGB 영상을 이용한 이미지 처리를 소개해 드리고자 합니다.

  • 추가로 지구물리 원격탐사에 대한 이론적 배경을 소개한 링크를 보내드립니다.

 

[강릉원주대 대기환경과학과] 2015년 2학기 전선 지구물리 원격탐사 소개 및 과제물

정보 업무명 : 2015년 2학기 전선 지구물리 원격탐사 소개 및 과제물 작성자 : 이상호 작성일 : 2019-12-20 설 명 : 수정이력 : 내용 [특징] 지구물리 원격탐사 수업에 대한 이해를 돕기위해 작성 [기능] 소개 주..

shlee1990.tistory.com

 

[특징]

  • RGB 영상을 이해하기 위해서 이미지 처리 기술이 요구되며 이 프로그램은 이러한 목적을 달성하기 위해 고안된 소프트웨어

 

[기능]

  • RGB 이미지 영상 읽기

  • Red, Green, Blue 영상 분할 및 합성

  • 빈도 분포 가시화

  • 마스킹 (Masking)

 

[활용 자료]

  • 자료명 : 20120720_1535.JPG

  • 자료 종류 : Skyview RGB 영상

  • 확장자 : JPG

  • 영역 : 관측소 지점

  • 기간 : 2012년 07월 20일 15:35 KST

  • 시간 해상도 : 매 5분

  • 제공처 : 복사-위성 연구소

 

20120720_1535.JPG

 

[사용법]

  • 입력 자료를 동일 디렉터리에 위치

  • 소스 코드를 실행 (idl -e Visualization_Using_Skyview_RGB_Image)

  • 가시화 결과를 확인

 

[사용 OS]

  • Linux

  • Windows 10

 

[사용 언어]

  • IDL v8.5

 

 소스 코드

  • 해당 작업을 하기 위한 컴파일 및 실행 코드는 IDL로 작성되었으며 가시화를 위한 라이브러리는 CIMSS/SSEC Library를 이용하였습니다.

  • 소스 코드는 단계별로 수행하며 상세 설명은 다음과 같습니다.

    • 1 단계는 주 프로그램은 작업 경로 설정, HDF 파일 읽기, 변수 전처리하여 메모리상에 저장하고 가시화를 위한 초기 설정합니다.

    • 일반적으로 포스트 스크립트 (PS) 형식에서 PNG로 변환하나 오랜 시간이 소요되는 단점이 있습니다. 따라서 2 단계에서는 imagemap를 통해 영상 표출하여 이미지 형식으로 저장합니다. 

 

[명세]

  • 전역 변수 설정

    • 이미지 검사 여부 (iop_chk_img_val)

    • 이미지 저장 여부 (iop_img)

    • Skyview 사례 설정 (fn1)

    • 저장 이미지 설정 (pn_img*)

    • Skyview 이미지 영상 크기 설정 (nxx, nyy)

iop_chk_img_val=0 ; set to 1 to check the RGB values of sky image
iop_img=1

path='C:\SYSTEM\PROG\IDL\RSEE_idl_1_sky_image\'  ; input data path

fn1='20120720_1535.JPG'  ; input jpeg file (a total sky image)
pn1=path+fn1
sFileDate = strmid(fn1,0,13)

print, pn1


pn_img0=pn1+'Visualization_Using_Skyview_RGB_Image'+sFileDate+'_img0.png'
pn_img1=pn1+'Visualization_Using_Skyview_RGB_Image'+sFileDate+'_img1.png'
pn_img2=pn1+'Visualization_Using_Skyview_RGB_Image'+sFileDate+'_img2.png'
pn_img3=pn1+'Visualization_Using_Skyview_RGB_Image'+sFileDate+'_img3.png'
pn_img4=pn1+'Visualization_Using_Skyview_RGB_Image'+sFileDate+'_img4.png'
pn_img5=pn1+'Visualization_Using_Skyview_RGB_Image'+sFileDate+'_img5.png'
pn_img6=pn1+'Visualization_Using_Skyview_RGB_Image'+sFileDate+'_img6.png'

print, pn_img0


;;
xbeg=0 & xend=639 & nxx=xend-xbeg+1
ybeg=0 & yend=479 & nyy=yend-ybeg+1
print, 'nxx, nyy=', nxx, nyy

 

etc-image-1

 

  • Skyview 이미지 영상 읽기

read_jpeg, pn1, newimg1, true=1  ; read the jpeg image in the memory

 

  • Skyview 이미지 영상을 이용한 전처리

    • RGB 영상에서 Red, Green, Blue 채널 영상 분할

szarr=size(newimg1)       ; check the dimension and size of variable
nxgrd=long(szarr[2]) & nygrd=long(szarr[3])
;
red=fltarr(nxx,nyy) & grn=fltarr(nxx,nyy) & blu=fltarr(nxx,nyy)
red_x=fltarr(nxx,nyy) & grn_x=fltarr(nxx,nyy) & blu_x=fltarr(nxx,nyy)

red[0:nxx-1,0:nyy-1]=newimg1[0,xbeg:xend,ybeg:yend]
grn[0:nxx-1,0:nyy-1]=newimg1[1,xbeg:xend,ybeg:yend]
blu[0:nxx-1,0:nyy-1]=newimg1[2,xbeg:xend,ybeg:yend]

red_x=red & grn_x=grn & blu_x=blu

rbrat=red_x/blu_x  


good=where(red_x ge 40 and blu_x ge 40, ngood)
bad=where(red_x lt 40 or blu_x lt 40, nbad)

red_x[bad]=0
grn_x[bad]=0
blu_x[bad]=0
print, 'ngood, nbad ', ngood, nbad

 

  • Red 영상을 위한 설정 및 가시화

    • tv를 통해 Red 채널 표출

    • saveimage를 통해 png 형식으로 이미지 저장

;==================================
window, 0, xsize=nxx, ysize=nyy
device, decomposed=1
;==================================
tv, red_x, channel=1

if (iop_img eq 1) then saveimage, pn_img0, /png

 

20120720_1535.JPGVisualization_Using_Skyview_RGB_Image20120720_1535_img0.png

 

  • Green 영상을 위한 설정 및 가시화

    • tv를 통해 Green 채널 표출

    • saveimage를 통해 png 형식으로 이미지 저장

;==================================
window, 1, xsize=nxx, ysize=nyy
device, decomposed=1
;==================================
tv, grn_x, channel=2

if (iop_img eq 1) then saveimage, pn_img1, /png

 

20120720_1535.JPGVisualization_Using_Skyview_RGB_Image20120720_1535_img1.png

 

  • Blue 영상을 위한 설정 및 가시화

    • tv를 통해 Blue 채널 표출

    • saveimage를 통해 png 형식으로 이미지 저장

;==================================
window, 2, xsize=nxx, ysize=nyy
device, decomposed=1
;==================================
tv, blu_x, channel=3

if (iop_img eq 1) then saveimage, pn_img2, /png

 

20120720_1535.JPGVisualization_Using_Skyview_RGB_Image20120720_1535_img2.png

 

  • RGB 영상을 위한 설정 및 가시화

    • tv를 통해 RGB 합성 영상 표출

    • saveimage를 통해 png 형식으로 이미지 저장

;==================================
window, 3, xsize=nxx, ysize=nyy
device, decomposed=1
;==================================
tv, red_x, channel=1
tv, grn_x, channel=2
tv, blu_x, channel=3

loadcolors  ; load color table

if (iop_img eq 1) then saveimage, pn_img3, /png

 

20120720_1535.JPGVisualization_Using_Skyview_RGB_Image20120720_1535_img3.png

 

  • 빈도 분포를 위한 설정 및 가시화

    • hist_plot를 통해 Red / Blue 비율 (rbrat)에 대한 빈도 분포 표출

    • 빈도 분포 결과 1을 기준으로 구분

    • saveimage를 통해 png 형식으로 이미지 저장

;==================================
window, 4, xsize=800, ysize=600
device, decomposed=0
;==================================
minx=0. & maxx=2.0 & miny=0. & maxy=0.1 & nbin=100 & binsize=(maxx-minx)/nbin
hist_plot, rbrat[good], min=minx, max=maxx, binsize=binsize $
         , /normal, xstyle=3, color=0, background=7 $
         , yrange=[miny,maxy], xrange=[minx,maxx] $
         , xtitle='RB Ratio', ytitle='Normalized Frequency'


cmask=fltarr(nxx,nyy)
gd=where(rbrat gt 1, ngd)
if(ngd gt 0) then cmask[gd]=255B

loadct, 39

if(iop_img eq 1) then saveimage, pn_img4, /png

 

20120720_1535.JPGVisualization_Using_Skyview_RGB_Image20120720_1535_img4.png

 

  • 구름 영역 외 마스킹 영상을 위한 설정 및 가시화

    • saveimage를 통해 png 형식으로 이미지 저장

;==================================
window, 5, xsize=nxx, ysize=nyy
device, decomposed=0
;==================================
tv, cmask

if(iop_img eq 1) then saveimage, pn_img5, /png

 

20120720_1535.JPGVisualization_Using_Skyview_RGB_Image20120720_1535_img5.png

 

  • 구름 마스킹 영상을 위한 설정 및 가시화

    • saveimage를 통해 png 형식으로 이미지 저장

;==================================
window, 6, xsize=nxx, ysize=nyy
device, decomposed=0
;==================================
cmask[bad]=0B
tv, cmask

if(iop_img eq 1) then saveimage, pn_img6, /png

 

20120720_1535.JPGVisualization_Using_Skyview_RGB_Image20120720_1535_img6.png

 

  • 가시화에 필요한 라이브러리

;===================================================================================
PRO LOADCOLORS, BOTTOM=BOTTOM, NAMES=NAMES

;- Check arguments
if (n_elements(bottom) eq 0) then bottom = 0

;- Load McIDAS graphics colors
red = [  0, 255,   0, 255,   0, 255,   0, 255, $
         0, 255, 255, 112, 219, 127,   0, 255, $
        90,  50, 150, 255]
grn = [  0,   0, 255, 255, 255,   0,   0, 255, $
         0, 187, 127, 219, 112, 127, 163, 171, $
        90,  50, 50, 90]
blu = [  0, 255, 255,   0,   0,   0, 255, 255, $
       115,   0, 127, 147, 219, 127, 255, 127, $
        90,  50, 255, 200]
tvlct, red, grn, blu, bottom

;- Set color names
names = [ 'Black', 'Magenta', 'Cyan', 'Yellow', 'Green', 'Red', 'Blue', 'White', $
          'Navy', 'Gold', 'Pink', 'Aquamarine', 'Orchid', 'Gray', 'Sky', 'Beige', $
          'DarkGray', 'GraphiteGray', 'Purple', 'FlowerPink' ]

END
;===================================================================================


;===================================================================================
PRO HIST_PLOT, DATA, MIN=MIN_VALUE, MAX=MAX_VALUE, $
  BINSIZE=BINSIZE, NORMALIZE=NORMALIZE, FILL=FILL, $
  _EXTRA=EXTRA_KEYWORDS

;- Check arguments
if n_params() ne 1 then message, 'Usage: HIST_PLOT, DATA'
if n_elements(data) eq 0 then message, 'DATA is undefined'

;- Check keywords
if n_elements(min_value) eq 0 then min_value = min(data)
if n_elements(max_value) eq 0 then max_value = max(data)
if n_elements(binsize) eq 0 then $
  binsize = (max_value - min_value) * 0.01
binsize = binsize > ((max_value - min_value) * 1.0e-5)

;- Compute histogram
hist = histogram(float(data), binsize=binsize, $
  min=min_value, max=max_value)
hist = [hist, 0L]
nhist = n_elements(hist)

;- Normalize histogram if required
if keyword_set(normalize) then $
  hist = hist / float(n_elements(data))

;- Compute bin values
bins = lindgen(nhist) * binsize + min_value

;- Create plot arrays
x = fltarr(2 * nhist)
x[2 * lindgen(nhist)] = bins
x[2 * lindgen(nhist) + 1] = bins
y = fltarr(2 * nhist)
y[2 * lindgen(nhist)] = hist
y[2 * lindgen(nhist) + 1] = hist
y = shift(y, 1)

;- Plot the histogram
plot, x, y, _extra=extra_keywords

;- Fill the histogram if required
if keyword_set(fill) then $
  polyfill, [x, x[0]], [y, y[0]], _extra=extra_keywords

END

PRO SAVEIMAGE, FILE, $
  BMP=BMP, PNG=PNG, GIF=GIF, JPEG=JPEG, TIFF=TIFF, $
  QUALITY=QUALITY, DITHER=DITHER, CUBE=CUBE, QUIET=QUIET

  ;- Check arguments
  if (n_params() ne 1) then $
    message, 'Usage: SAVEIMAGE, FILE'
  if (n_elements(file) eq 0) then $
    message, 'Argument FILE is undefined'
  if (n_elements(quality) eq 0) then quality = 75

  ;- Get output file type
  output = 'JPEG'
  if keyword_set(bmp)  then output = 'BMP'
  if keyword_set(png)  then output = 'PNG'
  if keyword_set(gif)  then output = 'GIF'
  if keyword_set(jpeg) then output = 'JPEG'
  if keyword_set(tiff) then output = 'TIFF'

  ;- Check if GIF output is available
  version = float(!version.release)
  if (version ge 5.4) and (output eq 'GIF') then $
    message, 'GIF output is not available'

  ;- Get contents of graphics window,
  ;- and color table if needed
  image = screenread(depth=depth)
  if (depth le 8) then tvlct, r, g, b, /get

  ;- Write 8-bit output file
  if (output eq 'BMP') or $
    (output eq 'PNG') or $
    (output eq 'GIF') then begin

    ;- If image depth is 24-bit, convert to 8-bit
    if (depth gt 8) then begin
      case keyword_set(cube) of
        0 : image = color_quan(image, 1, r, g, b, $
          colors=256, dither=keyword_set(dither))
        1 : image = color_quan(image, 1, r, g, b, cube=6)
      endcase
    endif

    ;- Reverse PNG image order if required
    if (output eq 'PNG') and (version le 5.3) then $
      image = reverse(temporary(image), 2)

    ;- Save the image
    case output of
      'BMP'  : write_bmp, file, image, r, g, b
      'PNG'  : write_png, file, image, r, g, b
      'GIF'  : write_gif, file, image, r, g, b
    endcase

  endif

  ;- Write 24-bit output file
  if (output eq 'JPEG') or $
    (output eq 'TIFF') then begin

    ;- Convert 8-bit image to 24-bit
    if (depth le 8) then begin
      info = size(image)
      nx = info[1]
      ny = info[2]
      true = bytarr(3, nx, ny)
      true[0, *, *] = r[image]
      true[1, *, *] = g[image]
      true[2, *, *] = b[image]
      image = temporary(true)
    endif

    ;- Reverse TIFF image order
    if (output eq 'TIFF') then $
      image = reverse(temporary(image), 3)

    ;- Write the image
    case output of
      'JPEG' : write_jpeg, file, image, $
        true=1, quality=quality
      'TIFF' : write_tiff, file, image, 1
    endcase

  endif

  ;- Report to user
  if (keyword_set(quiet) eq 0) then $
    print, file, output, $
    format='("Created ",a," in ",a," format")'

END

FUNCTION SCREENREAD, X0, Y0, NX, NY, DEPTH=DEPTH

  ;- Check arguments
  if (n_elements(x0) eq 0) then x0 = 0
  if (n_elements(y0) eq 0) then y0 = 0
  if (n_elements(nx) eq 0) then nx = !d.x_vsize - x0
  if (n_elements(ny) eq 0) then ny = !d.y_vsize - y0

  ;- Check for TVRD capable device
  tvrd_true = !d.flags and 128
  if (tvrd_true eq 0) then message, $
    'TVRD is not supported on this device: ' + !d.name

  ;- On devices which support windows, check for open window
  win_true = !d.flags and 256
  if (win_true gt 0) and (!d.window lt 0) then message, $
    'No graphics window are open'

  ;- Get IDL version number
  version = float(!version.release)

  ;- Get display depth
  depth = 8
  if (win_true gt 0) then begin
    if (version ge 5.1) then begin
      device, get_visual_depth=depth
    endif else begin
      if (!d.n_colors gt 256) then depth = 24
    endelse
  endif

  ;- Set decomposed color mode on 24-bit displays
  if (depth gt 8) then begin
    entry_decomposed = 0
    if (version gt 5.1) then $
      device, get_decomposed=entry_decomposed
    device, decomposed=1
  endif

  ;- Get the contents of the window
  if (depth gt 8) then true = 1 else true = 0
  image = tvrd(x0, y0, nx, ny, order=0, true=true)

  ;- Restore decomposed color mode on 24-bit displays
  if (depth gt 8) then device, decomposed=entry_decomposed

  ;- Return result to caller
  return, image

END

;===================================================================================

 

[전체] 

PRO Visualization_Using_Skyview_RGB_Image
iop_chk_img_val=0 ; set to 1 to check the RGB values of sky image
iop_img=1
path='C:\SYSTEM\PROG\IDL\RSEE_idl_1_sky_image\' ; input data path
fn1='20120720_1535.JPG' ; input jpeg file (a total sky image)
pn1=path+fn1
sFileDate = strmid(fn1,0,13)
print, "pn1 : ", pn1
pn_img0=pn1+'Visualization_Using_Skyview_RGB_Image'+sFileDate+'_img0.png'
pn_img1=pn1+'Visualization_Using_Skyview_RGB_Image'+sFileDate+'_img1.png'
pn_img2=pn1+'Visualization_Using_Skyview_RGB_Image'+sFileDate+'_img2.png'
pn_img3=pn1+'Visualization_Using_Skyview_RGB_Image'+sFileDate+'_img3.png'
pn_img4=pn1+'Visualization_Using_Skyview_RGB_Image'+sFileDate+'_img4.png'
pn_img5=pn1+'Visualization_Using_Skyview_RGB_Image'+sFileDate+'_img5.png'
pn_img6=pn1+'Visualization_Using_Skyview_RGB_Image'+sFileDate+'_img6.png'
print, "pn_img0 : ", pn_img0
;;
xbeg=0 & xend=639 & nxx=xend-xbeg+1
ybeg=0 & yend=479 & nyy=yend-ybeg+1
print, 'nxx, nyy=', nxx, nyy
;
read_jpeg, pn1, newimg1, true=1 ; read the jpeg image in the memory
;
;help, newimg1 ; , newimg2
szarr=size(newimg1) ; check the dimension and size of variable
nxgrd=long(szarr[2]) & nygrd=long(szarr[3])
;
red=fltarr(nxx,nyy) & grn=fltarr(nxx,nyy) & blu=fltarr(nxx,nyy)
red_x=fltarr(nxx,nyy) & grn_x=fltarr(nxx,nyy) & blu_x=fltarr(nxx,nyy)
red[0:nxx-1,0:nyy-1]=newimg1[0,xbeg:xend,ybeg:yend]
grn[0:nxx-1,0:nyy-1]=newimg1[1,xbeg:xend,ybeg:yend]
blu[0:nxx-1,0:nyy-1]=newimg1[2,xbeg:xend,ybeg:yend]
red_x=red & grn_x=grn & blu_x=blu
rbrat=red_x/blu_x
good=where(red_x ge 40 and blu_x ge 40, ngood)
bad=where(red_x lt 40 or blu_x lt 40, nbad)
red_x[bad]=0
grn_x[bad]=0
blu_x[bad]=0
print, 'ngood, nbad ', ngood, nbad
;==================================
window, 0, xsize=nxx, ysize=nyy
device, decomposed=1
;==================================
tv, red_x, channel=1
if (iop_img eq 1) then saveimage, pn_img0, /png
;==================================
window, 1, xsize=nxx, ysize=nyy
device, decomposed=1
;==================================
tv, grn_x, channel=2
if (iop_img eq 1) then saveimage, pn_img1, /png
;==================================
window, 2, xsize=nxx, ysize=nyy
device, decomposed=1
;==================================
tv, blu_x, channel=3
if (iop_img eq 1) then saveimage, pn_img2, /png
;==================================
window, 3, xsize=nxx, ysize=nyy
device, decomposed=1
;==================================
tv, red_x, channel=1
tv, grn_x, channel=2
tv, blu_x, channel=3
loadcolors ; load color table
if (iop_img eq 1) then saveimage, pn_img3, /png
;==================================
window, 4, xsize=800, ysize=600
device, decomposed=0
;==================================
minx=0. & maxx=2.0 & miny=0. & maxy=0.1 & nbin=100 & binsize=(maxx-minx)/nbin
hist_plot, rbrat[good], min=minx, max=maxx, binsize=binsize $
, /normal, xstyle=3, color=0, background=7 $
, yrange=[miny,maxy], xrange=[minx,maxx] $
, xtitle='RB Ratio', ytitle='Normalized Frequency'
cmask=fltarr(nxx,nyy)
gd=where(rbrat gt 1, ngd)
if(ngd gt 0) then cmask[gd]=255B
loadct, 39
if(iop_img eq 1) then saveimage, pn_img4, /png
;==================================
window, 5, xsize=nxx, ysize=nyy
device, decomposed=0
;==================================
tv, cmask
if(iop_img eq 1) then saveimage, pn_img5, /png
;==================================
window, 6, xsize=nxx, ysize=nyy
device, decomposed=0
;==================================
cmask[bad]=0B
tv, cmask
if(iop_img eq 1) then saveimage, pn_img6, /png
print, 'Program run successfully -- Stop'
;===================================================================================
;The end of main program
;===================================================================================
END
;===================================================================================
;===================================================================================
PRO LOADCOLORS, BOTTOM=BOTTOM, NAMES=NAMES
;- Check arguments
if (n_elements(bottom) eq 0) then bottom = 0
;- Load McIDAS graphics colors
red = [ 0, 255, 0, 255, 0, 255, 0, 255, $
0, 255, 255, 112, 219, 127, 0, 255, $
90, 50, 150, 255]
grn = [ 0, 0, 255, 255, 255, 0, 0, 255, $
0, 187, 127, 219, 112, 127, 163, 171, $
90, 50, 50, 90]
blu = [ 0, 255, 255, 0, 0, 0, 255, 255, $
115, 0, 127, 147, 219, 127, 255, 127, $
90, 50, 255, 200]
tvlct, red, grn, blu, bottom
;- Set color names
names = [ 'Black', 'Magenta', 'Cyan', 'Yellow', 'Green', 'Red', 'Blue', 'White', $
'Navy', 'Gold', 'Pink', 'Aquamarine', 'Orchid', 'Gray', 'Sky', 'Beige', $
'DarkGray', 'GraphiteGray', 'Purple', 'FlowerPink' ]
END
;===================================================================================
;===================================================================================
PRO HIST_PLOT, DATA, MIN=MIN_VALUE, MAX=MAX_VALUE, $
BINSIZE=BINSIZE, NORMALIZE=NORMALIZE, FILL=FILL, $
_EXTRA=EXTRA_KEYWORDS
;- Check arguments
if n_params() ne 1 then message, 'Usage: HIST_PLOT, DATA'
if n_elements(data) eq 0 then message, 'DATA is undefined'
;- Check keywords
if n_elements(min_value) eq 0 then min_value = min(data)
if n_elements(max_value) eq 0 then max_value = max(data)
if n_elements(binsize) eq 0 then $
binsize = (max_value - min_value) * 0.01
binsize = binsize > ((max_value - min_value) * 1.0e-5)
;- Compute histogram
hist = histogram(float(data), binsize=binsize, $
min=min_value, max=max_value)
hist = [hist, 0L]
nhist = n_elements(hist)
;- Normalize histogram if required
if keyword_set(normalize) then $
hist = hist / float(n_elements(data))
;- Compute bin values
bins = lindgen(nhist) * binsize + min_value
;- Create plot arrays
x = fltarr(2 * nhist)
x[2 * lindgen(nhist)] = bins
x[2 * lindgen(nhist) + 1] = bins
y = fltarr(2 * nhist)
y[2 * lindgen(nhist)] = hist
y[2 * lindgen(nhist) + 1] = hist
y = shift(y, 1)
;- Plot the histogram
plot, x, y, _extra=extra_keywords
;- Fill the histogram if required
if keyword_set(fill) then $
polyfill, [x, x[0]], [y, y[0]], _extra=extra_keywords
END
PRO SAVEIMAGE, FILE, $
BMP=BMP, PNG=PNG, GIF=GIF, JPEG=JPEG, TIFF=TIFF, $
QUALITY=QUALITY, DITHER=DITHER, CUBE=CUBE, QUIET=QUIET
;- Check arguments
if (n_params() ne 1) then $
message, 'Usage: SAVEIMAGE, FILE'
if (n_elements(file) eq 0) then $
message, 'Argument FILE is undefined'
if (n_elements(quality) eq 0) then quality = 75
;- Get output file type
output = 'JPEG'
if keyword_set(bmp) then output = 'BMP'
if keyword_set(png) then output = 'PNG'
if keyword_set(gif) then output = 'GIF'
if keyword_set(jpeg) then output = 'JPEG'
if keyword_set(tiff) then output = 'TIFF'
;- Check if GIF output is available
version = float(!version.release)
if (version ge 5.4) and (output eq 'GIF') then $
message, 'GIF output is not available'
;- Get contents of graphics window,
;- and color table if needed
image = screenread(depth=depth)
if (depth le 8) then tvlct, r, g, b, /get
;- Write 8-bit output file
if (output eq 'BMP') or $
(output eq 'PNG') or $
(output eq 'GIF') then begin
;- If image depth is 24-bit, convert to 8-bit
if (depth gt 8) then begin
case keyword_set(cube) of
0 : image = color_quan(image, 1, r, g, b, $
colors=256, dither=keyword_set(dither))
1 : image = color_quan(image, 1, r, g, b, cube=6)
endcase
endif
;- Reverse PNG image order if required
if (output eq 'PNG') and (version le 5.3) then $
image = reverse(temporary(image), 2)
;- Save the image
case output of
'BMP' : write_bmp, file, image, r, g, b
'PNG' : write_png, file, image, r, g, b
'GIF' : write_gif, file, image, r, g, b
endcase
endif
;- Write 24-bit output file
if (output eq 'JPEG') or $
(output eq 'TIFF') then begin
;- Convert 8-bit image to 24-bit
if (depth le 8) then begin
info = size(image)
nx = info[1]
ny = info[2]
true = bytarr(3, nx, ny)
true[0, *, *] = r[image]
true[1, *, *] = g[image]
true[2, *, *] = b[image]
image = temporary(true)
endif
;- Reverse TIFF image order
if (output eq 'TIFF') then $
image = reverse(temporary(image), 3)
;- Write the image
case output of
'JPEG' : write_jpeg, file, image, $
true=1, quality=quality
'TIFF' : write_tiff, file, image, 1
endcase
endif
;- Report to user
if (keyword_set(quiet) eq 0) then $
print, file, output, $
format='("Created ",a," in ",a," format")'
END
FUNCTION SCREENREAD, X0, Y0, NX, NY, DEPTH=DEPTH
;- Check arguments
if (n_elements(x0) eq 0) then x0 = 0
if (n_elements(y0) eq 0) then y0 = 0
if (n_elements(nx) eq 0) then nx = !d.x_vsize - x0
if (n_elements(ny) eq 0) then ny = !d.y_vsize - y0
;- Check for TVRD capable device
tvrd_true = !d.flags and 128
if (tvrd_true eq 0) then message, $
'TVRD is not supported on this device: ' + !d.name
;- On devices which support windows, check for open window
win_true = !d.flags and 256
if (win_true gt 0) and (!d.window lt 0) then message, $
'No graphics window are open'
;- Get IDL version number
version = float(!version.release)
;- Get display depth
depth = 8
if (win_true gt 0) then begin
if (version ge 5.1) then begin
device, get_visual_depth=depth
endif else begin
if (!d.n_colors gt 256) then depth = 24
endelse
endif
;- Set decomposed color mode on 24-bit displays
if (depth gt 8) then begin
entry_decomposed = 0
if (version gt 5.1) then $
device, get_decomposed=entry_decomposed
device, decomposed=1
endif
;- Get the contents of the window
if (depth gt 8) then true = 1 else true = 0
image = tvrd(x0, y0, nx, ny, order=0, true=true)
;- Restore decomposed color mode on 24-bit displays
if (depth gt 8) then device, decomposed=entry_decomposed
;- Return result to caller
return, image
END
;===================================================================================

 

 참고 문헌

[논문]

  • 없음

[보고서]

  • 없음

[URL]

  • 없음

 

 문의사항

[기상학/프로그래밍 언어]

  • sangho.lee.1990@gmail.com

[해양학/천문학/빅데이터]

  • saimang0804@gmail.com