The easy set can easily be solved by hand. For the hard set it is probably faster to convert the input into a text-based format such as PNM (ImageMagick may come in handy), flood fill the polygons, and then compare each pair.