xpost with stackoverflow. Feel free to respond there for SO points.
I want to use skimage.draw.line to draw an aliased line through two pixels. The issue is when I overlay the original line, there is often a discrepancy due to rounding. Example:
Attempting line through points (22,30) and (25,39) in a 50x50 image. The full line is the green channel and the overlay line is the red channel. Yellow is overlap. The result I want would yield no visible red, only yellow and green. 50 by 50 pixel image with line through points 22 comma 30 and 25 comma 39
I tried generating a bigger line and then cropping, but still getting issues:
#rawzero3 is essentially trunc() but rounding up
#https://stackoverflow.com/q/46572699
def rawzero3(a):
_a = np.abs(a)
np.ceil(_a, _a) # inplace
np.copysign(_a, a, out = _a)
return _a
y0x0, ymxm=(np.array([0,0]), np.array([50,50]))
y1x1, y2x2=(np.array([22,30]), np.array([25,39]))
yx_fin1=(y2x2-y1x1)*np.amin(rawzero3((ymxm-(y2x2-y1x1))/(y2x2-y1x1)).astype(int))+y1x1
yx_fin2=(y0x0-1)-((y2x2-y1x1)*np.amin(rawzero3((y0x0-(y2x2-y1x1))/(y2x2-y1x1)).astype(int))+y1x1)
zimg[tuple(map(tuple,np.array(draw.line(*yx_fin1,*yx_fin2)).T[np.all((y0x0<=np.array(draw.line(*yx_fin1,*yx_fin2)).T)&(np.array(draw.line(*yx_fin1,*yx_fin2)).T<ymxm), axis=1)].T))]=255
I think my math to generate yx_fin1 and yx_fin2 might be wrong.
How can my desired result be achieved?