当前位置:网站首页>Implementation of image binary morphological filtering based on FPGA -- Corrosion swelling
Implementation of image binary morphological filtering based on FPGA -- Corrosion swelling
2022-06-26 02:06:00 【Fighting_ XH】
One 、 Binary image
Binary image (Binary Image) It means that each pixel on the image has only two possible values or gray level states . in short , There are only two gray levels in the image 0 or 255( Black or white )
.
Two 、 morphology
morphology , Mathematical morphology (Mathematical Morphology), It is one of the most widely used technologies in image processing , It is mainly used to extract image components that are meaningful to express and depict the shape of the region from the image , Such as boundary and connected area , It is convenient for subsequent image recognition .
Common scenarios : edge detection , Hole filling , Texture analysis 、 Morphological skeleton extraction 、 Shape recognition 、 Image segmentation 、 Corner extraction , Image restoration and reconstruction 、 Image compression, etc .
The basic algorithm : Expansion corrosion
, Open operation , Close your operations ;
The process of corrosion followed by expansion is called open operation . It has the function of eliminating small objects , The function of separating objects from thin objects and smoothing the boundaries of larger objects .
The process of expansion before corrosion is called closed operation . It has the function of filling small cavities in objects , The function of connecting adjacent objects and smoothing boundaries .
Realization way : Move a structural element in the image ( Filter window
), After that, the structure elements and the following binary images are intersected and merged, etc . Therefore, this binary morphological algorithm can be transformed into a set of logical operations , Simple and suitable for parallel processing , This paper adopts Hardware FPGA
Realization .
3、 ... and 、 Corrosion expansion
For corrosion expansion , The input image must be a binary image
, Multiple functions can be realized through corrosion expansion operation , Such as :
(1) Suppress noise
(2) Separate elements
(3) Connect adjacent elements
(4) Find the obvious maximum and minimum regions in the image
(5) Find the image gradient
The principle of corrosion expansion
1、 corrosion
corrosion (Erode) It's the operation of finding the local minimum , Boundary points can be eliminated , Shrink the boundary inward , So as to eliminate small and meaningless objects .
With 3x3 Template as an example ,1 For white ,0 For black .
Corrosion is the use of this 3*3 The window traverses every pixel on the binary image , In the window 9 Pixel by pixel Phase sum operation
, The result is 1 The output of 1, Otherwise 0.
2、 inflation
inflation (Dialate) It's the operation of finding the local maximum , It can merge all the background points in contact with the object into the object , The process of expanding the boundary outward , To fill the void in the object .
Expansion is this 9 Pixels or .
Be careful : If the colors of the background and the image are interchanged (0 It means white ,1 It means black ), Then you only need to reverse the and or operations of image expansion and corrosion .
Four 、matlba Achieve corrosion expansion
clc;
clear all;
close all;
RGB = imread(' Binary image .bmp'); % Image Reading
[ROW,COL, DIM] = size(RGB); % Get the number of image rows and columns
%------------------------------< Erode >-----------------------------------
Erode_img = zeros(ROW,COL);
for r = 2:ROW-1
for c = 2:COL-1
and1 = bitand(RGB(r-1, c-1), bitand(RGB(r-1, c), RGB(r-1, c+1)));
and2 = bitand(RGB( r, c-1), bitand(RGB( r, c), RGB( r, c+1)));
and3 = bitand(RGB(r+1, c-1), bitand(RGB(r+1, c), RGB(r+1, c+1)));
Erode_img(r, c) = bitand(and1, bitand(and2, and3));
end
end
%------------------------------< Dilate >----------------------------------
Dilate_img = zeros(ROW,COL);
for r = 2:ROW-1
for c = 2:COL-1
or1 = bitor(RGB(r-1, c-1), bitor(RGB(r-1, c), RGB(r-1, c+1)));
or2 = bitor(RGB( r, c-1), bitor(RGB( r, c), RGB( r, c+1)));
or3 = bitor(RGB(r+1, c-1), bitor(RGB(r+1, c), RGB(r+1, c+1)));
Dilate_img(r, c) = bitor(or1, bitor(or2, or3));
end
end
%------------------------------< show >------------------------------------
figure; imshow(RGB); title(' Original picture ');
subplot(2,2,1); imshow(Erode_img); title(' corrosion ');
imwrite (Erode_img,'Erode_img.bmp');
subplot(2,2,2); imshow(Dilate_img);title(' inflation ');
imwrite (Dilate_img,'Dilate_img.bmp');
5、 ... and 、FPGA Achieve corrosion
Binary module 、3*3 Window generation module 、 Corrosion module
verilog Realize binarization
module two(
input clk,
input rst_n,
input wire iValid,
input [7:0] iData,
output reg out_Valid,
output reg [7:0]oData_two
);
parameter THRESHOLD = 8'd150; // Threshold of binarization always @ (posedge clk or negedge rst_n) if(!rst_n) oData_two <= 0; else if (iData > THRESHOLD) oData_two <= 8'd255;
else
oData_two <= 0;
always @ (posedge clk or negedge rst_n)
if(!rst_n)
out_Valid <= 0;
else
out_Valid <= iValid;
endmodule
verlog Achieve corrosion
module Erode(
input clk,
input rst_n,
input wire iValid ,
input [7:0] filter_11,filter_12,filter_13, // Generated 3*3 Window data
input [7:0] filter_21,filter_22,filter_23,
input [7:0] filter_31,filter_32,filter_33,
output Erode_de ,//de Synchronous signal
output wire [7:0] Erode_data
);
reg [1:0] de_shift1 ;
reg g1,g2,g3,g;
//---------------------------------------------------
// Pipeline parallel operation of corrosion algorithm
//---------------------------------------------------
//clk1, And all the rows , && Logic and
always @ (posedge clk or negedge rst_n)
if(!rst_n) begin
g1 <= 1'b0; g2 <= 1'b0;
g3 <= 1'b0; end else begin g1 <= filter_11 && filter_12 && filter_13; g2 <= filter_21 && filter_22 && filter_23; g3 <= filter_31 && filter_32 && filter_33; end //clk2, The result of the sum operation on each line is summed up again always @ (posedge clk or negedge rst_n) if(!rst_n) g <= 1'b0;
else
g <= g1 && g2 && g3;
assign Erode_data = g ? 8'd255 : 8'd0;
// Beat and synchronize
always @(posedge clk or negedge rst_n) begin
if(!rst_n)begin
de_shift1 <= 2'b0;
end
else begin
de_shift1 <= {
de_shift1[0], iValid};
end
end
assign Erode_de = de_shift1[1];
endmodule
You can see that the nine pixels in the window are performing phase and operation , next clk To calculate the g1,g2,g3, All are high level , Next clk To calculate the g, High level , So you can output 255. Empathy g Low level output 0.
6、 ... and 、FPGA Achieve expansion
Same as corrosion , The difference is that it performs or operations , The core code is as follows :
//clk1, Do all lines or
always @ (posedge clk or negedge rst_n)
if(!rst_n) begin
g1 <= 1'b0; g2 <= 1'b0;
g3 <= 1'b0; end else begin g1 <= filter_11 || filter_12 || filter_13; g2 <= filter_21 || filter_22 || filter_23; g3 <= filter_31 || filter_32 || filter_33; end //clk2, The result of each line and operation is or operation again always @ (posedge clk or negedge rst_n) if(!rst_n) g <= 1'b0;
else
g <= g1 || g2 || g3;
assign Erode_data = g ? 8'd255 : 8'd0;
FPGA The effect diagram of realizing corrosion expansion is as follows :
Left : corrosion
Right : inflation
边栏推荐
- SDRAM控制器——仲裁模块的实现
- How to use commands to write file names (including paths) in folders to txt files
- Shell learning record (I)
- 宁要一个完成,不要千万个开始(转载自豆瓣)
- LeetCode 31 ~ 40
- wifi 的理论速度计算方法
- Codecraft-17 and Codeforces Round #391 (Div. 1 + Div. 2, combined) C. Felicity is Coming!
- 记录一个诡异的图片上传问题
- Finding the sum of N multiplications
- Energetic girl wangyujie was invited to be the spokesperson for the global finals of the sixth season perfect children's model
猜你喜欢
readv & writev
Wanglaoji pharmaceutical's public welfare activity of "caring for the most lovely people under the scorching sun" was launched in Hangzhou
图形渲染管线
Exploring temporary information for dynamic network embedding
@Query 疑难杂症
The answer skills and examples of practical cases of the second construction company are full of essence
-- EGFR FISH probe solution
On the difference between strlen and sizeof
shell学习记录(一)
vs2015+PCL1.8.1+qt5.12-----(1)
随机推荐
SDRAM控制器——仲裁模块的实现
cv==biaoding---open----cv001
反向输出一个整数
vs2015+PCL1.8.1+qt5.12-----(1)
Codecraft-17 and Codeforces Round #391 (Div. 1 + Div. 2, combined) C. Felicity is Coming!
Cs144 environment configuration
Sweet cool girl jinshuyi was invited to be the spokesperson for the global finals of the sixth season perfect children's model
Chemical properties and application of trypsin
On the difference between strlen and sizeof
V4l2+qt video optimization strategy
The answer skills and examples of practical cases of the second construction company are full of essence
UN make (6) conditional execution of makefile
轻轻松松理解指针
论文阅读 Exploring Temporal Information for Dynamic Network Embedding
标定。。。
通俗易懂C語言關鍵字static
安装了Visual Studio 2013 Redistributable,mysql还是安装失败
Steps of program compilation precompile compilation assembly connection
Detailed explanation of memory leak check tools
静态库动态库的使用