# Improving the speed of evaluating Table with nested functions

I am a Mathematica novice working with a stack of 1024 x 1024 WatershedComponents (or MorphologicalComponents) label matrices that have resulted from watershedding timelapse microscopy images. I am trying to automatically assign the labels in a previous WatershedComponents mask (from a prior timepoint) to the mask generated from WatershedComponents at the next timepoint.

One approach I have tried is to calculate how much overlap there is for each component in the mask at the current time point with the masks that occupy the same positions in the matrix at the prior timepoint (i.e., this is basically a crude attempt at tracking the cells from time point to time point). To compute the amount of overlap, I am presently using the following functions below to generate a table of how much overlap there is (how many total positions in the two matrices overlap for each label). However, I am finding this is rather slow (takes about 30 to 40 seconds for matrices containing anywhere from 10 to 30 different labels). Is there a faster way to do this without using Table? Are there alternatives to Position or Intersection that might be faster? Would it help to use Compile? I don't know what is possible but achieving a 10-fold or better increase in performance would be more like what I was hoping for. I know best practice in Mathematica is to avoid using Table when possible. Thanks for any suggestions you can provide.

overlapTable =
Table[Length @ Intersection[