As a note for those who stumble on this thread in the future:
I recommend using the ImplicitBVH.jl package to accelerate the generation of a small set of actual intersection tests.
Even using a BSphere{T} for each segment of each contour for two input (512,512) random fields (i.e., overestimating the intersection density significantly in an already extreme test case), determining the potentially intersecting elements is eminently tractable. In an example, this approach reduces the number of intersection tests to be performed from 261587 * 260824 = 68228167688 to 2022690 in under 365.776 ms (with ~80% GC time).
Even then sweeping the initial segments (since the BSphere loses information about the segment points) is fast enough. I’ve updated the gist again, and attach a Haring-esque (128,128) example (intersections in green):
