當前位置:編程學習大全網 - 編程語言 - 環境規劃工程

環境規劃工程

我給妳寫個sobel,妳可以把sobel模板改成robert模板。

本來sobel有壹個小算法求閾值,但壹般不要求,所以我用黃金分割乘以255來代替。

索貝爾卷積碼如下:

作廢?CSobelDlg::CreateSobolImage(void)

{

靜電?const?int?sizeOfSobelMask?=?9;

靜電?int?sobelMaskHor[sizeOfSobelMask]?=?

{

-1,?-2,?-1,?

?0,0,0,

?1,2,1

};

靜電?int?索貝爾馬斯克[sizeOfSobelMask]?=?

{

1,?0,?-1,

2,?0,?-2,

1,?0,?1

};

int?numOfBytes?=?m_bmpInfo.bmWidthBytes?*?m _ BMP info . BM height;

未簽名?char*?pbuf1?=?新的?未簽名?char[numOfBytes];

未簽名?char*?pbuf2?=?新的?未簽名?char[numOfBytes];

m_bmpOrg。GetBitmapBits(numOfBytes,pbuf 1);

未簽名?夏爾?averageColor?=?0;

for(int?劃?=?0;?劃?& lt?m _ BMP info . BM height;?++?行)

{

for(int?科爾?=?0;?科爾?& lt?m _ BMP info . BM width;?++列)

{

averageColor?=?(?pbuf1[row?*?m_bmpInfo.bmWidthBytes?+?科爾?*?m_bmpInfo.bmBitsPixel?/?8?+?0]?+

pbuf1[row?*?m_bmpInfo.bmWidthBytes?+?科爾?*?m_bmpInfo.bmBitsPixel?/?8?+?1]?+

pbuf1[row?*?m_bmpInfo.bmWidthBytes?+?科爾?*?m_bmpInfo.bmBitsPixel?/?8?+?2]?)?/?3;

pbuf1[row?*?m_bmpInfo.bmWidthBytes?+?科爾?*?m_bmpInfo.bmBitsPixel?/?8?+?0]?=?平均顏色;

}

}

未簽名?夏爾?ts?=?0,?電視?=?0,?tmp?=?0,?dst?=?0,?idx?=?0;

for(int?劃?=?1;?劃?& lt?m_bmpInfo.bmHeight?-?1;?++?行)

{

for(int?科爾?=?1;?科爾?& lt?m_bmpInfo.bmWidth?-?1;?++列)

{

idx?=?ts?=?電視?=?0;

for(int?r?=?劃?-?1;?r?& lt=?劃?+?1;?++r)

{

for(int?c?=?科爾?-?1;?c?& lt=?科爾?+?1;?++c)

{

tmp?=?pbuf1[r?*?m_bmpInfo.bmWidthBytes?+?c?*?m_bmpInfo.bmBitsPixel?/?8];

ts?+=?(sobelMaskHor[idx]?*?tmp?);

電視?+=?(SobelMaskVer[idx]?*?tmp?);

++ idx;

}

}

dst?=?(未簽名?char)sqrt(?(float)(ts?*?ts?+?電視?*?電視)?);

如果(dst?& gt?(未簽名?char)(0.6180339887?*?255.0)?)?{

pbu F2[排?*?m_bmpInfo.bmWidthBytes?+?科爾?*?m_bmpInfo.bmBitsPixel?/?8?+?0]?=?0;

pbu F2[排?*?m_bmpInfo.bmWidthBytes?+?科爾?*?m_bmpInfo.bmBitsPixel?/?8?+?1]?=?255;

pbu F2[排?*?m_bmpInfo.bmWidthBytes?+?科爾?*?m_bmpInfo.bmBitsPixel?/?8?+?2]?=?0;

pbu F2[排?*?m_bmpInfo.bmWidthBytes?+?科爾?*?m_bmpInfo.bmBitsPixel?/?8?+?3]?=?255;

}

不然呢?{

pbu F2[排?*?m_bmpInfo.bmWidthBytes?+?科爾?*?m_bmpInfo.bmBitsPixel?/?8?+?0]?=?0;

pbu F2[排?*?m_bmpInfo.bmWidthBytes?+?科爾?*?m_bmpInfo.bmBitsPixel?/?8?+?1]?=?0;

pbu F2[排?*?m_bmpInfo.bmWidthBytes?+?科爾?*?m_bmpInfo.bmBitsPixel?/?8?+?2]?=?255;

pbu F2[排?*?m_bmpInfo.bmWidthBytes?+?科爾?*?m_bmpInfo.bmBitsPixel?/?8?+?3]?=?255;

}

}

}

m _ bmpSobol。CreateBitmap(m_bmpInfo.bmWidth,?m_bmpInfo.bmHeight,?1,?32,?pbu F2);

刪除?[]pbuf 1;

刪除?[]pbu F2;

}

我再給妳壹張這個程序的效果圖。

  • 上一篇:首席技術官CTO工作的崗位職責十篇
  • 下一篇:如何畫流程圖
  • copyright 2024編程學習大全網