Hi Experts,

I would like to build the following sum (gradient calculation) of a 8 bit monochromatic image (bitmap) with a resolution of 640x480 in an effective way:

j=rows-1 i=cols-1

Sum Sum ((A[i][j]-A[i+1][j])*(A[i]

[j]-A[i+1][j]))+((A[i][j]-A[i][j+1])*(A[i][j]-A[i][j+1]))

j=0 i=0

where the first sum runs from j=0 to j=number of rows and the second sum from i=0 to i= number of columns and A[i][j] ist the pixel intensity at the position (i,j). I've created a mfc dialog and here is coding:

void CImageAppDlg::OnBnClickedButton()

{

HBITMAP hBmp= (HBITMAP)LoadImage(NULL,L"C:\\Notebook.bmp", IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);

// m_MyBmp ist der member variable associated to the picture control

m_MyBmp.SetBitmap( hBmp );

CBitmap* pcBmp= CBitmap::FromHandle( hBmp );

BITMAP rBmp;

int n= pcBmp->GetBitmap( &rBmp );

const int nWide= rBmp.bmWidth;

const int nHigh= rBmp.bmHeight;

BYTE abPixels[640][480];

CDC* pCDC= m_MyBmp.GetWindowDC();

int x,y;

int Summe;

Summe=0;

for ( y=0; y<(nHigh-1); y++ ){

for ( x=0; x<(nWide-1); x++ ){

COLORREF clrRGB= pCDC->GetPixel(x,y);

abPixels[x][y]= GetRValue( clrRGB );

Summe+=((abPixels[x][y]-abPixels[x+1][y])*(abPixels[x][y]-abPixels[x+1][y]))+

((abPixels[x][y]-abPixels[x][y+1])*(abPixels[x][y]-abPixels[x][y+1]));

}

}

CString s;

s.Format( L"Summe=%d", Summe );

MessageBox( s );

}

I tested the coding above with the attached file below and I'm not sure if the implementation is correct...

Thank you

Notebook.bmp