以下の例は、8近傍で境界があった場合自身の画素値を1、それ以外で0にする例です。
void Edge() { LONG i, j; m_wEdge = new WORD[m_row*m_col]; //出力画像 for ( i = 1; i < m_row - 1; i++ ) { for ( j = 1; j < m_col - 1; j++ ) { m_wEdge[i*m_row + j] = m_wRecons[i*m_row + j]; //現在のピクセルが白のとき、この例では白側に境界線を作る if ( m_wEdge[i*m_row + j] ) { //8近傍で黒がなければ黒 m_wEdge[i*m_row + j] = 0; if ( !m_wRecons[(i-1)*m_row + (j-1)] ) m_wEdge[i*m_row + j] = (WORD)65533; if ( !m_wRecons[(i-1)*m_row + (j )] ) m_wEdge[i*m_row + j] = (WORD)65533; if ( !m_wRecons[(i-1)*m_row + (j+1)] ) m_wEdge[i*m_row + j] = (WORD)65533; if ( !m_wRecons[(i )*m_row + (j-1)] ) m_wEdge[i*m_row + j] = (WORD)65533; if ( !m_wRecons[(i )*m_row + (j+1)] ) m_wEdge[i*m_row + j] = (WORD)65533; if ( !m_wRecons[(i+1)*m_row + (j-1)] ) m_wEdge[i*m_row + j] = (WORD)65533; if ( !m_wRecons[(i+1)*m_row + (j )] ) m_wEdge[i*m_row + j] = (WORD)65533; if ( !m_wRecons[(i+1)*m_row + (j+1)] ) m_wEdge[i*m_row + j] = (WORD)65533; } } } }