def test_fill_line(): # This is a regression test # https://github.com/luispedro/mahotas/issues/3 canvas = np.zeros((50, 30)) poly = [(0, 10), (10, 0), (40, 20), (0, 10)] fill_polygon(poly, canvas) assert np.all(canvas[10, 1:10])
def test_polygon(): polygon = [(10,10), (10,20), (20,20)] canvas = np.zeros((40,40), np.bool) fill_polygon(polygon, canvas) assert canvas.sum() == (10*10+10)/2 canvas2 = canvas.copy() fill_polygon([], canvas2) assert np.all(canvas == canvas2)
def test_fill_line(): # This is a regression test # https://github.com/luispedro/mahotas/issues/3 canvas = np.zeros((50,30)) poly = [( 0,10), (10, 0), (40,20), ( 0,10)] fill_polygon(poly, canvas) assert np.all(canvas[10,1:10])
def ac_mask(acontour, framesize): mask = npy.zeros(framesize, dtype = npy.uint8) new_acontour = npy.zeros([2, 5 * acontour.shape[1] - 4], dtype = npy.float32) s = acontour.shape[1] cnt = npy.arange(0, s) * 5 spline = [0, 0] for i in range(2): spline[i] = itp.InterpolatedUnivariateSpline(cnt, acontour[i, :]) for j in range(new_acontour.shape[1]): if j % 5 == 0: new_acontour[:, j] = acontour[:, j / 5] else: for i in range(2): new_acontour[i, j] = spline[i](j) #print new_acontour for i in range(2): for j in range(new_acontour.shape[1]): new_acontour[i, j] = npy.max([new_acontour[i, j], 0]) new_acontour[i, j] = npy.min([new_acontour[i, j], framesize[i] - 1]) fill_polygon([(int(x[0] + 0.5), int(x[1] + 0.5)) for x in new_acontour.transpose()], mask) return mask
def ac_mask(acontour, framesize): mask = npy.zeros(framesize, dtype=npy.uint8) new_acontour = npy.zeros([2, 5 * acontour.shape[1] - 4], dtype=npy.float32) s = acontour.shape[1] cnt = npy.arange(0, s) * 5 spline = [0, 0] for i in range(2): spline[i] = itp.InterpolatedUnivariateSpline(cnt, acontour[i, :]) for j in range(new_acontour.shape[1]): if j % 5 == 0: new_acontour[:, j] = acontour[:, j / 5] else: for i in range(2): new_acontour[i, j] = spline[i](j) #print new_acontour for i in range(2): for j in range(new_acontour.shape[1]): new_acontour[i, j] = npy.max([new_acontour[i, j], 0]) new_acontour[i, j] = npy.min([new_acontour[i, j], framesize[i] - 1]) fill_polygon([(int(x[0] + 0.5), int(x[1] + 0.5)) for x in new_acontour.transpose()], mask) return mask
def test_border(): canvas = np.zeros((32,32)) polygon = np.array([(0,0),(0,32),(32,0)]) fill_polygon(polygon, canvas) assert not np.all(canvas)
def coords_to_fill_mask(xy, shape): canvas = np.zeros(shape) polygon.fill_polygon(xy, canvas) # modifies canvas in-place! return canvas
from skimage.measure import find_contours contours = find_contours(mole_edge, 0.9, fully_connected='high') mole.status = 85 db.session.merge(mole) db.session.commit() # In[64]: from mahotas.polygon import fill_polygon from skimage.transform import resize canvas = np.zeros((gray.shape[0], gray.shape[1])) fill_polygon(contours[0].astype(np.int), canvas) mole.status = 95 db.session.merge(mole) db.session.commit() # In[78]: import numpy.ma as ma from skimage.color import rgb2hsv hsv = rgb2hsv(small) deviations = [] for color in (0, 1, 2):
def test_polygon(): polygon = [(10,10), (10,19), (19,19)] canvas = np.zeros((40,40), np.bool) fill_polygon(polygon, canvas) assert canvas.sum() == (10*10+10)/2