Slow array access during labeling algorithm

I think you might get more and better answers if you provide a complete, runnable MWE as described in item 4 of this post.