Halcon學習:圖像灰度變化


 灰度線性變換:圖像相加 

 1 *關閉過程更新,不更新變量窗口,讓程序更快
 2 dev_update_off ()
 3 *讀取圖片
 4 dev_open_file_dialog ('read_image', 'default', 'default', Selection)
 5 read_image (Image, Selection)
 6 
 7 *圖像轉為灰度圖
 8 rgb1_to_gray (Image, GrayImage)
 9 
10 *圖像相加,c(a+b)+d  0.8x(GrayImage+GrayImage)+100  
11 add_image (GrayImage, GrayImage, ImageResult, 0.8, 100)
12 
13 *獲得圖像區域以及坐標
14 get_domain (GrayImage, Domain)
15 get_region_points (Domain, Rows, Columns)
16 
17 *獲得圖像每個坐標的灰度
18 get_grayval (GrayImage, Rows, Columns, Grayval)
19 
20 *循環改變灰度值,灰度值高於30的,賦值為255,即白色
21 for i := 0 to |Grayval|-1 by 1
22     if (Grayval[i]>30)
23         Grayval[i]:=255
24     endif
25 endfor
26 
27 *灰度賦值
28 set_grayval (ImageResult, Rows, Columns, Grayval)

效果圖:

 

 

灰度非線性變換:常用有對數函數、指數函數

對數函數一般是提高低范圍的像素,壓縮高范圍的像素

指數函數一般是提高高范圍的像素,壓縮低范圍像素

1 *圖像取對數
2 log_image (GrayImage, LogImage, 'e')
3 * set_grayval (LogImage, Rows, Columns, Grayval)
4 *圖像取指數
5 exp_image (LogImage, ExpImage, 'e')

效果圖:紅框內邊緣對比度提高了

  

 

 

 

 

灰度直方圖變換:對圖像中的像素灰度做映射變換,但是這種映射是基於灰度直方圖的

1 *圖像均衡化
2 equ_histo_image (GrayImage, ImageEquHisto)

效果圖:使得圖像分辨更清晰

 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM