在遙感圖像處理中,,我們看到的圖像是某些物理量經(jīng)過線性拉伸到0-255的灰度級后所表現(xiàn)的形式,,而其真正的物理意義并不能通過所顯示的圖像表達出來,這時就需要一個常用的工具——色標來進行處理,色標是將顯示圖像的數(shù)值對應(yīng)到其真實物理量的一個有效手段,。
但是,,在通過色標建立了顯示圖像到真實物理量的對應(yīng)關(guān)系后,遇到了一個問題——就是當我們對顯示圖像作了處理(亮度,、對比度,、線性拉伸,直方圖均衡化等)以后,,如何對色標進行處理的問題,。由于當我們對顯示圖像做了處理以后,顯示圖像的灰度發(fā)生了變化,,因此色標也必須改變,,以確保顯示圖像對應(yīng)到的物理量不發(fā)生變化。
如何使色標也跟隨顯示圖像的變化而變化呢,?
1.如果用比較笨的辦法,,可以使用循環(huán),遍歷每一個處理后圖像的像素和處理前圖像像素的關(guān)系,,但還是會有些問題,,因為圖像中在某個灰度級的像素個數(shù)可能為零,總之這時一個廢時費事的辦法,。
2.如果用比較聰明的辦法,,那就是本次的重點,請看下面的例子,。
;
;==========================================================================
pro luttest_draw, ev
compile_opt strictarr
widget_control,ev.top,get_uvalue=pstate
uname = widget_info(ev.id,/uname)
;屏幕坐標轉(zhuǎn)換到圖像坐標
x = ev.x
y = ev.y-30
if y lt 0 then return
;**注意:對原始圖像使用探針,即只對顯示圖像作處理
value = (*pstate).image[x,y]
;狀態(tài)欄更新
widget_control,(*pstate).wstatus[0],set_value='X:'+strtrim(string(x),2)
widget_control,(*pstate).wstatus[1],set_value='Y:'+strtrim(string(y),2)
widget_control,(*pstate).wstatus[2],set_value='VALUE:'+strtrim(string(value),2)
end
;
;==========================================================================
pro luttest_setcolorbar, pstate, displayimage
compile_opt strictarr
;獲取顯示圖像中的色標矢量,,此時色標矢量已經(jīng)跟隨顯示圖像做了處理。
lut = displayimage[0:255,0]
(*pstate).opalette->getproperty, red=r, green=g, blue=b
nr = r[lut]
ng = g[lut]
nb = b[lut]
(*pstate).ocbPalette->setproperty, red=nr, green=ng, blue=nb
end
;
;==========================================================================
pro luttest_tools, ev
compile_opt strictarr
widget_control,ev.top,get_uvalue=pstate
uname = widget_info(ev.id,/uname)
(*pstate).oimage->getproperty, data=displayimage
case uname of
'hist':displayimage = bytscl(hist_equal(displayimage))
'reverse':displayimage = 255-displayimage
'revert':begin
displayimage = bytscl((*pstate).image)
displayimage[0:255,0] = bindgen(256)
end
else:
endcase
luttest_setcolorbar, pstate, displayimage
(*pstate).oimage->setproperty, data=displayimage
(*pstate).owin->draw
end
;
;==========================================================================
pro luttest_cleanup, tlb
compile_opt strictarr
widget_control, tlb, get_uvalue=pstate
heap_free,pstate
end
;
;==========================================================================
pro luttest
compile_opt strictarr
;讀取數(shù)據(jù),到原始圖像image
file = FILEPATH('surface.dat', SUBDIR=['examples', 'data'])
image = intarr(350,450)
openr, lun, file, /get_lun
readu, lun, image
free_lun, lun
;復(fù)制一份,,拉伸到0-255作為顯示圖像
displayimage = bytscl(image)
;把0-255的線性矢量寫到顯示圖像的第一行,,讓其跟隨顯示圖像作處理
displayimage[0:255,0] = bindgen(256)
;創(chuàng)建界面
tlb = widget_base(/column)
wtoolsbase = widget_base(tlb,/row,event_pro='luttest_tools')
whist = widget_button(wtoolsbase,value='直方圖均衡化',uname='hist')
wreverse = widget_button(wtoolsbase,value='反相',uname='reverse')
wrevert = widget_button(wtoolsbase,value='還原',uname='revert')
wdraw = widget_draw(tlb,xsize=350,ysize=480,event_pro='luttest_draw',$
/motion_events,graphics_level=2,retain=2)
wstatus = widget_base(tlb,/row)
wX = widget_label(wstatus,value='X: ')
wY = widget_label(wstatus,value='Y: ')
wValue = widget_label(wstatus,value='VALUE: ')
widget_control, tlb, /realize
widget_control, wdraw, get_value=owin
oview = obj_new('IDLgrView',viewplane_rect=[0,-30,350,480])
owin->setproperty, graphics_tree=oview
;圖像的層次
omodel = obj_new('IDLgrModel')
loadct,3,/silent
tvlct,r,g,b,/get
opalette = obj_new('IDLgrPalette',red=r,green=g,blue=b)
oimage = obj_new('IDLgrImage',displayimage,palette=opalette)
omodel->add,oimage
oview->add,omodel
;色標的層次
ocolorbarModel = obj_new('IDLgrModel')
oview->add, ocolorbarModel
dd = max(image)-min(image)
rgb = bytarr(256,16)
rgb[*,*] = indgen(256*16) MOD 256
ocbpalette = obj_new('IDLgrPalette',red=r,green=g,blue=b)
ocbimage = obj_new('IDLgrImage',rgb,dimensions=[dd,16], $
location=[min(image),0],palette=ocbpalette)
oAxis = obj_new('IDLgrAxis',range=[min(image),max(image)], $
/exact,color=[0,0,0],textpos=1,ticklen=16,major=5)
ocolorbarModel->add, ocbimage
ocolorbarModel->add, oAxis
ocolorbarModel->translate, -min(image), 0, 0
ocolorbarModel->scale, 350*0.90/dd, 450/40./16., 1
ocolorbarModel->translate, 15,-30, 0
owin->draw
pstate = ptr_new({opalette:opalette, $
ocbpalette:ocbpalette, $
owin:owin, $
oimage:oimage,$
image:image, $
wstatus:[wX,wY,wValue]})
widget_control, tlb, set_uvalue=pstate
xmanager, 'luttest', tlb, cleanup='luttest_cleanup', /no_block
end