I have a 2D array of greyscale pixel values that looks like
255 250 250 250 235 251 255 201
255 250 250 250 235 251 255 151
255 250 250 250 235 251 255 151
255 250 250 250 235 251 255 151
255 250 250 250 235 251 255 151
In implementations I have seen online and in other posts, the program will obtain neighboring pixels specifically in an 3x3 window area.
For example,
for (row = 1; row <= numRows; ++row)
{
for (col = 1; col <= numCols; ++col)
{
//neighbor pixel values are stored in window including this pixel
window[0] = imageArr[row - 1][col - 1];
window[1] = imageArr[row - 1][col];
window[2] = imageArr[row - 1][col + 1];
window[3] = imageArr[row][col - 1];
window[4] = imageArr[row][col];
window[5] = imageArr[row][col + 1];
window[6] = imageArr[row + 1][col - 1];
window[7] = imageArr[row + 1][col];
window[8] = imageArr[row + 1][col + 1];
// do something with window
}
}
I am trying to implement a more dynamic window size. Ex. If the user wants to find neighboring pixels in an 4x4 area or an 5x5 area
imageArr. I think you meant to test for< numRows - 1etc. For even-sized windows obviously the center-point of the window is not symmetric so extra care is needed to define your valid operating space. Cleaner solutions might just use one loop andstd::copy_n,memcpyor evenstd::valarray. - paddystd::array<std::array<int,N>,N>from another array given the center row and column. - dougrowandcol. You'll get it, I'm sure. - paddy[0, numRows-N)and[0, numCols-N), and the inner two loops both[0, N). If you need to know the center point of the window, then it'll berow+N/2, col+N/2. And of course ifwindowis a 1D array, indexing that with 2D is stock standard and should probably be burned into your brain when you work with row-based images:window[y * N + x]usually. - paddy