Very interesting! Did you notice that in the two failing cases, all of the pixels on the right and bottom edges are incorrect?
So, that says there's something wrong with the code that handles those two edges.
Now, look at the relevant code for the lower right pixel. Remember that an array declared as array has valid elements from 0 to 9, not 10.