当前位置:网站首页>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 
边栏推荐
- 連接投影儀
- A lost note for konjaku beginner
- Command of gun make (4) rule
- Dazhou suggested that we media bloggers do these four things in the early stage
- 轻轻松松理解指针
- 创建OpenGl窗口
- cv==biaoding---open----cv001
- Chinese and English instructions of collagen enzyme Worthington
- shell学习记录(四)
- Steps of program compilation precompile compilation assembly connection
猜你喜欢

Mot - clé C facile à comprendre statique

关于VS scanf出现‘scanf‘: This function or variable may be unsafe. Consider usi问题的解决方法

SDRAM控制器——添加读写FIFO

Shell learning record (II)

树莓派 + AWS IoT 入门实验

shell学习记录(四)

One minute to understand the difference between synchronous, asynchronous, blocking and non blocking

Sunshine boy chenhaotian was invited to be the spokesperson for the global finals of the sixth season perfect children's model

Redis7.0 installation steps

Show spirit chenzitong was invited to be the chief experience officer of the global finals of the sixth season perfect children's model
随机推荐
Is the securities account recommended by qiniu safe?
Multi type study of Worthington collagen protease
Abnova anti GBA monoclonal antibody solution
Convert Weishi camera pictures
连接投影仪
About vs scanf, 'scanf' appears: this function or variable may be unsafe Solutions to the problem of consumer usi
How to add a "security lock" to the mobile office of government and enterprises?
Computer shortcut keys commonly used by experts
Playful girl wangyixuan was invited to serve as the Promotion Ambassador for the global finals of the sixth season perfect children's model
跨域问题的一种解决方案
Redis-链表
Jenkins localization and its invalid solution
Other codes,, VT,,, K
How to efficiently complete daily tasks?
关于VS scanf出现‘scanf‘: This function or variable may be unsafe. Consider usi问题的解决方法
Connecting the projector
Exploring temporary information for dynamic network embedding
buffer
Easyexcel read file
Three factors affecting personal growth