Mathematical tool to bound a pixel set using the closed quadrilateral?

33 Views Asked by At

I am currently working on automatically mesh generating. Now I encountered this problem:

enter image description here

Some algorithm outputs a pixel set, shown by red color in the above image. The pixel set may be a little noisy, but basically it look like a irregular quadrilateral. I want to draw a minimum quadrilateral to bound most pixels of this set, as is shown in the right part of the image.

The long straight line in the image is some existing edge in the mesh, it shall overlap with one the edges of the quadrilateral.

So, anyone can give any suggestion to locate this quadrilateral reasonably?