I’ve got some code that takes repeated local neighbourhoods from a large array. I can set the code to give me 3×3 neighbourhoods, or any other sized neighbourhoods such as 5×5 or 11×11. I then need to check various things about the array, as detailed below. I’ve started writing it with loads of nested if statements, but thought there must be a better way!
0 1 2 3 4
--------------
0 |1 2 3 4 5
1 |6 7 8 9 10
2 |11 12 13 14 15
3 |16 17 18 19 20
4 |21 22 23 24 25
Given the array above I want to check if the values in [0, 2] and [1, 2] are less than a threshold, and the values in [3, 2] and [4, 2] are greater than the threshold. I then want to do the same thing with a vertical line through the centre (rather than the horizontal line in the example I gave), and the same for both diagonals.
At the moment I can’t see any way to do this without loads of if statements which will get very confusing and difficult to maintain very quickly. I’m sure there must be a better way to do it – any ideas?
You can use an array of function pointers to specify what needs to be checked for each square.
If you need different sizes, just make a different
check_functionsarray for each size.