原创 【数字IC】高级数字 IC 设计(10)Sobel 设计

2023-3-18 21:54 525 5 5 分类: FPGA/CPLD 文集: 数字IC

Sobel算法是做图像的必备技能,其设计流程如下:

mif文件的制作→ 调用ip核生成rom以及仿真注意问题→ 灰度处理→ 均值滤波:重点是3*3 像素阵列的生成→ sobel边缘检测→ 图片的显示→ 结果展示 。

在技术上,Sobel算法是一离散性差分算子,用来运算图像亮度函数的灰度之近似值。在图像的任何一点使用此算子,将会产生对应的灰度矢量或是其法矢量。

 

  1. module Sobel(</p>
  2. clk_i,
  3. rst_n,
  4. iStart,
  5. iData,
  6. oData,
  7. data121,
  8. oStart
  9. );
  10. input clk_i;
  11. input rst_n;
  12. input [7:0] iData;
  13. input iStart;
  14. output [7:0] oData;
  15. output oStart;
  16. output [9:0] data121;
  17. //=======================================================
  18. //reg & wire
  19. //=======================================================
  20. reg [7:0] oData;
  21. wire oStart;
  22. //for Row buffer
  23. wire [7:0] Data_Row0,Data_Row1,Data_Row2;
  24. //for data121
  25. wire [9:0] data121;
  26. reg [9:0] DataV0,DataV1,DataV2;
  27. assign Data_Row0 = iData;
  28. //for odata
  29. wire [9:0] DataSub,Subina,Subinb;
  30. //for ostart delay
  31. reg [2:0] Start_delay;
  32. //=======================================================
  33. //row buffer
  34. //=======================================================
  35. Row_Buffer Row_Buffer (
  36. .clock(clk_i),
  37. .shiftin(iData),
  38. .taps9x(Data_Row2),
  39. .taps4x(Data_Row1)
  40. );
  41. //=======================================================
  42. //data121
  43. //=======================================================
  44. assign data121 = {2'd0,Data_Row0} + {1'b0,Data_Row1,1'b0}
  45. + {2'd0,Data_Row2};
  46. always @ (posedge clk_i or negedge rst_n)begin
  47. if(!rst_n)begin
  48. DataV0 <= 10'd0;
  49. DataV1 <= 10'd0;
  50. DataV2 <= 10'd0;
  51. end
  52. else begin
  53. DataV0 <= data121;
  54. DataV1 <= DataV0 ;
  55. DataV2 <= DataV1 ;
  56. end
  57. end
  58. //=======================================================
  59. //oData
  60. //=======================================================
  61. assign Subina = (DataV0 > DataV2) ? DataV0 : DataV2;
  62. assign Subinb = (DataV0 > DataV2) ? DataV2 : DataV0;
  63. assign DataSub = Subina - Subinb;
  64. always @ (posedge clk_i or negedge rst_n)begin
  65. if(!rst_n)begin
  66. oData <= 8'd0;
  67. end
  68. else begin
  69. if(DataSub[9:8] == 2'd0)
  70. oData <= DataSub[7:0];
  71. else
  72. oData <= 8'hff;
  73. end
  74. end
  75. //=======================================================
  76. //oStart whole delay will be 3
  77. //=======================================================
  78. always @ (posedge clk_i or negedge rst_n)begin
  79. if(!rst_n)begin
  80. Start_delay <= 3'd0 ;
  81. end
  82. else begin
  83. Start_delay[0] <= iStart;
  84. Start_delay[1] <= Start_delay[0];
  85. Start_delay[2] <= Start_delay[1];
  86. end
  87. end
  88. assign oStart = Start_delay[2];
  89. reg [9:0]Hcount;
  90. reg [8:0]Vcount;
  91. always @ (posedge clk_i or negedge rst_n)begin
  92. if(!rst_n)begin
  93. Hcount <= 10'd0;
  94. Vcount <= 9'd0;
  95. end
  96. else begin
  97. if(oStart)begin
  98. if(Hcount == 10'd639 && Vcount == 9'd479)begin
  99. Hcount <= 10'd0;
  100. Vcount <= 9'd0;
  101. end
  102. else if(Hcount == 10'd639)begin
  103. Hcount <= 10'd0;
  104. Vcount <= Vcount + 1'b1;
  105. end
  106. else begin
  107. Hcount <= Hcount + 1'b1;
  108. end
  109. end
  110. else begin
  111. Hcount <= 10'd0;
  112. Vcount <= 9'd0;
  113. end
  114. end
  115. end
  116. endmodule


PARTNER CONTENT

文章评论0条评论)

登录后参与讨论
EE直播间
更多
我要评论
0
5
关闭 站长推荐上一条 /3 下一条