Python, 2.62 * 10^40
This algorithm just floodfills (BFS) the plane starting from the black parts of the image, where for each new pixel we record what black part it was flooded from. As soon as we have two neighbouring pixels with different black parts as ancestors, we basically merge these two black parts by joining them through the ancestors of the two ...
C, score 2.397x10^38
Man this took way too long to do, most likely due to my choice of language. I got the algorithm working fairly early, but ran into a lot of problems with memory allocation (couldn't recursively free stuff due to stack overflows, leak sizes were huge).
Still! It beats the other entry on every test case, and might even be optimal gets ...
Python 3: 1.7x10^42 1.5x10^41
Using Pillow, numpy and scipy.
Images are assumed to be in an images folder located in the same directory as the script.
Disclaimer: It takes a long time to process all the images.
from PIL import Image
import numpy as np
def obtain_groups(image, threshold, structuring_el):