首页 / FPGA教程-AMD / 帖子

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

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

​软件版本: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 代码分析

clear;clear all;clc;

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

image_gray = rgb2gray(image_in);

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

for i = 2:1:row-1

for j = 2:1:col-1

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)

image_relief_d(i,j) = 255; elseif(image_relief_d(i,j) < 0)

image_relief_d(i,j) = 0; end

end end

image_relief_d1=zeros(size(image_gray),'like',image_gray); for i = 2:1:row-1

for j = 2:1:col-1

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)

image_relief_d1(i,j) = 255; elseif(image_relief_d1(i,j) < 0)

image_relief_d1(i,j) = 0; end

end end

subplot(311);

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

imshow(image_relief_d); title('the image relief image'); subplot(313);

imshow(image_relief_d1); title('the image relief 1 image');

2.2Verilog 代码分析

assign         o_hs                =hsyn_reg[1];

assign o_vs =vsyn_reg[1];

assign o_en = en_reg[1];

assign o_gray = gray_reg_1d;

assign relief = i_gray - gray_reg + value;

always@(posedge i_clk ornegedge i_rst_n) begin

if(!i_rst_n) begin

hsyn_reg <= 'd0;

vsyn_reg <= 'd0;

en_reg <= 'd0; gray_reg <= 'd0;

end else begin

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;

end end

always@(posedge i_clk ornegedge i_rst_n) begin

if(!i_rst_n) begin

gray_reg_ 1d <= 'd0;

end

else if(relief > 255) begin

gray_reg_ 1d <= 255;

end

else if(relief < 0) begin

gray_reg_ 1d <= 0;

end else begin

gray_reg_ 1d <= relief;

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

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