灰階映像的sobel邊緣檢測演算法

來源:互聯網
上載者:User

標籤:src   移位   sys   set   變數聲明   映像   eset   簡單的   data   

之前上一篇文章寫了如何將圖片進行灰階化處理,這篇文章參考CB的文章簡單的介紹一下如何進行sobel邊緣化處理。

邊緣 : 周圍像素灰階急劇變化的那些像素的集合,它是映像最基本的特徵

公式 : 

    

這裡Gx和Gy分別代表橫向及縱向邊緣檢測的映像灰階值,該點灰階值大小為G,式子裡A代表經過灰階

處理的原始映像,最終計算出來的結果和設定的閾值進行比較如果大於閾值顯示一個顏色,否則就顯示其他

顏色即可。

 

 

 

採用流水線的方法:

  1、移位,A是一個3X3的矩陣,需要不斷的重新整理,我用的是9個寄存器,每一個時鐘就重新整理一次。

  2、計算Gx 和Gy,矩陣相乘展開以後就是幾個資料相乘,因為矩陣因子裡面有負數,所以需要

          比較大小,把正值給保留下來。

  3、求平方和

  4、利用altera內建的IP核,實現開根號處理。

  5、跟閾值進行比較

/*-----------------------------------------------------------------------Date                :        2017-XX-XXDescription            :        Design for .-----------------------------------------------------------------------*/module sobel(    //global clock    input                    clk,            //system clock    input                    rst_n,             //sync reset        //gray interface    input            [7:0]    gray,        //sobel    interface    output            [10:0]    sobel_data    ); //--------------------------------//Funtion :  變數聲明reg            [7:0]        matrix_p11 , matrix_p12 , matrix_p13;reg            [7:0]        matrix_p21 , matrix_p22 , matrix_p23;reg            [7:0]        matrix_p31 , matrix_p32 , matrix_p33;reg            [9:0]        gx_temp1;reg            [9:0]        gx_temp2;reg            [9:0]        gx_data;reg            [9:0]        gy_temp1;reg            [9:0]        gy_temp2;reg            [9:0]        gy_data;             reg            [20:0]        gxy_square;//--------------------------------//Funtion :  移位always @(posedge clk or negedge rst_n)begin    if(!rst_n)    begin        matrix_p11 <= 1‘d0;        matrix_p12 <= 1‘d0;        matrix_p13 <= 1‘d0;        matrix_p21 <= 1‘d0;        matrix_p22 <= 1‘d0;        matrix_p23 <= 1‘d0;        matrix_p31 <= 1‘d0;        matrix_p32 <= 1‘d0;        matrix_p33 <= 1‘d0;            end    else    begin        matrix_p11 <= gray;        matrix_p12 <= matrix_p11;        matrix_p13 <= matrix_p12;        matrix_p21 <= matrix_p13;        matrix_p22 <= matrix_p21;        matrix_p23 <= matrix_p22;        matrix_p31 <= matrix_p23;        matrix_p32 <= matrix_p31;        matrix_p33 <= matrix_p32;        endend//--------------------------------//Funtion :  計算Gx Gyalways @(posedge clk or negedge rst_n)begin    if(!rst_n)    begin        gx_temp1 <= 1‘d0;        gx_temp2 <= 1‘d0;        gx_data     <= 1‘d0;    end    else    begin        gx_temp1 <= matrix_p31 + (matrix_p32 << 1) + matrix_p33;        gx_temp2 <= matrix_p11 + (matrix_p12 << 1) + matrix_p13;        gx_data  <= (gx_temp1 >= gx_temp2) ? gx_temp1 - gx_temp2 : gx_temp2 - gx_temp1;    endendalways @(posedge clk or negedge rst_n)begin    if(!rst_n)    begin        gy_temp1 <= 1‘d0;        gy_temp2 <= 1‘d0;        gy_data     <= 1‘d0;    end    else    begin        gy_temp1 <= matrix_p11 + (matrix_p21 << 1) + matrix_p31;        gy_temp2 <= matrix_p13 + (matrix_p23 << 1) + matrix_p33;        gy_data  <= (gy_temp1 >= gy_temp2) ? gy_temp1 - gy_temp2 : gy_temp2 - gy_temp1;    endend//--------------------------------//Funtion :  gx^2 + gy^2always @(posedge clk or negedge rst_n)begin    if(!rst_n)        gxy_square <= 1‘d0;    else        gxy_square <= gx_data * gx_data + gy_data * gy_data;end//--------------------------------//Funtion :  sqrtsqrt_sobel sqrt_inst(    .radical(gxy_square),    .q(sobel_data),    //remainder    );endmodule    

 

 

 

 

灰階映像的sobel邊緣檢測演算法

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.