一. Sobel简介
一句话可以概况为,分别求水平与竖直梯度,然后求平方和再开方(近似的话就直接求绝对值之和),最后与设定的阈值进行比较,大于的话就赋值为0,小于的话就赋值为255。
x方向梯度dx的求法:3*3的图像矩阵与下面的矩阵在对应位置相乘然后相加
y方向梯度dy的求法:同上
二. 代码实现
0] Sobel_px ,Sobel_nx; :
0] Sobel_py ,Sobel_ny; :
0] Sobel_x; :
0] Sobel_y; :
0] Sobel_data; :
//x方向的梯度
assign Sobel_x = (Sobel_px > Sobel_nx) ? (Sobel_px - Sobel_nx) : (Sobel_nx - Sobel_px);
//y方向的梯度
assign Sobel_y = (Sobel_py > Sobel_ny) ? (Sobel_py - Sobel_ny) : (Sobel_ny - Sobel_py);
(Sobel_x + Sobel_y > 'd135) ? 'd0 : 'd255; =
clk_9M or negedge rst)
begin
= 1'b0) =
begin
Sobel_px <= 'd0;
Sobel_nx <= 'd0;
end
else if(cur_x >= 'd100 && cur_x <= 'd199 && cur_y >= 'd50)
begin
Sobel_nx <= data_line_11 + data_line_21 + data_line_21 + data_line_31;
Sobel_px <= data_line_13 + data_line_23 + data_line_23 + data_line_33;
end
else
begin
Sobel_nx <= 'd0;
Sobel_px <= 'd0;
end
end
clk_9M or negedge rst)
begin
= 1'b0) =
begin
Sobel_py <= 'd0;
Sobel_ny <= 'd0;
end
else if(cur_x >= 'd100 && cur_x <= 'd199 && cur_y >= 'd50)
begin
Sobel_py <= data_line_11 + data_line_12 + data_line_12 + data_line_13;
Sobel_ny <= data_line_31 + data_line_32 + data_line_32+ data_line_33;
end
else
begin
Sobel_ny <= 'd0;
Sobel_py <= 'd0;
end
end
审核编辑:汤梓红
全部0条评论
快来发表一下你的评论吧 !