Я бы сам написал это, не уверен, что есть библиотеки.
Я бы рассмотрел каждую точку по очереди, для каждого региона. Тогда (я думаю) это должно сработать:
if (surrounding 8 squares has at least one with different region)
{
for each 3 squares, above, below, left and right
{
if (less than 3 are different, and the middle is different)
{
is a boundry
}
}
for each 3 squares, above, below
{
for each 3 squares, left, right
{
if(all 3 from outer loop and all 3 from inner loop are different)
{
is a boundry
}
}
}
not a boundry
}
else
{
not a boundry
}
Обращайтесь за пределами квадратов как разные.