使用halcon處理射線圖像,對高能區域和低能區域分割處理感興趣區域,篩選區域下的灰度值區間范圍。
圖像灰度值為16位深度圖。
* 讀取灰度圖像
read_image (Image, '/123.tif')** 獲取圖像尺寸
get_image_size (Image, Width, Height)* 分割圖像為左右兩部分(高能量和低能量區域)
gen_rectangle1 (LeftROI, 0, 0, Height-1, Width/2-1)
gen_rectangle1 (RightROI, 0, Width/2, Height-1, Width-1)* 提取左右區域圖像
reduce_domain (Image, LeftROI, LeftImage)
reduce_domain (Image, RightROI, RightImage)* 預處理 - 增強對比度
emphasize (LeftImage, LeftEnhanced, 7, 7, 1.0)
emphasize (RightImage, RightEnhanced, 7, 7, 1.0)* 中值濾波去噪
median_image (LeftEnhanced, LeftFiltered, 'circle', 2, 'mirrored')
median_image (RightEnhanced, RightFiltered, 'circle', 2, 'mirrored')* 閾值分割提取礦石區域
threshold (LeftFiltered, LeftRegions, 50, 43055)
threshold (RightFiltered, RightRegions, 50, 43055)* 形態學處理去除小噪點
connection (LeftRegions, LeftConnected)
connection (RightRegions, RightConnected)
select_shape (LeftConnected, LeftOres, 'area', 'and', 500, 9999999)
select_shape (RightConnected, RightOres, 'area', 'and', 500, 9999999)* 計算每個礦石區域的灰度特征
* 高能量礦石區域分析
count_obj (LeftOres, NumLeftOres)
for i := 1 to NumLeftOres by 1select_obj (LeftOres, SingleOre1, i)* 計算區域的平均灰度值intensity (SingleOre1, LeftFiltered, MeanIntensity1, Deviation1)min_max_gray (SingleOre1, LeftFiltered, 0, Min1, Max1, Range1)* 根據灰度值分類if (MeanIntensity1 > 180)Class := 'High-grade ore'Color := 'blue'elseif (MeanIntensity1 > 120)Class := 'Medium-grade ore'Color := 'yellow'elseClass := 'Low-grade ore'Color := 'red'endif* 獲取區域邊界框smallest_rectangle1 (SingleOre1, Row1, Col1, Row2, Col2)gen_rectangle1 (Rectangle1, Row1, Col1, Row2, Col2)* 顯示結果dev_set_color (Color)dev_display (SingleOre1)endfor* 低能量礦石區域分析
count_obj (RightOres, NumRightOres)
for j := 1 to NumRightOres by 1select_obj (RightOres, SingleOre2, j)* 計算區域的平均灰度值intensity (SingleOre2, RightFiltered, MeanIntensity2, Deviation2)min_max_gray (SingleOre2, RightFiltered, 0, Min2, Max2, Range2)* 根據灰度值分類(使用不同的閾值)if (MeanIntensity2 > 150)Class := 'High-grade ore'Color := 'green'elseif (MeanIntensity2 > 90)Class := 'Medium-grade ore'Color := 'yellow'elseClass := 'Low-grade ore'Color := 'red'endif* 獲取區域邊界框smallest_rectangle1 (SingleOre2, Row1, Col1, Row2, Col2)gen_rectangle1 (Rectangle2, Row1, Col1, Row2, Col2)* 顯示結果dev_set_color (Color)dev_display (SingleOre2)endforstop()