[X]关闭

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

文档创建者:FPGA课程
浏览次数:9
最后更新:2024-10-21
文档课程分类-AMD-ZYNQ
AMD-ZYNQ: ZYNQ-FPGA部分 » 2_FPGA实验篇(仅旗舰) » 8-FPGA图像入门
本帖最后由 FPGA课程 于 2024-10-21 18:43 编辑

​ 软件版本: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 代码分析
源代码如下:
  1. clear;clear all;clc;

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


  4. image_binary=zeros(row,col); for i=1:row
  5. for j=1:col
  6. if image_gray(i,j) > 92
  7. image_binary(i,j)=255; else
  8. image_binary(i,j)=0; end
  9. end end

  10. image_edge_0=zeros(row,col);
  11. for i = 2:1:row-1
  12. for j = 2:1:col-1
  13. %bitand 按位与运算 bitor 按位或运算,全为黑色或白色 if(...
  14. bitand(bitand(bitand(bitand(bitand(bitand(bitand(bitand(...
  15. image_binary(i-1,j-1), image_binary(i-1,j)),image_binary(i-1,j+1)),...
  16. image_binary(i,j-1    )),image_binary(i,j    )),image_binary(i,j+1    )),...
  17. 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(...
  18. image_binary(i-1,j-1), image_binary(i-1,j)),image_binary(i-1,j+1)),...
  19. image_binary(i,j-1    )),image_binary(i,j    )),image_binary(i,j+1    )),...
  20. image_binary(i+1,j-1)),image_binary(i+1,j)),image_binary(i+1,j+1)) == 0)
  21. image_edge_0(i,j) = 0; else
  22. image_edge_0(i,j) = 255; end
  23. end end

  24. image_edge_ 1=zeros(row,col); for i = 2:1:row-1
  25. for j = 2:1:col-1 if(...
  26. 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     ||...
  27. 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)

  28. image_edge_1(i,j) = 0; else
  29. image_edge_1(i,j) = 255; end
  30. end end

  31. subplot(221);
  32. imshow(image_gray); title('the image gray image'); subplot(222);
  33. imshow(image_binary); title('the image binary image'); subplot(223);
  34. imshow(image_edge_0); title('the image edge 0 image'); subplot(224);
  35. imshow(image_edge_ 1); title('the image edge 1 image');
复制代码

2.2Verilog 代码分析
  1. always@(posedge i_clk ornegedge i_rst_n) begin
  2. if(!i_rst_n) begin
  3. outline_en <= 'd0;
  4. end    else    begin
  5. if(((r_temp_ 11[0] &&
  6. r_temp_ 12[0] &&
  7. r_temp_ 13[0] &&
  8. r_temp_21[0] &&
  9. r_temp_22[0] &&
  10. r_temp_23[0] &&
  11. r_temp_31[0] &&
  12. r_temp_32[0] &&
  13. r_temp_33[0]) == 1) ||((
  14. r_temp_ 11[0] ||
  15. r_temp_ 12[0] ||
  16. r_temp_ 13[0] ||
  17. r_temp_21[0] ||
  18. r_temp_22[0] ||
  19. r_temp_23[0] ||
  20. r_temp_31[0] ||
  21. r_temp_32[0] ||
  22. r_temp_33[0]) == 0) )
  23. outline_en <= 1; else
  24. outline_en <= 0;
  25. end end

  26. always@(posedge i_clk ornegedge i_rst_n) begin
  27. if(!i_rst_n) begin
  28. binary_reg <= 'd0; end
  29. else if(outline_en) begin
  30. binary_reg <= 'd0;
  31. end    else    begin
  32. binary_reg <= 'd255; end
  33. 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




您需要登录后才可以回帖 登录 | 立即注册

本版积分规则