Image Sub-pixel interpolation by Verilog
bilinear interpolation
--------------------------------------------------------
input
a0 a1
b0 b1
--------------------------------------------------------
- t1 = a0*(1-dx) + a1*dx
- t2 = b0*(1-dx) + b1*dx
- c = t1*(1-dy) + t2*dy
c is the output
-------------------------------------------------------
`define _DEBUG
module sub_pixel(clk
, rst_n
, a_en
, a0
, a1
, b0
, b1
, dx
, dy
, c
, c_en
`ifdef _DEBUG
, _sum_a0_s2
, _sum_a1_s2
, _sum_b0_s2
, _sum_b1_s2
`endif
);
parameter SHIFT_BITS = 4'd10;
localparam SCALE = 32'd1<<SHIFT_BITS;
input clk, rst_n, a_en;
input [7:0]a0, a1, b0, b1;
input [(SHIFT_BITS-1):0]dx, dy;
output [7:0]c;
output c_en;
`ifdef _DEBUG
output [31:0]_sum_a0_s2;
output [31:0]_sum_a1_s2;
output [31:0]_sum_b0_s2;
output [31:0]_sum_b1_s2;
`endif
//////////////////////////////////////////
//Step 1
reg [7:0]a0_s1, a1_s1, b0_s1, b1_s1;
reg [31:0]_dx_s1, _dy_s1, _1_dx_s1, _1_dy_s1;
reg a_en_s1;
always@(posedge clk or negedge rst_n)
begin
if (!rst_n)
begin
_dx_s1 <= 32'd0;
_dy_s1 <= 32'd0;
_1_dx_s1 <= 32'd0;
_1_dy_s1 <= 32'd0;
a0_s1 <= 8'd0;
a1_s1 <= 8'd0;
b0_s1 <= 8'd0;
b1_s1 <= 8'd0;
a_en_s1 <= 1'd0;
end
else
begin
_dx_s1 <= dx;
_dy_s1 <= dy;
_1_dx_s1 <= SCALE - dx;
_1_dy_s1 <= SCALE - dy;
a0_s1 <= a0;
a1_s1 <= a1;
b0_s1 <= b0;
b1_s1 <= b1;
a_en_s1 <= a_en;
end
end
//////////////////////////////////////////
//Step 2
reg a_en_s2 = 1'd0;
reg [31:0]_dy_s2, _1_dy_s2;
reg [31:0]sum_a0_s2 = 32'd0;
reg [31:0]sum_a1_s2 = 32'd0;
reg [31:0]sum_b0_s2 = 32'd0;
reg [31:0]sum_b1_s2 = 32'd0;
always@(posedge clk or negedge rst_n)
begin
if (!rst_n)
begin
a_en_s2 <= 1'd0;
_dy_s2 <= 32'd0;
_1_dy_s2 <= 32'd0;
sum_a0_s2 <= 32'd0;
sum_a1_s2 <= 32'd0;
sum_b0_s2 <= 32'd0;
sum_b1_s2 <= 32'd0;
end
else
begin
a_en_s2 <= a_en_s1;
_dy_s2 <= _dy_s1;
_1_dy_s2 <= _1_dy_s1;
sum_a0_s2 <= a0_s1*_1_dx_s1;
sum_a1_s2 <= a1_s1*_dx_s1;
sum_b0_s2 <= b0_s1*_1_dx_s1;
sum_b1_s2 <= b1_s1*_dx_s1;
end
end
//////////////////////////////////////////
//Step 3
reg a_en_s3 = 1'd0;
reg [31:0]_dy_s3, _1_dy_s3;
reg [31:0]sum_a_s3 = 32'd0;
reg [31:0]sum_b_s3 = 32'd0;
always@(posedge clk or negedge rst_n)
begin
if (!rst_n)
begin
a_en_s3 <= 1'd0;
_dy_s3 <= 32'd0;
_1_dy_s3 <= 32'd0;
sum_a_s3 <= 32'd0;
sum_b_s3 <= 32'd0;
end
else
begin
a_en_s3 <= a_en_s2;
_dy_s3 <= _dy_s2;
_1_dy_s3 <= _1_dy_s2;
sum_a_s3 <= sum_a0_s2 + sum_a1_s2;
sum_b_s3 <= sum_b0_s2 + sum_b1_s2;
end
end
//////////////////////////////////////////
//Step 4
reg a_en_s4 = 1'd0;
reg [31:0]sum_a_s4 = 32'd0;
reg [31:0]sum_b_s4 = 32'd0;
always@(posedge clk or negedge rst_n)
begin
if (!rst_n)
begin
a_en_s4 <= 1'd0;
sum_a_s4 <= 32'd0;
sum_b_s4 <= 32'd0;
end
else
begin
a_en_s4 <= a_en_s3;
sum_a_s4 <= sum_a_s3[31:(SHIFT_BITS-1)]*_1_dy_s3;
sum_b_s4 <= sum_b_s3[31:(SHIFT_BITS-1)]*_dy_s3;
end
end
//////////////////////////////////////////
//Step 5
reg a_en_s5 = 1'd0;
reg [31:0]sum_s5 = 1'd0;
always@(posedge clk or negedge rst_n)
begin
if (!rst_n)
begin
a_en_s5 <= 1'd0;
sum_s5 <= 1'd0;
end
else
begin
a_en_s5 <= a_en_s4;
sum_s5 <= sum_a_s4 + sum_b_s4;
end
end
assign c = sum_s5[(SHIFT_BITS+8):(SHIFT_BITS+1)];
assign c_en = a_en_s5;
`ifdef _DEBUG
assign _sum_a0_s2 = sum_a0_s2;
assign _sum_a1_s2 = sum_a1_s2;
assign _sum_b0_s2 = sum_b0_s2;
assign _sum_b1_s2 = sum_b1_s2;
`endif
endmodule
----------------------------------------------------------------------------
////////////////TEST BENCH/////////////////////////
////////////////////////////////////////////////////////
`define _DEBUG
`timescale 1 ns/ 1 ns
module sub_pixel_vlg_tst();
parameter SHIFT_BITS = 4'd10;
localparam SCALE = 32'd1<<SHIFT_BITS;
// test vector input registers
reg [7:0] a0;
reg [7:0] a1;
reg a_en;
reg [7:0] b0;
reg [7:0] b1;
reg clk;
reg [9:0] dx;
reg [9:0] dy;
reg rst_n;
// wires
wire [7:0]c;
wire c_en;
`ifdef _DEBUG
wire [31:0]_sum_a0_s2;
wire [31:0]_sum_a1_s2;
wire [31:0]_sum_b0_s2;
wire [31:0]_sum_b1_s2;
`endif
// assign statements (if any)
sub_pixel i1 (
.clk(clk)
, .rst_n(rst_n)
, .a_en(a_en)
, .a0(a0)
, .a1(a1)
, .b0(b0)
, .b1(b1)
, .dx(dx)
, .dy(dy)
, .c(c)
, .c_en(c_en)
`ifdef _DEBUG
, ._sum_a0_s2(_sum_a0_s2)
, ._sum_a1_s2(_sum_a1_s2)
, ._sum_b0_s2(_sum_b0_s2)
, ._sum_b1_s2(_sum_b1_s2)
`endif
);
initial
begin
clk = 0;
forever #5 clk <= ~clk;
end
initial
begin
rst_n <= 0;
a_en <= 0;
#(5 + 100) rst_n <= 1;
@(posedge clk)
begin
a_en <= 1; a0 <= 4; a1 <= 6; b0 <= 8; b1 <= 10; dx <= SCALE/2; dy <= SCALE/2;
end
@(posedge clk)
begin
a_en <= 1; a0 <= 40; a1 <= 60; b0 <= 80; b1 <= 100; dx <= SCALE/2; dy <= SCALE/2;
end
@(posedge clk)
begin
a_en <= 1; a0 <= 40; a1 <= 60; b0 <= 80; b1 <= 100; dx <= SCALE/4; dy <= SCALE/4;
end
@(posedge clk)
begin
a_en <= 1; a0 <= 40; a1 <= 60; b0 <= 80; b1 <= 100; dx <= SCALE/10; dy <= SCALE/10;
end
@(posedge clk)
begin
a_en <= 1; a0 <= 40; a1 <= 60; b0 <= 80; b1 <= 100; dx <= SCALE - SCALE/10; dy <= SCALE - SCALE/10;
end
@(posedge clk)
begin
a_en = 0;
end
#5000 $stop;
end
endmodule
Image Sub-pixel interpolation by Verilog的更多相关文章
- Research Guide for Video Frame Interpolation with Deep Learning
Research Guide for Video Frame Interpolation with Deep Learning This blog is from: https://heartbeat ...
- On-Demand Learning for Deep Image Restoration
摘要 论文来源:ICCV 2017 之前的缺点:目前的机器学习方法只专注于在特定困难程度的图像损坏(如一定程度的噪声或模糊)情况下进行良好的训练模型. 改进的方法:提出了一种基于深度卷积神经网络的按需 ...
- Atitit 图像处理Depixelizing Pixel Art像素风格画的矢量化
Atitit 图像处理Depixelizing Pixel Art像素风格画的矢量化 在去年的时候,偶然看到hqx算法. 一个高质量的插值放大算法. 与双线性插值等插值算法相比,这个算法放大后对人眼 ...
- UnderStand Perspective Rasterization, SV_POSITION(gl_FragCoord) to Pixel, SV mean Systems Value
Shader "UnderStandPRR" { Properties { _MainTex ("Texture", 2D) = "white&quo ...
- verilog 代码分析与仿真
verilog 代码分析与仿真 注意:使用vivado 自带的仿真工具, reg和wire等信号需要赋予初始值 边沿检测 module signal_test( input wire cmos_pcl ...
- 【接口时序】7、VGA接口原理与Verilog实现
一. 软件平台与硬件平台 软件平台: 1.操作系统:Windows-8.1 2.开发套件:ISE14.7 3.仿真工具:ModelSim-10.4-SE 硬件平台: 1. FPGA型号:Xilinx公 ...
- verilog实现中值滤波
前言 项目需要,想要实现算法中的其中一步即中值滤波,同时,因为图像处理部分中值滤波相对来说还是比较简单的,将中值滤波的硬件实现作为进入FPGA领域的第一次尝试.虽然说网上有较多关于中值滤波的文档,可是 ...
- BT.656 NTSC制式彩条生成模块(verilog)
BT.656 NTSC制式彩条生成模块(verilog) 1.知识储备 隔行扫描是将一副图像分成两场扫描,第一场扫描第1,2,5,7...等奇数行,第二场扫描2,4,6,8...等偶数行,并把扫奇数行 ...
- verilog版插值
开发环境:IDE:LIBERO 9.0(ACTEL公司的)芯片:AFS600 (BGA256),是混合系列的FPGA仿真软件:modelsim atcel 6.5d综合软件:synplify pr ...
随机推荐
- WCF基础之消息协定
通常定义消息的架构,使用数据协定就够了,但是有时必须将类型精确映射到soap消息,方法两种:1.插入自定义soap标头:2.另一种是定义消息的头和正文的安全属性.消息协定通过MessageContra ...
- SUBMIT 用法
[转自http://lz357502668.blog.163.com/blog/static/16496743201241195817597/] 1.最普通的用法 *Code used to exec ...
- surf算法解析
surf构造的金字塔图像与sift有很大的不同,sift采用的是DOG图像,surf采用的是hessian矩阵行列式近似值图像,hessian矩阵是surf算法的核心,构建hessian矩阵的目的是为 ...
- Advanced GET 9.1 修正汉化版(免注册、页面加载、保存都正常)
http://www.55188.com/viewthread.php?tid=2846679 Advanced GET 9.1 修正汉化版(免注册.页面加载.保存都正常) 网上流传的很多GET9.1 ...
- deviceToken的获取(二)
第一步:申请证书: 第二步:申请app ids,应用名字必须一致.然后再进入进行编辑,使其enable,绿灯. 第三步:申请provisioning profile,生成.mobileprovisio ...
- HDU - 5703 Desert 【找规律】
题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=5703 题意 给出一杯容量为N的水 每次至少喝1个单位 有多少种不同的方式喝完 比如 给出3 就有4种方 ...
- form memory cache、form disk cache与304
200 from memory cache 不访问服务器,直接读缓存,从内存中读取缓存.此时的数据时缓存到内存中的,当kill进程后,数据将不存在200 from disk cache 不访问服务器, ...
- my.cnf重要配置参数说明
不同存储引擎中关键参数优化 MyISAM存储引擎 MyISAM存储引擎适用于读多写少,对读性能要求比较高的系统 官方文档:http://dev.mysql.com/doc/refman/5.6/en/ ...
- poj3984《迷宫问题》暑假集训-搜索进阶
K - 迷宫问题 Crawling in process... Crawling failed Time Limit:1000MS Memory Limit:65536KB 64bit ...
- SpringCloud之客户端连接Eureka集群
客户端分别yml: ###服务启动端口号 server: port: 8002 ###服务名称(服务注册到eureka名称) spring: application: name: app-toov5- ...