学习testbench--图像读取

来源:互联网 发布:淘宝网页面显示不正常 编辑:程序博客网 时间:2024/06/15 06:27

之前一直疑问如何将图像写成testbench来检测由FPGA写的图像处理模块的正确性。

终于在某个blog上找到了一种方法:

    第一步:通过matlab将图片数据分成RGB数据存入三个txt文件中

img = 'test';
img_data = imread(img,'bmp');
[X,Y,Z] = size(img_data);
fid_R = fopen('data_R.txt','w+');
fid_G = fopen('data_G.txt','w+');
fid_B = fopen('data_B.txt','w+');
 
for x = 1:X
   for y = 1:Y
       r = img_data(x,y,1);
       g = img_data(x,y,2);
       b = img_data(x,y,3);
       r_b = dec2bin(r);
       g_b = dec2bin(g);
       b_b = dec2bin(b);
       fprintf(fid_R, '%s\n', r_b);
       fprintf(fid_G, '%s\n', g_b);
       fprintf(fid_B, '%s\n', b_b);
   end
end
 
    第二步:使用testbench读取
    module readimg();
 
parameter cols = 392;
parameter rows = 258;
reg[7:0] mem_R[cols*rows-1:0];
reg[7:0] mem_G[cols*rows-1:0];
reg[7:0] mem_B[cols*rows-1:0];
 
initial
begin
$readmemb("data_R.txt",mem_R);
$readmemb("data_G.txt",mem_G);
$readmemb("data_B.txt",mem_B);
end
endmodule

--------本文转自http://www.eefocus.com/ssagittis/blog/15-02/310385_0c479.html-------------
原创粉丝点击