当前位置:网站首页>[fruit recognition] fruit recognition based on morphology, including Matlab source code
[fruit recognition] fruit recognition based on morphology, including Matlab source code
2022-06-09 10:34:00 【Matlab scientific research studio】
1 brief introduction
Mathematical morphology operations can be divided into binary morphology and gray morphology , Gray morphology is extended from binary morphology . Mathematical morphology has 2 A basic operation , Corrosion and expansion , Corrosion and expansion combine to form open operation and closed operation .
Open operation is first corrosion and then expansion , Closed operation is to expand first and then corrode .
1 Binary morphology
Roughly speaking , Corrosion can make the target area “ smaller ”, Its essence causes the boundary of the image to shrink , Can be used to eliminate small and meaningless targets . The formula is expressed as :
The expression is represented by the structure B corrosion A, It should be noted that B You need to define an origin ,【 and B The moving process of the convolution kernel is consistent with the moving process of the convolution kernel , It is the same as calculating after the convolution kernel overlaps with the image 】 When B Translate the origin of to the image A Pixel of (x,y) when , If B stay (x,y) It's about , Completely contained in the image A Overlapping areas ,( That is to say B In Chinese, it means 1 Corresponding to the element position of A All image values are also 1) The pixel corresponding to the image will be output (x,y) The assignment is 1, Otherwise, it is assigned as 0.
Let's look at a demo .
B In order A Move up ( Just as the convolution kernel moves on the image , And then in B Perform morphological operations on the coverage of ), When it covers A The area of this is [1,1;1,1] perhaps [1,0;1,1] when ,( That is to say B in ‘1’ Is a subset of the coverage area ) The position corresponding to the output image will be 1.
2 inflation
Roughly speaking , The expansion will make the target area “ Bigger ”, Merge the background points in contact with the target area into the target , Expand the target boundary to the outside . It can be used to fill some holes in the target area and eliminate the small particle noise contained in the target area .
The expression is represented by the structure B inflation A, The structural elements B The origin of the image is translated to the image pixel (x,y) Location . If B In image pixels (x,y) Place and A The intersection of is not empty ( That is to say B In Chinese, it means 1 The position of the element corresponds to A At least one of the image values of is 1), The pixel corresponding to the output image (x,y) The assignment is 1, Otherwise, it is assigned as 0.
The illustration shows :
3 Summary
That is, whether corrosion or expansion , Are structural elements B Like convolution , Pan on the image , Structural elements B The origin in is equivalent to the kernel center of the convolution kernel , The result is also stored on the element corresponding to the core center . It's just that corrosion is B Is completely contained in the area it covers , When expanding B It can intersect with the area it covers .
4 Grayscale morphology
Before we talk about gray value morphology , Let's make an agreement , About structural elements B Covered image A The area marked as P( take Part The meaning of ).
5 Gray morphological corrosion
Then corrosion in gray morphology is an operation similar to convolution , use P Subtract structural elements B Form a small rectangle , Take the minimum value and assign it to the position of the corresponding origin .
Let's look at an example , Deepen the understanding of gray morphology .
Suppose we have the following image A And structural elements B:
The process of gray morphology corrosion is as follows :
We show the output result of the first element of the output image , That is, the origin corresponds to 4 The location of . The values of other elements of the output image are obtained in this way . We'll see ,B The first area covered is the subtracted matrix , Then find... In its difference matrix min( minimum value ) As the value of the position corresponding to the origin .
The expansion of gray morphology
According to the above description of corrosion , We make the same description of expansion , Dilation in gray morphology is an operation similar to convolution , use P add B, Then assign the maximum value in this area to the structural element B The position corresponding to the origin of .

Here is also a description of the origin of the first element value of the output image .
Finding the maximum sum of the above matrices is 6, So the 6 Assigned to the position corresponding to the origin of the structural element .
2 Part of the code
function tfeat = get_features(colorimg, mask)% Feature extraction functionhsvimg = rgb2hsv(colorimg);h = hsvimg(:,:,1);mask1 = mask(:);index = mask1>0;[counts,x] = imhist(h(index)); % Draw histogramHue = find(counts == max(counts));% ShapeValue = regionprops(mask, 'majoraxislength','minoraxislength');% Shape = ShapeValue.MajorAxisLength/ShapeValue.MinorAxisLength;ShapeValue = regionprops(mask, 'eccentricity');Shape = ShapeValue.Eccentricity;tfeat = [Hue, Shape ];%tfeat = [feat1 feat2 f.Orientation f2.Eccentricity f1.Extent];
3 Simulation results

4 reference
[1] Yang Pei . be based on matlab GUI Fruit recognition system [J]. Electronic production , 2021(12):2.
About bloggers : Good at intelligent optimization algorithms 、 Neural networks predict 、 signal processing 、 Cellular automata 、 The image processing 、 Path planning 、 UAV and other fields Matlab Simulation , relevant matlab Code problems can be exchanged by private letter .
Some theories cite network literature , If there is infringement, contact the blogger to delete .
边栏推荐
- 如何实现合规的远程办公?
- C语言与Lua的交互(实践二)
- You need to think about the following questions about the online help center
- [PHP] brief description and relevant examples of the special class trail for code reuse
- Security monitoring video easycvr video access interface adds the close button of a single video
- 349. intersection of two arrays
- TensorFlow新文档发布:新增CLP、DTensor...最先进的模型已就绪!
- Interaction between C language and Lua (practice 2)
- 978. longest turbulent subarray
- 从数据库查询权限信息
猜你喜欢

Test development engineers who don't work overtime are not good programmers? It may not be a stupid bird, but it always flies first

UnsupportedOperationException异常解决

关于在线帮助中心你需要思考以下几个问题
![Construction of vocabulary and sampling -- [torch learning notes]](/img/51/e1b67a0675f4e3db9abe9207c0b968.png)
Construction of vocabulary and sampling -- [torch learning notes]
![[model deployment and business implementation] model transformation of AI framework deployment scheme](/img/ea/8ca6bc6ae16ba1f90f6a5a38be184d.jpg)
[model deployment and business implementation] model transformation of AI framework deployment scheme

Mysql数据库头歌实训任务存储过程如何通关?

刷脸认证如何实现人脸又快又准完成校验?

dict中的部分指令与set中的差和交集与增减元素

AI 考生挑战高考作文获 48 分;IBM 宣布退出俄罗斯市场,已暂停在俄所有业务;OpenCV 4.6 发布|极客头条...

InfoQ 极客传媒 15 周年庆征文| 迁移 Eureka 到 Nacos 之双注册双订阅模式
随机推荐
Key configuration points of video fusion cloud service easycvr platform deployed in ECS
Sword finger offer 18 Delete the node of the linked list
損失 3 億美元後,IBM 宣布退出俄羅斯!
Other permission verification methods
Test development engineers who don't work overtime are not good programmers? It may not be a stupid bird, but it always flies first
1331. array sequence number conversion - quick sort plus binary search
【LeetCode】【牛客】二叉树刷题
How to pass the MySQL database header song training task stored procedure?
The more you look at the screen, the better it looks
31. next spread
Security monitoring video easycvr video access interface adds the close button of a single video
Terrain learning summary (6) -- terrain practice based on Alibaba cloud platform
Iscc2022 challenge arena Misc
Terraform 学习总结(6)—— 基于阿里云平台上的 Terraform 实战
Sequence model - 【 torch learning notes 】
978. longest turbulent subarray
苹果胜诉 美法官驳回iPhone和iPad安全缺陷集体诉讼
长大后的我们为何贪恋年少?
N-grams language model -- [torch learning notes]
go strconv包