In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-15 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
OpenCV how to achieve corrosion, many novices are not very clear about this, in order to help you solve this problem, the following editor will explain for you in detail, people with this need can come to learn, I hope you can gain something.
Corrosion and expansion are the most basic morphological operations.
Corrosion and expansion are for white parts (highlighted parts).
Expansion is the "domain expansion" of the highlighted part of the image, and the effect image has a larger highlight area than the original image; corrosion is the erosion of the highlight area in the original image, and the effect image has a smaller highlight area than the original image.
Expansion
Expansion is the operation of finding the local maximum. From the visual point of view of the image, the bright part of the image is enlarged and the dark part is reduced.
# include # includeusing namespace std;using namespace cv;int main () {Mat img = imread ("lol1.jpg"); namedWindow ("original", WINDOW_NORMAL); imshow ("original", img); Mat out; Mat element = getStructuringElement (MORPH_RECT, Size (15,15)); dilate (img, out, element); namedWindow ("inflation operation", WINDOW_NORMAL); imshow ("expansion operation", out) WaitKey (0);}
As you can see, the original bright part of the image is enlarged and the dark part is reduced.
Corrosion
# include # includeusing namespace std;using namespace cv;int main () {Mat img = imread ("lol1.jpg"); namedWindow ("original", WINDOW_NORMAL); imshow ("original", img); Mat out; Mat element = getStructuringElement (MORPH_RECT, Size (15,15)); erode (img, out, element); namedWindow ("corrosion operation", WINDOW_NORMAL); imshow ("corrosion operation", out) WaitKey (0);}
As you can see, the original dark part of the image is enlarged and the bright part is reduced.
Open operation: first corrode and then expand, used to eliminate small objects
Closed operation: first expand and then erode, used to eliminate small black holes
Morphological gradient: the difference between the expansion map and the top view, which is used to retain the edge outline of the object.
Top cap: the difference between the original image and the open operation map, used to separate patches that are brighter than adjacent patches.
Black hat: the difference between the closed operation and the original image, used to separate patches darker than adjacent points.
There is a good function getStructuringElement in opencv. As long as we pass the corresponding processing parameters to this function, we can operate accordingly, which is very convenient to use.
The corresponding action macro definitions are listed below.
# include # includeusing namespace std;using namespace cv;int main () {Mat img = imread ("lol1.jpg"); namedWindow ("original image", WINDOW_NORMAL); imshow ("original image", img); Mat out; Mat element = getStructuringElement (MORPH_RECT, Size (15,15)); morphologyEx (img, out, MORPH_GRADIENT, element); namedWindow ("morphological processing operation", WINDOW_NORMAL) Imshow ("morphological processing operation", out); waitKey (0);}
Morphological gradient processing
This is the effect of the top hat operation.
Is it helpful for you to read the above content? If you want to know more about the relevant knowledge or read more related articles, please follow the industry information channel, thank you for your support.
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.
The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.