前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >FPGA实现图像浮雕效果

FPGA实现图像浮雕效果

作者头像
FPGA开源工作室
发布2019-10-29 18:08:48
6420
发布2019-10-29 18:08:48
举报
文章被收录于专栏:FPGA开源工作室FPGA开源工作室

FPGA实现图像浮雕效果

1 概述

浮雕在我们现实生活中处处可见,尤其是中国古代的建筑浮雕众多。浮雕既是一种刻在砖、石壁或木头上的一种雕塑。

图像处理算法原理:newpixel(i,j) = pixel(i,j)-pixel(i,j+1)+TH

i为图像高度,j为图像宽度,pixel为当前图像像素点,TH为阈值(0-255)。

2 matlab实现

Matlab实验TH均取100。

实验原图:

Matlab源码:

close all

clear all

clc

Irgb = imread('1.bmp');%

Igray= rgb2gray(Irgb);

[Height,Width,Dim] = size(Irgb);

Inew = zeros(Height,Width);

TH = 100;

for i = 1:Height

for j=1:Width-1

Inew(i,j)=Igray(i,j)-Igray(i,j+1)+TH;

%Inew(i,j)=Igray(i,j+1)-Igray(i,j)+100;

if Inew(i,j) >255

Inew(i,j) = 255;

elseif Inew(i,j) <0

Inew(i,j) = 0;

else

Inew(i,j) = Inew(i,j);

end

end

end

Inew = uint8(Inew);

subplot(221),imshow(Irgb);

subplot(222),imshow(Igray);

subplot(223),imshow(Inew);

subplot(224),imshow(Irgb);

Matlab实验结果:

3 FPGA实现

FPGA实现浮雕效果算法过程:

1,将RGB图像转换为灰度图像

2,对灰度图像进行浮雕算法处理实现浮雕效果

FPGA源码:

/**********************************

copyright@FPGA OPEN SOURCE STUDIO

微信公众号:FPGA开源工作室

Algorithm:emboss = img(i,j)-img(i,j+1)+TH

Description:i--Image height

j--Image width

TH --[0 255]

***********************************/

module emboss#(

parameter DW = 24,

parameter TH = 100

)(

input pixelclk,

input reset_n,

input [DW-1:0] din,//gray in

input i_hsync,

input i_vsync,

input i_de,

output [DW-1:0]dout,//emboss out

output o_hsync,

output o_vsync,

output o_de

);

wire [7:0] gray = din[23:16]; //img(i,j)

reg [7:0] gray_r;//img(i,j+1)

reg signed [9:0] emboss_r;//10bit signed -512 --511

reg [7:0] dout_r;

reg hsync_r0,hsync_r1;

reg vsync_r0,vsync_r1;

reg de_r0,de_r1;

assign o_hsync = hsync_r1;

assign o_vsync = vsync_r1;

assign o_de = de_r1;

assign dout = {dout_r,dout_r,dout_r};

//synchronization

always @(posedge pixelclk) begin

hsync_r0 <= i_hsync;

vsync_r0 <= i_vsync;

de_r0 <= i_de;

hsync_r1 <= hsync_r0;

vsync_r1 <= vsync_r0;

de_r1 <= de_r0;

end

//pipeline

always @(posedge pixelclk) begin

if(!reset_n)

gray_r <= 0;

else

gray_r <= gray;

end

always @(posedge pixelclk or negedge reset_n)begin

if(!reset_n) begin

emboss_r<= 0;

dout_r <= 0;

end

else begin

emboss_r<= gray-gray_r+TH;//max 355 min -155

if(emboss_r>255) dout_r <= 255;

else if(emboss_r<0) dout_r <= 0;

else dout_r <= emboss_r[7:0];

end

end

Endmodule

FPGA实现效果:

本文参与 腾讯云自媒体分享计划,分享自微信公众号。
原始发表:2019-08-11,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 FPGA开源工作室 微信公众号,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档