In [1]:
import sys
sys.path.insert(0, '../../code/functions/')
import math
from skimage.filters import threshold_otsu
from skimage.measure import label
import numpy as np
import cv2
import plosLib as pLib
import pickle
import scipy.ndimage as ndimage
import time
from scipy import sparse
import matplotlib.pyplot as plt
import mouseVis as mv
import pickle
import matplotlib.pyplot as plt
from tiffIO import loadTiff, unzipChannels
from connectLib import binaryThreshold
import numpy as np
import connectLib as cLib
import plotly
plotly.offline.init_notebook_mode()
import scipy.stats as st



In [8]:
def generateTube(x0, x1, y0, y1, thickness, mat):
    x = np.linspace(x0, x1, int(np.sqrt(np.abs((x1 - x0)**2 + (y1 - y0)**2))))
    y = np.linspace(y0, y1, int(np.sqrt(np.abs((x1 - x0)**2 + (y1 - y0)**2))))
    coords = zip(x, y)
    if y1 == y0: 
        perpSlope = 1000
    elif x1 == x0:
        perpSlope = .001
    else:
        perpSlope = -1.0*(x1 - x0)/(y1 - y0)
    numSamplePoints = thickness/2
    netCoords = []
    for coord in coords:
        xtop = coord[0] + numSamplePoints/np.sqrt(1 + perpSlope*perpSlope)
        xbot = coord[0] - numSamplePoints/np.sqrt(1 + perpSlope*perpSlope)
        ytop = coord[1] + perpSlope*numSamplePoints/np.sqrt(1 + perpSlope*perpSlope)
        ybot = coord[1] - perpSlope*numSamplePoints/np.sqrt(1 + perpSlope*perpSlope)
        xperp = np.linspace(xtop, xbot, int(np.sqrt(np.abs((xtop - xbot)**2 + (ytop - ybot)**2))))
        yperp = np.linspace(ytop, ybot, int(np.sqrt(np.abs((xtop - xbot)**2 + (ytop - ybot)**2))))
        coordsPerp = zip(xperp, yperp)
        finalCoordsPerp = []
        for coordPerp in coordsPerp:
            if coordPerp[0] > 0 and coordPerp[1] > 0 and coordPerp[0] < mat.shape[0] - 1 and coordPerp[1] < mat.shape[1] - 1:
                finalCoordsPerp.append(((int(math.floor(coordPerp[1]))), (int(math.floor(coordPerp[0])))))
        netCoords.append(finalCoordsPerp)
    return netCoords


mat = np.zeros((401,401))
#this is just for viewing purposes
x0 = 0
x1 = 200
y0 = 200
y1 = 200
netCoords = generateTube(x0, x1, y0, y1, 80, mat)
#finalCoordsPerp is what Brandon wants
for viewCoord in netCoords:
    for subCoord in viewCoord:
        mat[subCoord[0]][subCoord[1]] = 2
x = np.linspace(x0, x1, int(np.sqrt(np.abs((x1 - x0)**2 + (y1 - y0)**2))))
y = np.linspace(y0, y1, int(np.sqrt(np.abs((x1 - x0)**2 + (y1 - y0)**2))))
coords = zip(x, y)
for coord in coords:
     mat[coord[1]][coord[0]] = 1
plt.imshow(mat)
plt.show()


/usr/local/lib/python2.7/site-packages/ipykernel/__main__.py:44: VisibleDeprecationWarning:

using a non-integer number instead of an integer will result in an error in the future


In [ ]:


In [ ]: