Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Example Analysis of Image Morphology Operation Technology in Python

2025-04-03 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly shows you the "Python image morphology operation technology example analysis", the content is easy to understand, clear, hope to help you solve doubts, the following let Xiaobian lead you to study and learn "Python image morphology operation technology example analysis" this article.

1 image morphological operation

In the detailed description of image filtering effects in Python OpenCV image processing, we classify image filtering as follows:

Neighborhood filtering

Linear filter

Nonlinear filtering

Frequency domain filtering

Low-pass filtering

High pass filter

In nonlinear filtering, only median filtering was introduced before. in fact, there is a kind of very commonly used nonlinear filtering method, called Image Morphology Operation (Morphological operations).

Image morphology operation is a kind of nonlinear filtering technology based on image shape operation. Its basic idea is to use some special structural elements to measure or extract the corresponding shapes and features in the image for further image analysis and processing. Here the structural element is equivalent to the template we are involved in filtering-a matrix of given pixels, which can be arbitrarily shaped, but is generally square.

Next, let's analyze several classical image morphology algorithms, and then program and test.

2 corrosion

Corrosion is to use the local gray minimum value instead of the target pixel value to realize the corrosion of the highlighted area.

For example, there is such an image and a structural element where the blue square of the structural element represents the template origin.

Let's start traversing this image. When we get to the position below, the minimum gray value in the template is the pixel of the gray square, so the pixel at the blue square in the origin of the template is gray (originally white, corroded).

After going through this image in this way, you get

3 expansion

Expansion is to use the local gray maximum value instead of the target pixel value to achieve the expansion of the highlighted area.

Similar to etching, traverse this image, and when you get to the position below, the maximum gray value in the template is the pixel of the white square, so the pixel at the blue square in the origin of the template is white (originally gray, inflated).

After traversing the image in this way, the final result of the expansion is

Feel the effect of corrosion and expansion in the last physical picture.

4 open operation and closed operation

If you understand the image corrosion and expansion, then the opening and closing operation is very easy.

Open operation (Opening): corrode and then expand

Closed operation (Closing): expand first and then erode

The open operation can effectively remove outliers, burrs and bridges, while the closed operation can fill the holes and close the gaps.

The image above assumes that the gray area is highlighted.

5 Top cap operation and bottom cap operation

The top cap operation and bottom cap operation are used to characterize the difference between the opening and closing operation and the original image, similar to the gradient difference of edge detection.

Image capping operation: characterizes the difference between the original image and the image obtained by open operation

Image bottom cap operation: characterizes the difference between the original image and the image obtained by closed operation

6 Demons and angels

First look at the original picture, a pair of lovely cats

To perform the corrosion operation, first create a structural element

Int eSize = 3; / / structural element size int s = eSize * 2 + 1terMat structureElement = getStructuringElement (MORPH_RECT, Size (s, s), Point (- 1,-1))

Then use the structural element to traverse the original image. OpenCV has encapsulated API, which can be called directly.

Erode (src, dst, structureElement); imshow ("after etching operation:", dst)

Get the corroded image as follows, the eyes are hollow, a little bit of horror inside the flavor, these are still the original two cats?

The expansion operation is similar to etching, and there is also API encapsulated by OpenCV.

Dilate (srcImg, dstImg, structureElement, Point (- 1,-1), 1); imshow ("after expansion operation:", dstImg)

The inflated kitten looks much more relaxed and feels sublimated.

In the future, if you want to have a photo to create the contrast between light and shadow, good and evil, angels and demons, you can consider using image erosion and expansion operations.

The above is all the contents of the article "example Analysis of Image Morphology Operation Technology in Python". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report