GTX_AI 发表于 2019-7-14 12:10:08

基于MLP的图像多分类分割

基于MLP的图像多分类分割(a multilayer perceptron)* This example program applies image segmentation with an MLP
* classifier to separate oranges and lemons from the background.
*
read_image (Image, 'color/citrus_fruits_01')
get_image_pointer1 (Image, Pointer, Type, Width, Height)
dev_close_window ()
dev_open_window (0, 0, Width, Height, 'white', WindowHandle)
set_display_font (WindowHandle, 12, 'mono', 'true', 'false')
dev_set_draw ('margin')
dev_set_line_width (2)
dev_display (Image)
dev_update_window ('off')
dev_update_pc ('off')
dev_update_var ('off')
dev_set_color ('white')
*
* Create an MLP classifier
create_class_mlp (3, 3, 3, 'softmax', 'normalization', 10, 42, MLPHandle)
*
* Read a training image and add samples for the classes
* 'oranges' and 'background' to the classifier
read_image (Image, 'color/citrus_fruits_01')
dev_display (Image)
* 第1类(OrangeRegion)
gen_rectangle1 (OrangeRegion, 100, 130, 230, 200)
* 第2类(LemonRegion)
gen_empty_region (EmptyRegion)
* 第3类(背景)
gen_rectangle1 (BackgroundRegion, 30, 20, 50, 50)
* 样本Smaples
gen_empty_obj (TrainingRegions1)
concat_obj (TrainingRegions1, OrangeRegion, TrainingRegions1)
concat_obj (TrainingRegions1, EmptyRegion, TrainingRegions1)
concat_obj (TrainingRegions1, BackgroundRegion, TrainingRegions1)
*
add_samples_image_class_mlp (Image, TrainingRegions1, MLPHandle)
stop ()
*
* Read a training image and add samples for the classes
* 'lemons' and 'background' to the classifier
read_image (Image, 'color/citrus_fruits_03')
dev_display (Image)
* 第1类(OrangeRegion)
gen_empty_region (EmptyRegion)
* 第2类(LemonRegion)
gen_rectangle1 (LemonRegion, 180, 130, 230, 240)
* 第3类(背景)
gen_rectangle1 (BackgroundRegion, 400, 20, 430, 50)
* 样本Smaples
gen_empty_obj (TrainingRegions2)
concat_obj (TrainingRegions2, EmptyRegion, TrainingRegions2)
concat_obj (TrainingRegions2, LemonRegion, TrainingRegions2)
concat_obj (TrainingRegions2, BackgroundRegion, TrainingRegions2)
*
add_samples_image_class_mlp (Image, TrainingRegions2, MLPHandle)
stop ()
*
* Train the classifier
train_class_mlp (MLPHandle, 200, 1, 0.01, Error, ErrorLog)
stop ()
dev_set_draw ('fill')
*
* Segment images
for i := 1 to 15 by 1
    read_image (Image, 'color/citrus_fruits_' + i)
    classify_image_class_mlp (Image, ClassRegions, MLPHandle, 0.5)
    select_obj (ClassRegions, ClassOranges, 1)
    select_obj (ClassRegions, ClassLemons, 2)
    select_obj (ClassRegions, ClassBackground, 3)
    dev_set_draw ('fill')
    dev_display (Image)
    dev_set_color ('slate blue')
    dev_display (ClassBackground)
    dev_set_color ('goldenrod')
    dev_display (ClassOranges)
    dev_set_color ('yellow')
    dev_display (ClassLemons)
    disp_message (WindowHandle, 'Classify Image ' + i, 'window', 10, 10, 'black', 'true')
    disp_continue_message (WindowHandle, 'black', 'true')
    stop ()
    *
endfor
dev_clear_window ()
*
* Clear the classifier from memory
clear_class_mlp (MLPHandle)
disp_message (WindowHandle, 'No more lines to execute', 'window', 10, 10, 'black', 'true')





LJN 发表于 2020-8-21 22:29:20

学习啦,谢谢大佬的帖子

大娱乐家 发表于 2020-7-1 10:38:45

学习了,谢谢大神
页: [1]
查看完整版本: 基于MLP的图像多分类分割