def plotTrack(crossSections,centerPoints):
	fig = plt.figure()
	ax = fig.add_subplot(111, projection='3d')
	for index in range(len(xArr1)):
		zArr1.append(EdgeFinder.getHeight(xArr1[index],yArr1[index],centerPoints)*HEIGHT_SCALE)
		zArr2.append(EdgeFinder.getHeight(xArr2[index],yArr2[index],centerPoints)*HEIGHT_SCALE)	
	t = np.linspace(0, 1, len(zArr1))
	t2 = np.linspace(0, 1, len(zArr1))

	x12 = np.interp(t2, t, xArr1)
	y12 = np.interp(t2, t, yArr1)
	z12 = np.interp(t2, t, zArr1)
	x22 = np.interp(t2, t, xArr2)
	y22 = np.interp(t2, t, yArr2)
	z22 = np.interp(t2, t, zArr2)
	sigma = 2
	x13 = gaussian_filter1d(x12, sigma)
	y13 = gaussian_filter1d(y12, sigma)
	z13 = gaussian_filter1d(z12, sigma)
	x23 = gaussian_filter1d(x22, sigma)
	y23 = gaussian_filter1d(y22, sigma)
	z23 = gaussian_filter1d(z22, sigma)
	ax.plot(z13,y13,x13,color = 'b')
	ax.plot(z23,y23,x23,color = 'b')
	plt.show()
Exemple #2
0
    def re_annotate(self, from_edges=False, window=FULL_EXTEND):
        """create a position specific scoring matrix for the surrounding regions,
        see how far you can go while keeping conservation, using a maximum
        likelihood method. Can either annotate from feature (by default) or
        from edges"""
        if len(self.lst) < 2:
            return

        # unzip
        if from_edges:
            [befores, afters] = zip(*[e.around_IS(window) for e in self.lst])
        else:
            [befores, afters] = zip(*[e.around_gene(window) for e in self.lst])

        # make them the same length
        minlength_before = min([len(b) for b in befores])
        minlength_after = min([len(a) for a in afters])

        befores = [b[:minlength_before] for b in befores]
        afters = [a[:minlength_after] for a in afters]

        verbose = False
        individual = True

        before_lens = EdgeFinder.find_left_edges([str(s) for s in befores],
                                                    individual, verbose)
        after_lens = EdgeFinder.find_left_edges([str(s) for s in afters],
                                                    individual, verbose)

        for e, before_len, after_len in zip(self.lst, before_lens, after_lens):
            if from_edges:
                start = e.start
                end = e.end
            else:
                start = e.feature.location._start.position
                end = e.feature.location._end.position

            if e.direction == 1:
                newstart = start - before_len
                newend = end + after_len
            else:
                newstart = start - after_len
                newend = end + before_len

            e.change(newstart=newstart, newend=newend)
 def isEdge(self,row,col):
     edge = ef.isedge(row, col, self.pixels, [self.numRows, self.numCols])
     edge = edge==1        
     if edge == 1:
         print 'edge'
         self.paintEdge(row, col)
         return True
     else:
         return False
 def firstEdge(self, row):
     print 'start'
     col = ef.firstedge(row, self.pixels, [self.numRows, self.numCols])
     print 'edge'        
     print col
     self.origRow = row
     self.origCol = col
     self.prevRow = row
     self.prevCol = col-1
     self.nextEdge(row, col)        
     return row, col
 def nextEdge(self, row, col):
     """ returns the next point that is an edge """
     (nextRow, nextCol) = ef.nextedge(row, col, self.prevRow, self.prevCol, self.clockwise, self.pixels, [self.numRows, self.numCols])
     self.prevRow = row
     self.prevCol = col        
     self.paintEdge(row, col)
     if not(self.realEdge) and len(self.edgeLocations) > self.minEdgeLength:
         self.realEdge = True
         print 'realEdge'
     print 'newEdge'
     return nextRow, nextCol
	y23 = gaussian_filter1d(y22, sigma)
	z23 = gaussian_filter1d(z22, sigma)
	ax.plot(z13,y13,x13,color = 'b')
	ax.plot(z23,y23,x23,color = 'b')
	plt.show()

# This entire script is used mainly for debugging and visualizing the cross sections to make
# that everything is as it should be. Outputs multiple images as visual representation
if __name__ == "__main__":
	parser = ap.ArgumentParser()
	parser.add_argument('im')
	parser.add_argument('crossSections')
	parser.add_argument('centerPoints')
	args = parser.parse_args()

	centerPoints = EdgeFinder.getCenterPoints(args.centerPoints)
	img = cv2.imread(args.im)

	crossSections = []

	with open(args.crossSections) as f:
		for line in f:
			crossSection = line.split()
			xMid = float(crossSection[0])
			yMid = float(crossSection[1])
			dist = float(crossSection[2])
			angle = float(crossSection[3])
			height = float(crossSection[4])
			crossSections.append((xMid,yMid,dist,angle,height))
	displayCrossSections(crossSections,img,"interpolatedCrossSections1.txt")
	plotTrack(crossSections,centerPoints)