[X]关闭

[米联客-XILINX-H3_CZ08_7100] FPGA_图像入门连载-22FPGA 实现图像浮雕效果处理

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

​软件版本: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 图像浮雕效果算法简介        
浮雕效果就是为了突出图像中的变化部分,降低图像中相似的部分,使图像中出现纵深感,以达到浮雕的效果。
一般的处理流程是,将要处理的像素点的左上角像素与右下角的像素做差值然后加上 128,大于 255 就把该像 素换成 255,小于 0 则换成 0 ,其他的不做任何处理。
image_relief_d(i,j)  =image_gray(i-1,j-1)  -  image_gray(i+1,j+1)  +  128;
为了计算方便我们还可以采用一行像素中前后两个像素做差值然后加上一个阈值补偿,大于 255 就把该像素换 成 255,小于 0 则换成 0 ,其他的不做任何处理。
image_relief_d(i,j)  =image_gray(i,j+1)  -  image_gray(i,j)  +  value;

2 设计分析
2.1Matlab 代码分析
  1. clear;clear all;clc;

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

  4. image_relief_d=zeros(size(image_gray),'like',image_gray);

  5. for i = 2:1:row-1
  6. for j = 2:1:col-1
  7. image_relief_d(i,j) =image_gray(i-1,j-1) - image_gray(i+1,j+1) + 128; if(image_relief_d(i,j) > 255)
  8. image_relief_d(i,j) = 255; elseif(image_relief_d(i,j) < 0)
  9. image_relief_d(i,j) = 0; end

  10. end end
  11. image_relief_d1=zeros(size(image_gray),'like',image_gray); for i = 2:1:row-1
  12. for j = 2:1:col-1
  13. image_relief_d1(i,j) =image_gray(i-1,j-1) - image_gray(i+1,j+1) + 128; if(image_relief_d1(i,j) > 255)
  14. image_relief_d1(i,j) = 255; elseif(image_relief_d1(i,j) < 0)
  15. image_relief_d1(i,j) = 0; end

  16. end end

  17. subplot(311);
  18. imshow(image_gray); title('the image gray image'); subplot(312);
  19. imshow(image_relief_d); title('the image relief image'); subplot(313);
  20. imshow(image_relief_d1); title('the image relief 1 image');
复制代码

2.2Verilog 代码分析
  1. assign         o_hs                =hsyn_reg[1];
  2. assign         o_vs                =vsyn_reg[1];
  3. assign         o_en                = en_reg[1];        
  4. assign         o_gray        = gray_reg_1d;
  5. assign  relief = i_gray - gray_reg + value;

  6. always@(posedge i_clk ornegedge i_rst_n) begin
  7. if(!i_rst_n) begin
  8. hsyn_reg <= 'd0;
  9. vsyn_reg <= 'd0;
  10. en_reg             <= 'd0; gray_reg <= 'd0;
  11. end    else    begin
  12. hsyn_reg <= {hsyn_reg[0],i_hsyn}; vsyn_reg <= {vsyn_reg[0],i_vsyn}; en_reg             <= {en_reg[0],i_en}; gray_reg <= i_gray;
  13. end end
  14. always@(posedge i_clk ornegedge i_rst_n) begin
  15. if(!i_rst_n) begin
  16. gray_reg_ 1d   <= 'd0;
  17. end
  18. else if(relief > 255) begin
  19. gray_reg_ 1d   <= 255;
  20. end
  21. else if(relief < 0) begin
  22. gray_reg_ 1d   <= 0;
  23. end    else    begin
  24. gray_reg_ 1d   <= relief;
  25. end end
复制代码

2.3 工程结构分析
我们将图像浮雕效果的模块做成 IP 后,在vivado 中进行工程的搭建,工程结构如图所示:
7c41b2a98f7e469293ad300fbb484272.jpg
3 仿真及结果
3.1Matlab 实验结果
a64dbdccd95644718caae4e1916acab1.jpg

3.2Modelsim 实验结果
e3b0e9fae8a64457b121f3fdd2fe4caa.jpg
4 搭建 Vitis-sdk 工程
创建 soc_base  sdk  platform  和 APP  工程的过程不再重复,可以阅读 3-3-01_sdk_base_app。以下给出创建好 soc_base sdk platform 的截图和对应工程 APP 的截图。
4.1 创建 SDK Platform 工程
00f44801247c4475980ec1269616c541.jpg

4.2SDK APP 工程
d370278a6d4a46269b8dc6476a8ffa70.jpg
5 硬件连接
硬件连接如图所示:
fd225c1417da4c319563d4dd84df6456.jpg
6 上板实验结果
实验结果如图所示:

cce867d3e3134755b1068d7b954704a4.jpg







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

本版积分规则