luispedro / mahotas

Computer Vision in Python
https://mahotas.rtfd.io
Other
844 stars 148 forks source link

`mahotas.polygon.fill_polygon` skips rows of pixels at all vertices on the left hand side of a polygon #3

Closed joferkington closed 13 years ago

joferkington commented 13 years ago

As a simple example to reproduce the problem:

import numpy as np
import matplotlib.pyplot as plt
import mahotas.polygon

canvas = np.zeros((100,100))
poly = [(20,10), (35, 0), (60,20), (65, 25), (70,50), (40,60), (30,40), (20,10)]
mahotas.polygon.fill_polygon(poly, canvas)

plt.imshow(canvas, interpolation='nearest')
plt.show()

Fortunately the fix is quite simple. I'm at work and don't have git available, otherwise I'd submit a pull request, but it appears to be a single-line fix.

On line 105 of mahotas/polygon.py: The line if p[0] <= y and pj[0] >= y or pj[0] <= y and p[0] >= y: Should be: if p[0] < y and pj[0] >= y or pj[0] < y and p[0] >= y:

Cheers, and thanks for a very useful piece of software!

luispedro commented 13 years ago

Thank you.

Unfortunately, it seems to introduce another issue. It breaks test_convex3(). It also breaks test_polygon(), but I think it is actually test_polygon() which needs to be improved.

This needs to be fixed, though. I'm working on it.

luispedro commented 13 years ago

Just incorporated this fix into master with a hackish solution for the convex hull issue.

Thank you again!