# Efficiently determining if a morphological component overlaps a polygon with vertices at real number coordinates

I have a list of morphological components $m$, a set of vertices for a polytope $P$ (at real number coordinates), and I'd like to be able to calculate a list of morphological components $m'$ that anywhere overlap the area of $P$. I can do this by approximating each pixel as a point, and calculating a winding number for these points with respect to $P$ to determine if they fall within the polygon's area. However, this is hardly an efficient strategy, and it's not as exact as I would like. My hope is to have a scheme to detect if the polygon crosses any square bright pixel region. Is there a clever way to do this that works very quickly?

I suspect the quickest approach will be to rasterize the polygon. For example

Create an example component matrix:

m = MorphologicalComponents[ColorNegate@
Rasterize[Graphics[Disk /@ RandomReal[{0, 20}, {40, 2}]], ImageSize -> {300, 300}]];

m // Colorize


Define the polygon and rasterize it:

poly = Polygon[{{50, 50}, {50, 250}, {200, 200}}];
polyimage = Binarize @ Graphics[poly, PlotRange -> {{0, 300}, {0, 300}}, ImageSize -> 300]


Identify values in m which overlap with zeros in polyimage (excluding the background component)

overlaps = Complement[Flatten @ Pick[m, ImageData[polyimage], 0], {0}]
(* {6, 7, 9, 13, 15, 19} *)


Check that the identified components do indeed overlap the polygon:

ImageCompose[
SelectComponents[m, "Label", MemberQ[overlaps, #] &] // Colorize, {polyimage, 0.3}]