首页 / FPGA教程-AMD / 帖子

[米联客-XILINX-H3_CZ08_7100] FPGA_图像入门连载-20FPGA 实现图像二值化轮廓提取处理

作者 UT发布 2024-10-21 2990 次浏览 0 条回复 论坛存档
U
UT发布
2024-10-21
楼主

​ 软件版本:VIVADO2021.1

操作系统:WIN10 64bit

硬件平台:适用 XILINX A7/K7/Z7/ZU/KU 系列 FPGA

实验平台:米联客-MLK-H3-CZ08-7100开发板

板卡获取平台:https://milianke.tmall.com/

登录“米联客”FPGA社区 http://www.uisrc.com 视频课程、答疑解惑!


1 图像二值化轮廓提取算法简介

二值化轮廓提取可以显著的提取出二值图像中的物体特征,对于识别和分析图像内容提供了方便。以 3x3 的滑 动模板,具体操作是当图像中的九个像素全为白色(“1”)或全为黑色(“0”)时输出为黑色(“0”),其他输出白色 (ℼ1”),这样就可以将图中物体的轮廓使用白色线条描述出来。

2 设计分析

2.1Matlab 代码分析

源代码如下:

clear;clear all;clc;

image_in = imread('geeker_fpga.jpg'); [row,col,n] = size(image_in);

image_gray = rgb2gray(image_in);

image_binary=zeros(row,col); for i=1:row

for j=1:col

if image_gray(i,j) > 92

image_binary(i,j)=255; else

image_binary(i,j)=0; end

end end

image_edge_0=zeros(row,col);

for i = 2:1:row-1

for j = 2:1:col-1

%bitand 按位与运算 bitor 按位或运算,全为黑色或白色 if(...

bitand(bitand(bitand(bitand(bitand(bitand(bitand(bitand(...

image_binary(i-1,j-1), image_binary(i-1,j)),image_binary(i-1,j+1)),...

image_binary(i,j-1 )),image_binary(i,j )),image_binary(i,j+1 )),...

image_binary(i+1,j-1)),image_binary(i+1,j)),image_binary(i+1,j+1)) == 255 ||... bitor(bitor(bitor(bitor(bitor(bitor(bitor(bitor(...

image_binary(i-1,j-1), image_binary(i-1,j)),image_binary(i-1,j+1)),...

image_binary(i,j-1 )),image_binary(i,j )),image_binary(i,j+1 )),...

image_binary(i+1,j-1)),image_binary(i+1,j)),image_binary(i+1,j+1)) == 0)

image_edge_0(i,j) = 0; else

image_edge_0(i,j) = 255; end

end end

image_edge_ 1=zeros(row,col); for i = 2:1:row-1

for j = 2:1:col-1 if(...

image_binary(i-1,j-1)== 0 &&image_binary(i-1,j)== 0 &&image_binary(i-1,j+1) == 0 &&... image_binary(i,j-1) == 0 &&image_binary(i,j) == 0 &&image_binary(i,j+1) == 0 &&... image_binary(i+1,j-1)== 0 &&image_binary(i+1,j)== 0 &&image_binary(i+1,j+1) == 0 ||...

image_binary(i-1,j-1)== 255 &&image_binary(i-1,j)== 255 &&image_binary(i-1,j+1) == 255&&... image_binary(i,j-1) == 255 &&image_binary(i,j) == 255 &&image_binary(i,j+1) == 255&&... image_binary(i+1,j-1)== 255 &&image_binary(i+1,j)== 255 &&image_binary(i+1,j+1) == 255)

image_edge_1(i,j) = 0; else

image_edge_1(i,j) = 255; end

end end

subplot(221);

imshow(image_gray); title('the image gray image'); subplot(222);

imshow(image_binary); title('the image binary image'); subplot(223);

imshow(image_edge_0); title('the image edge 0 image'); subplot(224);

imshow(image_edge_ 1); title('the image edge 1 image');

2.2Verilog 代码分析

always@(posedge i_clk ornegedge i_rst_n) begin

if(!i_rst_n) begin

outline_en <= 'd0;

end else begin

if(((r_temp_ 11[0] &&

r_temp_ 12[0] &&

r_temp_ 13[0] &&

r_temp_21[0] &&

r_temp_22[0] &&

r_temp_23[0] &&

r_temp_31[0] &&

r_temp_32[0] &&

r_temp_33[0]) == 1) ||((

r_temp_ 11[0] ||

r_temp_ 12[0] ||

r_temp_ 13[0] ||

r_temp_21[0] ||

r_temp_22[0] ||

r_temp_23[0] ||

r_temp_31[0] ||

r_temp_32[0] ||

r_temp_33[0]) == 0) )

outline_en <= 1; else

outline_en <= 0;

end end

always@(posedge i_clk ornegedge i_rst_n) begin

if(!i_rst_n) begin

binary_reg <= 'd0; end

else if(outline_en) begin

binary_reg <= 'd0;

end else begin

binary_reg <= 'd255; end

end

2.3 工程结构分析

我们将图像算法的模块做成 IP 后,在vivado 中进行工程的搭建,工程结构如图所示:

102c7cf44b3a4c62ac8cb391926fdf15.jpg

3 仿真及结果

3.1Matlab 实验结果

7a80e9952df34e18bce0785b607ea1ac.jpg

3.2Modelsim 实验结果

251fd0c8b6004d93ace6017bbf1baba0.jpg

4 搭建 Vitis-sdk 工程

创建 soc_base sdk platform 和 APP 工程的过程不再重复,可以阅读 3-3-01_sdk_base_app。以下给出创建好 soc_base sdk platform 的截图和对应工程 APP 的截图。

4.1 创建 SDK Platform 工程

fad74342fe6d49c2b109f08f62dcc65f.jpg

4.2SDK APP 工程

3d19f2bff728422abcc14948e416de64.jpg

5 硬件连接

硬件连接如图所示:

c6cfc8dbe0b1457094b295fc7006702c.jpg

6 上板实验结果

实验结果如图所示:

10974db1834048018edeca038aef04a9.jpg​

这是论坛时期的原帖存档,只读。新的讨论请到 提问, 沉淀下来的内容会进 知识库 和 方案库。