*********************************木板的紋理識別程式
**********************************本程式知識量太大,需要多多研究!
***定義變數
feature***tended:=
feature***tended1:=
numberclasses := |classes|
**載入影象檔案
list_files ('f:/7.機器視覺/halcon/halcon學習/紋理識別專題', ['files','follow_links'], imagefiles)
**初始化視窗
dev_close_window ()
read_image (image, imagefiles[0])
get_image_size (image, width, height)
dev_open_window (0, 0, width, height, 'black', windowhandle)
for i := 0 to |imagefiles| - 1 by 1
**1.提取特徵
read_image (image, imagefiles[i])
rgb1_to_gray (image, grayimage)
threshold (grayimage, region, 31, 254)
connection (region, connectedregions)
select_shape (connectedregions, selectedregions, 'area', 'and', 150, 99999)
**灰度共生矩陣,目的是提取紋理特徵後面四個變數
cooc_feature_image (image, image, 6, 90, energy, correlation, homogeneity, contrast)
*sobel邊緣檢測
sobel_amp (image, edgeamplitude, 'sum_abs', 3)
**獲得灰度直方圖,8是量化因子
gray_histo_abs (edgeamplitude, edgeamplitude, 8, absolutehisto)
feature***tended:=[energy, correlation, homogeneity, contrast]
**向特徵陣列中新增乙個特徵absolutehisto
feature***tended:=[feature***tended,absolutehisto]
cooc_feature_image (image, image, 6, 90, energy, correlation, homogeneity, contrast)
*sobel邊緣檢測
sobel_amp (image, edgeamplitude, 'sum_abs', 3)
**獲得灰度直方圖,8是量化因子
gray_histo_abs (edgeamplitude, edgeamplitude, 8, absolutehisto)
feature***tended1 := [feature***tended,energy, correlation, homogeneity, contrast]
**向特徵陣列中新增乙個特徵absolutehisto
feature***tended1 := [feature***tended1,absolutehisto]
**生成特徵向量
featurevector := real(feature***tended1)
**如果是第一張影象,則建立分類器。
if(i == 0)
***2.建立分類器
numberfeatures := |feature***tended1|
create_class_mlp (numberfeatures, 15, 5, 'softmax', 'normalization', 10, 42, mlphandle)
endif
**3.新增樣本到分類器中
add_sample_class_mlp (mlphandle, featurevector, i)
stop()
endfor
**4.訓練分類器
train_class_mlp (mlphandle, 200, 1, 000.01, error, errorlog)
stop()
**寫入分類器
write_class_mlp (mlphandle, 'd:')
**5.分類器識別特徵向量
for i := 0 to |imagefiles|-1 by 1
**提取測試樣本的特徵向量
read_image (image, imagefiles[i])
rgb1_to_gray (image, grayimage)
threshold (grayimage, region, 31, 254)
connection (region, connectedregions)
select_shape (connectedregions, selectedregions, 'area', 'and', 150, 99999)
**灰度共生矩陣,目的是提取紋理特徵後面四個變數
cooc_feature_image (image, image, 6, 90, energy, correlation, homogeneity, contrast)
*sobel邊緣檢測
sobel_amp (image, edgeamplitude, 'sum_abs', 3)
**獲得灰度直方圖,8是量化因子
gray_histo_abs (edgeamplitude, edgeamplitude, 8, absolutehisto)
feature***tended:=[energy, correlation, homogeneity, contrast]
**向特徵向量中新增乙個特徵absolutehisto
feature***tended:=[feature***tended,absolutehisto]
cooc_feature_image (image, image, 6, 90, energy, correlation, homogeneity, contrast)
*sobel邊緣檢測
sobel_amp (image, edgeamplitude, 'sum_abs', 3)
**獲得灰度直方圖,8是量化因子
gray_histo_abs (edgeamplitude, edgeamplitude, 8, absolutehisto)
feature***tended1 := [feature***tended, energy, correlation, homogeneity, contrast]
**向特徵向量中新增乙個特徵absolutehisto
feature***tended1 := [feature***tended1,absolutehisto]
**得到測試樣本的特徵向量
featurevector := real(feature***tended1)
**識別測試樣本的特徵向量
classify_class_mlp (mlphandle, featurevector, 1, classids, confidence)
dev_display (image)
imagefiles1 :='founde classes ' + classes[classids[0]]
disp_message (windowhandle, imagefiles1, 'image', 12, 12, 'black', 'true')
stop()
endfor
disp_message (windowhandle, '所有測試樣本都已經識別完成...', 'window', 12, 12, 'black', 'true')
stop()
disp_message (windowhandle, '所有工作完成...', 'window', 12, 12, 'black', 'true')
這個程式雖然和之前的程式一樣使用了mlp,但是這個程式涉及到了乙個概念:特徵向量。特徵提取和特徵識別始終貫穿了機器視覺的學習和使用,是核心中的核心。
**灰度共生矩陣,目的是提取紋理特徵後面四個變數
cooc_feature_image (image, image, 6, 90, energy, correlation, homogeneity, contrast)
特徵相加,相當於陣列的加法:feature***tended:=[feature***tended,absolutehisto]
matlab練習程式(紋理合成)
關於紋理合成最經典的 應該就數efros的texture synthesis by non parametric sampling這篇 了,引用量近2000。這裡的合成是基於樣例的,就是先有乙個小的紋理影象,然後合成乙個大的。我個人的理解是,先產生乙個大的隨機影象,然後對隨機影象中每個畫素及其鄰域畫...
程式練習2 blob分析的顏色識別例程
blon分析方法進行顏色識別 dev close window read image image,cable2 get image size image,width,height dev open window 0,0,width,height,black windowhandle dev disp...
Day5 構造程式邏輯 練習
1.生成斐波那契數列的前20個數 說明 斐波那契數列 fib 又稱 分割數列,是義大利數學家萊昂納多。斐波那契在 計算之書 中,提出乙個在理想假設條件下兔子成長率的問題而引入的數列,所以也叫兔子 數列特點 前兩個數都是1,從第三個數開始,每個數都是它前面兩個數的和,如1,1,2,3,5,8,13.a...