Hello Mat

 找回密码
 立即注册
查看: 12147|回复: 2

基于MLP的图像多分类分割

[复制链接]

84

主题

115

帖子

731

金钱

管理员

Rank: 9Rank: 9Rank: 9

积分
1467
发表于 2019-7-14 12:10:08 | 显示全部楼层 |阅读模式
基于MLP的图像多分类分割(a multilayer perceptron)
  1. * This example program applies image segmentation with an MLP
  2. * classifier to separate oranges and lemons from the background.
  3. *
  4. read_image (Image, 'color/citrus_fruits_01')
  5. get_image_pointer1 (Image, Pointer, Type, Width, Height)
  6. dev_close_window ()
  7. dev_open_window (0, 0, Width, Height, 'white', WindowHandle)
  8. set_display_font (WindowHandle, 12, 'mono', 'true', 'false')
  9. dev_set_draw ('margin')
  10. dev_set_line_width (2)
  11. dev_display (Image)
  12. dev_update_window ('off')
  13. dev_update_pc ('off')
  14. dev_update_var ('off')
  15. dev_set_color ('white')
  16. *
  17. * Create an MLP classifier
  18. create_class_mlp (3, 3, 3, 'softmax', 'normalization', 10, 42, MLPHandle)
  19. *
  20. * Read a training image and add samples for the classes
  21. * 'oranges' and 'background' to the classifier
  22. read_image (Image, 'color/citrus_fruits_01')
  23. dev_display (Image)
  24. * 第1类(OrangeRegion)
  25. gen_rectangle1 (OrangeRegion, 100, 130, 230, 200)
  26. * 第2类(LemonRegion)
  27. gen_empty_region (EmptyRegion)
  28. * 第3类(背景)
  29. gen_rectangle1 (BackgroundRegion, 30, 20, 50, 50)
  30. * 样本Smaples
  31. gen_empty_obj (TrainingRegions1)
  32. concat_obj (TrainingRegions1, OrangeRegion, TrainingRegions1)
  33. concat_obj (TrainingRegions1, EmptyRegion, TrainingRegions1)
  34. concat_obj (TrainingRegions1, BackgroundRegion, TrainingRegions1)
  35. *
  36. add_samples_image_class_mlp (Image, TrainingRegions1, MLPHandle)
  37. stop ()
  38. *
  39. * Read a training image and add samples for the classes
  40. * 'lemons' and 'background' to the classifier
  41. read_image (Image, 'color/citrus_fruits_03')
  42. dev_display (Image)
  43. * 第1类(OrangeRegion)
  44. gen_empty_region (EmptyRegion)
  45. * 第2类(LemonRegion)
  46. gen_rectangle1 (LemonRegion, 180, 130, 230, 240)
  47. * 第3类(背景)
  48. gen_rectangle1 (BackgroundRegion, 400, 20, 430, 50)
  49. * 样本Smaples
  50. gen_empty_obj (TrainingRegions2)
  51. concat_obj (TrainingRegions2, EmptyRegion, TrainingRegions2)
  52. concat_obj (TrainingRegions2, LemonRegion, TrainingRegions2)
  53. concat_obj (TrainingRegions2, BackgroundRegion, TrainingRegions2)
  54. *
  55. add_samples_image_class_mlp (Image, TrainingRegions2, MLPHandle)
  56. stop ()
  57. *
  58. * Train the classifier
  59. train_class_mlp (MLPHandle, 200, 1, 0.01, Error, ErrorLog)
  60. stop ()
  61. dev_set_draw ('fill')
  62. *
  63. * Segment images
  64. for i := 1 to 15 by 1
  65.     read_image (Image, 'color/citrus_fruits_' + i)
  66.     classify_image_class_mlp (Image, ClassRegions, MLPHandle, 0.5)
  67.     select_obj (ClassRegions, ClassOranges, 1)
  68.     select_obj (ClassRegions, ClassLemons, 2)
  69.     select_obj (ClassRegions, ClassBackground, 3)
  70.     dev_set_draw ('fill')
  71.     dev_display (Image)
  72.     dev_set_color ('slate blue')
  73.     dev_display (ClassBackground)
  74.     dev_set_color ('goldenrod')
  75.     dev_display (ClassOranges)
  76.     dev_set_color ('yellow')
  77.     dev_display (ClassLemons)
  78.     disp_message (WindowHandle, 'Classify Image ' + i, 'window', 10, 10, 'black', 'true')
  79.     disp_continue_message (WindowHandle, 'black', 'true')
  80.     stop ()
  81.     *
  82. endfor
  83. dev_clear_window ()
  84. *
  85. * Clear the classifier from memory
  86. clear_class_mlp (MLPHandle)
  87. disp_message (WindowHandle, 'No more lines to execute', 'window', 10, 10, 'black', 'true')
复制代码





本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?立即注册

x
回复

使用道具 举报

0

主题

16

帖子

1

金钱

新手上路

Rank: 1

积分
8
发表于 2020-8-21 22:29:20 | 显示全部楼层
学习啦,谢谢大佬的帖子
回复 支持 1 反对 0

使用道具 举报

0

主题

14

帖子

1

金钱

新手上路

Rank: 1

积分
12
发表于 2020-7-1 10:38:45 | 显示全部楼层
学习了,谢谢大神
回复 支持 1 反对 0

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Python|Opencv|MATLAB|Halcom.cn ( 蜀ICP备16027072号 )

GMT+8, 2024-11-22 16:54 , Processed in 0.209803 second(s), 24 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表