图像锐化
god81 2008-12-17 06:38:32 拉普拉斯锐化,但是效果不对,请教各位大虾,谢谢!
void CBmpShowView::OnLaplaciansharp()
{
// TODO: Add your command handler code here
CBmpShowDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
ImgWidth = pDoc->nImgWidth;
ImgHeight = pDoc->nImgHeight;
LPBYTE lpDIBHdr;
LPBYTE lpDIBBits;
int i,j;
HPALETTE hOldPal = NULL;
HANDLE hDIB;
hDIB = pDoc->m_hDIB;
if(!hDIB)
return;
lpDIBHdr = (LPBYTE)GlobalLock(hDIB);
lpDIBBits = lpDIBHdr+sizeof(BITMAPINFOHEADER)+DIBNumColors(lpDIBHdr)*sizeof(RGBQUAD);
for(i = 1; i < ImgHeight; i++)
{
// 每列
for(j = 2; j < ImgWidth; j++)
{ int lap[300];
int a,b;
a=*(lpDIBBits+i*ImgWidth+j+1)+*(lpDIBBits+i*ImgWidth+j-1);
b=*(lpDIBBits+(i+1)*ImgWidth+j)+*(lpDIBBits+(i-1)*ImgWidth+j);
lap[i,j]=5*(*(lpDIBBits+i*ImgWidth+j))-(a+b);
*(lpDIBBits+i*ImgWidth+j)=lap[i,j];
//判断是否越界//
if ((*(lpDIBBits+i*ImgWidth+j)) < 0)
{
// 直接赋值为0
*(lpDIBBits+i*ImgWidth+j) = 0;
}
else if (*(lpDIBBits+i*ImgWidth+j) > 255)
{
// 直接赋值为255
*(lpDIBBits+i*ImgWidth+j) = 255;
}
}
}
pDoc->UpdateAllViews(NULL);
}