FPGA-based image binarization processing, including tb test files and MATLAB-assisted verification

1. Preview of algorithm operation renderings

Import FPGA data into matlab for display

2.Algorithm running software version

Vivado2019.2

matlab2022a

3. Some core programs

`timescale 1ns / 1ps
.............................................................................
module test_image;

reg i_clk;
reg i_rst;
reg i_ready;
reg [7:0] Tmp[0:100000];
reg [7:0] datas;
wire [7:0] o_ybw;
integer fids,jj=0,dat;
 
//D:\FPGA_Proj\FPGAtest\code2

initial 
begin
	fids = $fopen("D:\\FPGA_Proj\\FPGAtest\\code2\\data.bmp","rb");
	dat  = $fread(Tmp,fids);
	$fclose(fids);
end
 
initial 
begin
i_clk=1;
i_rst=1;
i_ready=0;
#1000;
i_ready=1;
i_rst=0;
end 

always #5  i_clk=~i_clk;
 
always@(posedge i_clk) 
begin
	datas<=Tmp[jj];
	jj<=jj+1;
end
 

im2bw im2bw_u(
.i_clk    (i_clk),
.i_rst    (i_rst),
.i_ready  (i_ready),
.i_xin    (datas),
.o_ybw    (o_ybw)
);

integer fout1;
initial begin
 fout1 = $fopen("result.txt","w");
end

always @ (posedge i_clk)
 begin

	$fwrite(fout1,"%d\n",o_ybw);
	
end

endmodule
0X_005m

4. Overview of algorithm theory

       Image binarization processing based on FPGA (Field Programmable Gate Array) mainly relies on digital image processing technology. The principle is to convert a grayscale image into a binary image, leaving only black and white in the image, thereby simplifying the image data and facilitating further analysis and processing of the image.

        In image binarization processing, the most commonly used method is the threshold method, which means setting a threshold and then dividing the pixels of the image into two categories based on this threshold. Specifically, if the grayscale value of a certain pixel in the image is greater than or equal to this threshold, it is set to white (or black), otherwise it is set to black (or white).

The mathematical formula of the threshold method is as follows:

Binarized image pixel point P(x,y) = { 1, if the gray value of the original image pixel point P(x,y) >= threshold; 0, if the original image pixel point P(x,y) The gray value < threshold. }

Among them, P(x,y) is the pixel point of the image at the (x,y) position.

FPGA-based image binarization processing usually includes the following steps:

  1. Image acquisition: Obtain image data through a camera or other image input device.
  2. Preprocessing: Preprocess the collected images, such as noise reduction, normalization, etc., to improve image quality and reduce the complexity of subsequent processing.
  3. Binarization: Binarize the preprocessed image. Commonly used methods include global thresholding, local thresholding, etc.
  4. Post-processing: further process the binarized image, such as denoising, filling, etc., to improve the binarization effect.
  5. Output: Output the processed image data to a display device or other device.

       The role of FPGA in these steps is mainly to implement these algorithms and process image data in real time. Because FPGA has parallel processing capabilities and configurability, it is very suitable for implementing such image processing tasks that require efficient, real-time processing.

      The specific implementation of image binarization processing based on FPGA will vary depending on the FPGA model, image processing algorithm, hardware environment and other factors. For example, different FPGA models may have different hardware resources (such as logic units, memory size, etc.), so some optimizations may need to be made based on hardware resources when implementing image processing algorithms. At the same time, different image processing algorithms have different requirements for computing performance, so it may be necessary to select a suitable FPGA model based on the requirements of the algorithm.

       In general, FPGA-based image binarization processing is an efficient and real-time image processing technology. It uses the parallel processing capabilities and configurability of FPGA to implement image processing algorithms, thereby achieving real-time processing and processing of image data. analyze.

5. Algorithm complete program engineering

OOOOO

OOO

O

Guess you like

Origin blog.csdn.net/aycd1234/article/details/132768682