当前位置:网站首页>Digital image processing -- popular understanding of corrosion and expansion
Digital image processing -- popular understanding of corrosion and expansion
2022-07-03 15:19:00 【alw_ one hundred and twenty-three】
I have planned to present this series of blog posts in the form of animated interesting popular science , If you're interested Click here .
0. What's the use of corrosion and expansion ?
Corrosion and expansion are two basic operations in digital morphology , Generally used for binary images ( Of course RGB Pictures can also be used ). The effect of corrosion is to make the dark area larger , The role of expansion is to make the bright area larger ( It can be imagined that Cheng Balala's energy and gunara's dark god are fighting in the gods .. If Balala energy wins, it will expand , Gunara, the dark god, wins, which is corrosion ...)
The most typical application scenario is after your binarization , When your goal and background are not very clean, you can try two operations , Sometimes the effect is surprisingly good . For example, if I want to binarize a diagram of verification code, the result will be more accurate , You can try corrosion and expansion ( The second picture is expansion + Effect after corrosion , It can be seen that the interference points and lines have been removed ).

1. corrosion
Corrosive raw materials are : Original picture 、 nucleus ( Corroded soul )、 Result chart ( The goods are copied from the original drawing ). Here are chestnuts to illustrate the workflow of corrosion .
Suppose now we want to corrode such a single channel diagram ( By IG Children's shoes that have cared for their eyesight can certainly see that what is painted in the picture is 1)
Then we need to make a copy of the original drawing as the result drawing , Now the result graph is the same as the original one .
With the original diagram and the result diagram , We need souls ( Design core ). The nucleus is generally square ,X Shaped , Rhombic , Etc., etc. ( Of course, you can do it yourself DIY, For example, I just DIY A cross shaped ). And the effect of corrosion has a lot to do with the core you designed , What kind of nucleus is suitable for what kind of map depends on your own brain hole and experience . Anyway, I like to try more cores , See which one works well . I'm here DIY Its core is 3 That's ok 3 Columns of the matrix , Look like the following :
Now with the soul , We are about to inject soul . How to inject ? It's simple , Throw our core into the upper left corner of the original and result graphs (PS: I don't do it here padding, Because I am lazy ).

After throwing it , We are going to use the values in the core . We have 0 and 1( Nonzero value ),0 It means I don't care,1( Nonzero value ) On behalf of your success, it attracted my attention . When our core is covered on the original picture, it shows that I only care about my core 1( Nonzero value ) The corresponding pixel on the original image , That is, I only care about the cross in the middle of my red frame 5 individual 255, Other 4 I don't care about pixels . After locking the target , We just have to look at me 5 Are there any pixels 0, If so, we will change the pixel value in the center of the red box in the result image to 0, Or I'll do nothing . Let's have a look ,5 individual 255, did not 0 So do nothing .
It took us a long time to find that we didn't do anything , You're not angry , So pinch , Let's move the red box on the original image and the result image one step to the right ( In fact, it's not a matter of being angry , Is corrosion and expansion is to traverse the entire graph , So we have to iterate ). So after moving a step, it became maozi .

New place , A new start , So we need to continue the routine just now , Look at the cross in the red box of the original picture 5 Are there pixels 0, Found to have 0!. So the pixel value of the center point of the red box in our result graph is changed to 0 了 .
Then continue the routine just now , Move right , See if there is any place you care about 0, If you can't move on the right side, move down . Until the whole red frame is soaked with rain and dew , The whole corrosion algorithm is finished .
After we finish, we will find that the result picture turns into maozi .
Um. , Normal , Because corrosion is to make the black area larger , therefore 1 Getting fat , And the original 1 There is a partition in the middle , After corrosion, the partition is also connected .
2. inflation
In fact, after understanding corrosion , Understanding inflation is simply a batch . Corrosion is called corrosion because it only looks at whether there is in the area of interest 0, Yes 0 I will assign the result to 0, So the black area can become larger . Expansion is just the opposite of corrosion , It only depends on whether there is 255, Yes 255 I will assign the result to 255, So the bright area can become larger .
If the original drawing (0 It can be regarded as noise ) It's purple sauce 
The result picture was also dark purple at the beginning 
Suppose the inflated soul is also the core of the cross 
Then the first step of expansion is to put a red box on the original diagram and the result diagram 

Then it depends on whether the cross area is 255, When I find it, I will change the pixel of the corresponding position on the result graph to 255( Of course , At this time, the corresponding pixels of the result image are 255, So it's equivalent to doing nothing ). Move the red box on the original image and the result image to the right 

At this time, it was found that there was 255, When I find it, I will change the pixel of the corresponding position on the result graph to 255( Of course , At this time, the corresponding pixels of the result image are 255, So it's equivalent to doing nothing ). Move the red box on the original image and the result image to the right .

At this time, there are 255, So change the pixels corresponding to the result image to 255, After modification, the result picture is maozi .
Then continue to move , Move to the lower right corner , The whole algorithm stops . After inflation , The result is dark purple .
You can see that , The original 0 I regard it as noise , After expansion, all the noise is erased .
3. Conclusion
It can be seen that the two algorithm processes of corrosion and expansion are very simple , Nothing more than friction .. Devil like steps .. Rub on the image .. friction .. Although the algorithm is simple , But if the nuclear design is good , Use the right words , It's enough to get a satisfactory effect .
边栏推荐
- Global and Chinese markets for flexible chips 2022-2028: Research Report on technology, participants, trends, market size and share
- Leetcode sword offer find the number I (nine) in the sorted array
- What is one hot encoding? In pytoch, there are two ways to turn label into one hot coding
- Kubernetes - yaml file interpretation
- Global and Chinese market of Bus HVAC systems 2022-2028: Research Report on technology, participants, trends, market size and share
- Global and Chinese market of lighting control components 2022-2028: Research Report on technology, participants, trends, market size and share
- 什么是one-hot encoding?Pytorch中,将label变成one hot编码的两种方式
- 秒杀系统2-Redis解决分布式Session问题
- XWiki安装使用技巧
- Puppet自动化运维排错案例
猜你喜欢

Troubleshooting method of CPU surge

百度智能云助力石嘴山市升级“互联网+养老服务”智慧康养新模式
![MySQL reports an error: [error] mysqld: file '/ mysql-bin. 010228‘ not found (Errcode: 2 “No such file or directory“)](/img/cd/2e4f5884d034ff704809f476bda288.png)
MySQL reports an error: [error] mysqld: file '/ mysql-bin. 010228‘ not found (Errcode: 2 “No such file or directory“)

Basic SQL tutorial

Matplotlib drawing label cannot display Chinese problems

Kubernetes will show you from beginning to end

视觉上位系统设计开发(halcon-winform)-1.流程节点设计

详解指针进阶2
![[pytorch learning notes] datasets and dataloaders](/img/c0/9cd539caff34db3cccc44505bbe3c5.png)
[pytorch learning notes] datasets and dataloaders

Functional modules and application scenarios covered by the productization of user portraits
随机推荐
Qt常用语句备忘
Summary of JVM knowledge points
What is machine reading comprehension? What are the applications? Finally someone made it clear
【可能是全中文网最全】pushgateway入门笔记
[attention mechanism] [first vit] Detr, end to end object detection with transformers the main components of the network are CNN and transformer
Influxdb2 sources add data sources
【Transformer】入门篇-哈佛Harvard NLP的原作者在2018年初以逐行实现的形式呈现了论文The Annotated Transformer
SQL server installation location cannot be changed
Mmdetection learning rate and batch_ Size relationship
基础SQL教程
The method of parameter estimation of user-defined function in MATLAB
Redis cache penetration, cache breakdown, cache avalanche solution
Popular understanding of linear regression (I)
qt使用QZxing生成二维码
Use of Tex editor
Global and Chinese market of transfer case 2022-2028: Research Report on technology, participants, trends, market size and share
The first character of leetcode sword offer that only appears once (12)
【日常训练】395. 至少有 K 个重复字符的最长子串
[set theory] inclusion exclusion principle (complex example)
Kubernetes - YAML文件解读