|
MLP下的图像分类:- * The object of this example is to classify different kinds of wood according to their surface texture.
- dev_update_off()
- dev_set_draw('margin')
- HalconImages:='C:\\Users\\Public\\Documents\\MVTec\\HALCON-12.0\\examples\\images'
- ImagePath := '/wood/'
- try
- read_image (Image, HalconImages + ImagePath + 'apple/apple_01')
- ReadPath := HalconImages + ImagePath
- catch (Exception)
- endtry
- read_image (Image, ImagePath + 'apple/apple_01')
- get_image_pointer1 (Image, Pointer, Type, Width, Height)
- dev_close_window ()
- dev_open_window_fit_image (Image, 0, 0, Width, Height, WindowID)
- set_display_font (WindowID, 22, 'mono', 'true', 'false')
- dev_display (Image)
- dev_update_off ()
- * Now the different wood classes are specified.
- Classes := ['apple','beech','cherry','maple','oak','walnut']
- gen_features (Image, FeatureVector)
- NumFeatures := |FeatureVector|
- NumClasses := |Classes|
- NumHidden := 15
- create_class_mlp (NumFeatures, NumHidden, NumClasses, 'softmax', 'normalization', 10, 42, MLPHandle)
- for CorrectClassID := 0 to NumClasses - 1 by 1
- list_files (ReadPath + Classes[CorrectClassID], 'files', Files)
- for k := 0 to |Files| - 1 by 2
- read_image (Image, Files[k])
- dev_display (Image)
- gen_features (Image, FeatureVector)
- add_sample_class_mlp (MLPHandle, FeatureVector, CorrectClassID)
- endfor
- endfor
- train_class_mlp (MLPHandle, 200, 1, 0.0001, Error, ErrorLog)
- write_class_mlp (MLPHandle, 'classify_wood.gmc')
- disp_message (WindowID, 'Training of wood textures completed\nPress \'Run\' to continue', 'window', -1, -1, 'black', 'true')
- stop ()
- *
- read_image (Image, ImagePath + 'apple/apple_02')
- gen_features (Image, FeatureVector)
- classify_class_mlp (MLPHandle, FeatureVector, 1, FoundClassIDs, Confidence)
- *
- clear_class_mlp (MLPHandle)
复制代码
特征选取函数如下:
(1)分类器特征提取 http://halcom.cn/forum.php?mod=viewthread&tid=33506&extra=page%3D1
|
|