Converting region of interest (ROI) polygon to a mask

I tried this way:


using Images
using GeometricalPredicates

pts = [(1.0, 1.0), (10.0, 50.0), (100.0, 25.0)]
adj = 256
randompoints = [Point(p[1] + adj, p[2] + adj) for p in pts]

w = 512
h = 512
buffer = zeros(Int, w, h)
poly = Polygon(randompoints...)
[if inpolygon(poly, Point(x, y)) buffer[x, y] = 1 end for x in collect(1:1:w), y in collect(1:1:h)];

then doing

Gray.(buffer)

should come up with a triangle.

4 Likes