www.久久久久|狼友网站av天堂|精品国产无码a片|一级av色欲av|91在线播放视频|亚洲无码主播在线|国产精品草久在线|明星AV网站在线|污污内射久久一区|婷婷综合视频网站

當(dāng)前位置:首頁 > > FPGA開源工作室

基于FPGA的圖像差分處理

1背景知識(shí)

差分圖像就是目標(biāo)場景在連續(xù)時(shí)間點(diǎn)圖像相減所構(gòu)成的圖像,廣義的差分圖像定義為目標(biāo)場景在時(shí)間點(diǎn)tktk+L所成圖像的差別。差分圖像是由目標(biāo)場景在相鄰時(shí)間點(diǎn)的圖像相減得到的,從而能夠得到目標(biāo)場景隨時(shí)間的變換。

差分圖像在許多領(lǐng)域得到了廣泛的應(yīng)用,比如:視頻壓縮,生物醫(yī)學(xué)診斷,天文學(xué),遙感,人臉識(shí)別等。

2 matlab仿真

MATLAB源碼:

Main.m

I = imread('flower.bmp'); figure, imshow(I);

I_gray = rgb2gray(I);figure,imshow(I_gray);

Id = mipcentraldiff(I_gray,'dx'); figure, imshow(Id);

Mipcentraldiff.m

function dimg = mipcentraldiff(img,direction)

% MIPCENTRALDIFF Finite difference calculations

%

% DIMG = MIPCENTRALDIFF(IMG,DIRECTION)

%

% Calculates the central-difference for?a given direction

% IMG : input image

% DIRECTION : 'dx'?or 'dy'

% DIMG : resultant image

%

% See also MIPFORWARDDIFF MIPBACKWARDDIFF MIPSECONDDERIV

% MIPSECONDPARTIALDERIV

% Omer Demirkaya, Musa Asyali, Prasana Shaoo, ...

% Medical Image Processing Toolbox

img = padarray(img,[1 1],'symmetric','both');

[row,col] = size(img);

dimg = zeros(row,col);

switch(direction)

case'dx',

dimg(:,2:col-1) = (img(:,3:col)-img(:,1:col-2))/2;

case'dy',

dimg(2:row-1,:) = (img(3:row,:)-img(1:row-2,:))/2;

otherwise,

disp('Direction is unknown');

end

dimg = dimg(2:end-1,2:end-1);

仿真結(jié)果:

1 RGB原圖

2 gray

3 central_diff

3 FPGA設(shè)計(jì)

4 基于串口傳圖的中心差分

如圖4所示,我們將RGB565格式轉(zhuǎn)化為Ycbcr格式,Y通道進(jìn)入中心差分模塊,完成中心差分算法。

FPGA源碼:

/*

Module name:

Description:

Data:         2018/03/16

Engineer:     lipu

e-mail:       137194782@qq.com

微信公眾號(hào): FPGA開源工作室

*/

////////////////////////////////////////////////////////////////

wire [15:0] rgb;

wire hs;

wire vs;

wire de;

wire o_hs;

wire o_vs;

wire o_de;

wire[7 : 0]o_y_8b;

wire[7 : 0]o_cb_8b;

wire[7 : 0]o_cr_8b;

//assign TFT_rgb = {o_y_8b[7:3],o_y_8b[7:2],o_y_8b[7:3]};     //Y

//assign TFT_rgb = {o_cb_8b[7:3],o_cb_8b[7:2],o_cb_8b[7:3]};  //cb

//assign TFT_rgb = {o_cr_8b[7:3],o_cr_8b[7:2],o_cr_8b[7:3]};  //cr

//////////////////////////////////////////////////////////////

tft_ctrl tft_ctrl(

.Clk9M(clk9M),//系統(tǒng)輸入時(shí)鐘9MHZ

.Rst_n(Rst_n),//復(fù)位輸入,低電平復(fù)位

.data_in({Rd_data[7:0],Rd_data[15:8]}),//待顯示數(shù)據(jù)

.hcount(),//TFT行掃描計(jì)數(shù)器

.vcount(),//TFT場掃描計(jì)數(shù)器

.TFT_RGB(rgb),//TFT數(shù)據(jù)輸出

.TFT_HS(hs),//TFT行同步信號(hào)

.TFT_VS(vs),//TFT場同步信號(hào)

.TFT_CLK(TFT_clk),//TFT像素時(shí)鐘

.TFT_DE(de),//TFT數(shù)據(jù)使能

.TFT_begin(tft_begin),

.TFT_PWM(TFT_pwm)//TFT背光控制

);

rgb_to_ycbcr  rgb_to_ycbcr_inst(

.clk(TFT_clk),

.i_r_8b({rgb[15:11],3'b0}),

.i_g_8b({rgb[10:5],2'b0}),

.i_b_8b({rgb[4:0],3'b0}),

.i_h_sync(hs),

.i_v_sync(vs),

.i_data_en(de),


.o_y_8b(o_y_8b),

.o_cb_8b(o_cb_8b),

.o_cr_8b(o_cr_8b),


.o_h_sync(o_hs),

.o_v_sync(o_vs),

.o_data_en(o_de)

);


reg [7:0] diff_data;

reg [7:0] o_y_8b_r0;

reg [7:0] o_y_8b_r1;

reg [7:0] o_y_8b_r2;

reg hs0;

reg hs1;

reg hs2;

reg vs0;

reg vs1;

reg vs2;

reg de0;

reg de1;

reg de2;

always @(posedge TFT_clk or negedge Rst_n) begin

if(!Rst_n) begin

hs0 <= 0;

hs1 <= 0;

hs2 <= 0;

vs0 <= 0;

vs1 <= 0;

vs2 <= 0;

de0 <= 0;

de1 <= 0;

de2 <= 0;

o_y_8b_r0 <= 0;

o_y_8b_r1 <= 0;

o_y_8b_r2 <= 0;

end

else begin

hs0 <= o_hs;

hs1 <= hs0;

hs2 <= hs1;

vs0 <= o_vs;

vs1 <= vs0;

vs2 <= vs1;

de0 <= o_de;

de1 <= de0;

de2 <= de1;

o_y_8b_r0 <= o_y_8b;

o_y_8b_r1 <= o_y_8b_r0;

o_y_8b_r2 <= o_y_8b_r1;

end

end

always @(posedge TFT_clk or negedge Rst_n) begin

if(!Rst_n)

diff_data <= 0;

else if(de2)

diff_data <= (o_y_8b_r2 - o_y_8b_r0) >>1;

else

diff_data <= diff_data;

end

assign TFT_rgb = {diff_data[7:3],diff_data[7:2],diff_data[7:3]};

assign TFT_de  = de1;

assign TFT_hs  = hs1;

assign TFT_vs  = vs1;

Endmodule

結(jié)果展示:

5 FPGA中心差分結(jié)果

如圖5所示,由于手機(jī)拍攝原因,圖片不是很清晰,但基本結(jié)果一致,實(shí)驗(yàn)成功。我們將把中心差分模塊移植到基于ov5640的實(shí)時(shí)圖像采集系統(tǒng)完成rgb三通道的彩色輸出。

6 基于ov5640r/g/b通道彩色實(shí)時(shí)輸出中心差分


實(shí)驗(yàn)結(jié)果成功,部分帶有彩色。

本站聲明: 本文章由作者或相關(guān)機(jī)構(gòu)授權(quán)發(fā)布,目的在于傳遞更多信息,并不代表本站贊同其觀點(diǎn),本站亦不保證或承諾內(nèi)容真實(shí)性等。需要轉(zhuǎn)載請(qǐng)聯(lián)系該專欄作者,如若文章內(nèi)容侵犯您的權(quán)益,請(qǐng)及時(shí)聯(lián)系本站刪除。
關(guān)閉