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 ...
随机推荐
- iOS启动页加载广告
1.定义全局成员变量 @interface AppDelegate () @property (strong, nonatomic) UIImageView *adImageView; @proper ...
- 【python】-- paramiko、跳板机(堡垒机)
paramiko Python的paramiko模块,该模块用于连接远程服务器并执行相关命令,常用于作批量管理使用 一.下载: pip3 install paramiko 源码:查看 二.parami ...
- 《编程导论(Java)·1.1.2 颠倒的世界(柏拉图法则)》
假设你读<编程导论(Java)·1.1.2 颠倒的世界(柏拉图法则)>感到无趣,请尝试评价这个段子. 3. Classes Classes drive me crazy. That mig ...
- ubuntu编译内核模块报错:Required key not available 的解决
系统为ubuntu18.04, 在编译内核模块insmod helloworld.ko的时候提示如下错误. 出现此问题的原因是,Ubuntu Kernel 使用 EFI_SECURE_BOOT_SIG ...
- php生成随机密码的自定义函数
php生成随机密码的自定义函数 生成一个随机密码的函数,生成的密码为小写字母与数字的随机字符串,长度可自定义. 复制代码代码如下: <?php /* * php自动生成新密码自定义函数(带实例 ...
- iOS uitableViewCell 选中 push后返回 取消选中状态
首先我有一个UITableViewController,其中每个UITableViewCell点击后都会push另一个 ViewController,每次点击Cell的时候,Cell都会被选中,当从p ...
- js之定时器
一.通过定时器我们可以间隔设定时间重复调用某个函数,利用这个特性,我们可以做很多事,例如,12306上的每间隔5秒查询自动查询一次余票,简单动画的实现等等 二.定时器的格式: 定时器有两种格式,分别是 ...
- 【leetcode刷题笔记】Reverse Integer
Reverse digits of an integer. Example1: x = 123, return 321Example2: x = -123, return -321 解题:设定一个变量 ...
- STM32大文件分块校验CRC
一.CRC校验的使用 STM32内置CRC计算单元,节约了软件计算的时间.在软件开发中,可以为firm追加4字节的CRC校验码到生成的BIN文件最后位置,这个CRC码就是全部代码区域数据的CRC ...
- keep-alive使用笔记
vue2.0提供了keep-alive组件,用来缓存组件,避免多次加载,减少性能消耗. 1.将整个网页缓存起来 <router-view class="view" keep- ...