当前位置:网站首页>[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 :
 picture
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 .
 picture
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 .
 picture
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 :
 picture
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:
 picture
The process of gray morphology corrosion is as follows :
 picture
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 .
 picture
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 .
 picture
 picture
Here is also a description of the origin of the first element value of the output image .
 picture
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 function  hsvimg = rgb2hsv(colorimg); h = hsvimg(:,:,1); mask1 = mask(:); index = mask1>0;[counts,x] = imhist(h(index));                      % Draw histogram Hue = 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 .

原网站

版权声明
本文为[Matlab scientific research studio]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/160/202206090950326319.html