当前位置:网站首页>Matlab bottom source code realizes image corrosion and expansion operation (consistent with Halcon effect)
Matlab bottom source code realizes image corrosion and expansion operation (consistent with Halcon effect)
2022-07-18 01:30:00 【Handwriting meets unexpectedly】
Theoretical basis
The operation of mathematical morphology is based on the two basic operations of corrosion and expansion , Several other commonly used mathematical morphological operations are introduced , The most common basic operations are seven , Namely : inflation , corrosion , Open operation , Closed operation , hit , Refinement and coarsening , They are the basis of all morphology , Using these operations and their combinations, we can analyze and process the shape and structure of the image , Common in image preprocessing , Segment the back image , feature extraction , boundary detection , Lay the foundation for image filtering .
Corrosion is one of the two most basic operations in mathematical morphology , The function of corrosion in mathematical morphology is to eliminate the boundary points of objects , Shrink the boundary inward , Objects smaller than structural elements can be removed . In this way, structural elements of different sizes are selected , You can remove objects of different sizes . For example, there is a small channel between the two areas , The two areas can be separated by corrosion . The mathematical expression of corrosion is
S = X ⨂ B = { x , y ∣ B x y ⊆ X } S=X\bigotimes B=\left \{ x,y\mid B_{xy}\subseteq X\right \} S=X⨂B={ x,y∣Bxy⊆X}
Expansion is another basic operation in mathematical morphology besides corrosion . The role of expansion in mathematical morphology is just opposite to that of corrosion , It is an extension of the boundary points of binary objects , Merge all the background points in contact with the object into the object . If the distance between two objects is relatively close , Then the expansion operation may connect two objects , Inflation is very useful for filling holes . The mathematical expression of inflation is :
S = X ⨁ B = { x , y ∣ B x y ∩ X ≠ φ } S=X\bigoplus B=\left \{ x,y\mid B_{xy}\cap X\neq \varphi \right \} S=X⨁B={ x,y∣Bxy∩X=φ}
Image corrosion operation
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Image etching
%Author:Zhu
% Time :2022.6
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
clc;
image = imread("F:\\fabrik.png");
image_matrix=image(:,:,1);
image_matrix=double(image_matrix);
[height,width,channels]=size(image);
image_out = zeros(height,width);
% The size of the input convolution kernel
maskHeight=11;
maskWidth=11;
% Current pixel value
currentPixel=0;
for i=(maskHeight+1)/2:height-(maskHeight+1)/2
for j=(maskWidth+1)/2:width-(maskWidth+1)/2
minValue = 255;
% Update Max
for k=1:maskHeight
for p=1:maskWidth
currentPixel = image_matrix(i-(maskHeight+1)/2+k,j-(maskWidth+1)/2+p);
if(currentPixel<minValue) minValue = currentPixel; end end end % Update the value of the convolution kernel Center image_out(i,j)=minValue; end end % Image edge pixel modification for i=1:height for j=1:width if(i>(maskHeight+1)/2 && i<height-(maskHeight+1)/2 && j>(maskWidth+1)/2 && j<width-(maskWidth+1)/2)
image_out(i,j)= image_out(i,j);
else
image_out(i,j)= image_matrix(i,j);
end
end
end
% Display images
image_out = uint8(image_out);
subplot(1,2,1);
imshow(image);
subplot(1,2,2);
imshow(image_out);
Image expansion operation
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Image expansion
%Author:Zhu
% Time :2022.6
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
clc;
image = imread("F:\\fabrik.png");
image_matrix=image(:,:,1);
image_matrix=double(image_matrix);
[height,width,channels]=size(image);
image_out = zeros(height,width);
% The size of the input convolution kernel
maskHeight=11;
maskWidth=11;
% Current pixel value
currentPixel=0;
for i=(maskHeight+1)/2:height-(maskHeight+1)/2
for j=(maskWidth+1)/2:width-(maskWidth+1)/2
maxValue = 0;
% Update Max
for k=1:maskHeight
for p=1:maskWidth
currentPixel = image_matrix(i-(maskHeight+1)/2+k,j-(maskWidth+1)/2+p);
if(currentPixel>maxValue)
maxValue = currentPixel;
end
end
end
% Update the value of the convolution kernel Center
image_out(i,j)=maxValue;
end
end
% Image edge pixel modification
for i=1:height
for j=1:width
if(i>(maskHeight+1)/2 && i<height-(maskHeight+1)/2 && j>(maskWidth+1)/2 && j<width-(maskWidth+1)/2)
image_out(i,j)= image_out(i,j);
else
image_out(i,j)= image_matrix(i,j);
end
end
end
% Display images
image_out = uint8(image_out);
subplot(1,2,1);
imshow(image);
subplot(1,2,2);
imshow(image_out);
Halcon operator
* Corrosion image
gray_erosion_rect (Image, ImageMin, 11, 11)
* Dilated image
gray_dilation_rect (Image, ImageMax, 11, 11)
Halcon Compare with the image effect of the source code
Halcon Corrosion effect 
Matlab Source code corrosion effect 
Halcon Expansion effect 
Matlab Source expansion effect 
边栏推荐
猜你喜欢

Configure scan packages based on annotations

服务网格中 sidecar 流量治理与多协议嗅探

Technical implementation details of SAP e-commerce cloud Spartacus UI sitecontextrouteshandler

JMeter 21天打卡 day02

数据湖(十九):SQL API 读取Kafka数据实时写入Iceberg表

今日睡眠质量记录80分

小程序webview页面转发后,打开页面空白

PAT. A1018 Public Bike Management
QT | VS2017 + Qt5.14.2环境搭建

Room:又要写业务代码了?看看我吧,给你飞一般的感觉!
随机推荐
A top-notch book and an ingenious translation! Machine learning and asset pricing is heavily listed
Connecting with enterprise wechat, customer relationship management can also be very simple!
Incremental abstraction in distributed probabilistic slam graph
029.文件的复制和移动
Pytoch (II) -- main components of pytorch
Cloud native: docker practical experience (III) deploy MySQL 8 master-slave replication on docker
大家有没有遇到过flink-oracle-cdc 获取最新的日志 卡住的情况?怎么解决?
Mobile browser product analysis
Guys, the capture delay of flick CDC Oracle is particularly high. Is there any optimization method
基于机器学习的笑脸检测
How much do you know about programming paradigms -- clarify the mainstream programming paradigms
善良的人都晚熟
Q3 qmainwindow status bar riveted parts core parts
kali安装Nessus
PAT. A1018 Public Bike Management
C language Beijing Winter Olympics competition ranking system
From March to June, after summary, more than 200 pages of true question notes and detailed explanations (including core test sites and 6 major factories)
职员信息管理系统--程序设计
Play with Nacos! Replace Eureka as configuration center and Registration Center
【LaTex 中英文样式&加粗】自由选择中英文字体样式,中英文字体粗黑程度设置