基于FPGA的图像缩小算法实现,包括tb测试文件和MATLAB辅助验证

1.算法运行效果图预览

 

 

 

将FPGA的处理结果导出到matlab中显示图像效果:

 

 

 

2.算法运行软件版本

vivado2019.2

 

matlab2022a

 

3.算法理论概述

       图像放小算法主要通过抽取算法实现,常见的抽取算法最大值抽取,和均值抽取。其示意图如下所示:

 

 

 

       以缩小一半为例,如果是最大值抽取,则在一个2*2窗口内,选择最大的像素输出,那么整个图像的维度就变为了原图像的一半。如果是均值抽取,则在一个2*2窗口内,选择四个像素均值输出,那么整个图像的维度就变为了原图像的一半。

 

       在FPGA上实现图像放小算法时,可以采用硬件并行处理的方式,以提高处理速度。具体地,可以通过图像数据缓冲单元模块来实现。

 

 

 

 

4.部分核心程序

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
`timescale 1ns / 1ps
//
// Company:
// Engineer:
//
// Create Date: 2022/07/28 01:51:45
// Design Name:
// Module Name: test_image
// Project Name:
// Target Devices:
// Tool Versions:
// Description:
//
// Dependencies:
//
// Revision:
// Revision 0.01 - File Created
// Additional Comments:
//
//
  
  
module test_image;
  
reg i_clk;
reg i_rst;
reg i_en;
reg [7:0] image_buff [0:100000];
reg [7:0] II0;
wire [7:0] o_image;
wire flager;
integer fids,jj=0,dat;
  
//D:\FPGA_Proj\FPGAtest\codepz
  
initial
begin
    fids = $fopen("D:\\FPGA_Proj\\FPGAtest\\codepz\\data.bmp","rb");
    dat  = $fread(image_buff,fids);
    $fclose(fids);
end
  
initial
begin
i_clk=1;
i_rst=1;
#2000;
i_rst=0;
end
  
always #10  i_clk=~i_clk;
  
always@(posedge i_clk)
begin
     if(i_rst)
     begin
     II0<=0;
     jj<=0;
     end
     else
     begin
     if(jj<=66614 & jj>=1)
     i_en<=1'b1;
     else
     i_en<=1'b0;
     II0<=image_buff[jj];
     jj<=jj+1;
     end
end
  
  
tops tops_u(
.i_clk              (i_clk),
.i_rst              (i_rst),
.i_en               (i_en),
.i_I0               (II0),
.o_image            (o_image),
.flager             (flager)
);
  
reg[19:0]cnts;
always @(posedge i_clk or posedge i_rst)
begin
     if(i_rst)
     begin
         cnts<=20'd0;
     end
else begin
         cnts<=cnts+20'd1;
     end
end 
  
  
  
integer fout1;
integer fout2;
initial begin
  fout1 = $fopen("flager.txt","w");
  fout2 = $fopen("expansion.txt","w");
end
  
  
always @ (posedge i_clk)
 begin
    if(cnts <= 66514)
    begin
    $fwrite(fout1,"%d\n",flager);
    $fwrite(fout2,"%d\n",o_image);
    end
    else
    begin
    $fwrite(fout1,"%d\n",0);
    $fwrite(fout2,"%d\n",0);
    end
     
end
  
endmodule

  

posted @   简简单单做算法  阅读(65)  评论(0编辑  收藏  举报
(评论功能已被禁用)
相关博文:
阅读排行:
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· C#/.NET/.NET Core优秀项目和框架2025年2月简报
· Manus爆火,是硬核还是营销?
· 一文读懂知识蒸馏
· 终于写完轮子一部分:tcp代理 了,记录一下
点击右上角即可分享
微信分享提示