def line_profile(self, event): if event.inaxes == self.fig_image_parameter[4].ax: if self.line_prof_edit == 0: if self.line_prof is None: print('create line') self.line_prof_edit = 1 self.line_prof = LineDraw.LineDraw( self.ax_image, epsilon=0.05 * np.sqrt(np.size(self.image_data))) self.line_prof.ConnectDraw() else: print('edit line') self.line_prof_edit = 1 self.line_prof.ConnectMove() elif self.line_prof_edit == 1: print('disconect') self.line_prof_edit = 0 self.line_prof.DisconnectDraw() self.line_prof.DisconnectMove() self.fig_line_prof = plt.figure() self.ax_fig_line_prof = self.fig_line_prof.add_subplot(1, 1, 1) print(self.line_prof.WidthData) first_postion = (self.line_prof.LineCoords[0][1], self.line_prof.LineCoords[0][0]) second_postion = (self.line_prof.LineCoords[1][1], self.line_prof.LineCoords[1][0]) self.profile = skimage.measure.profile_line( self.image_data, first_postion, second_postion, linewidth=int(self.line_prof.WidthData)) self.ax_fig_line_prof.plot(self.profile) plt.show() else: return
def __init__(self, image, axis, colourbar_axis=None, cmap=plt.get_cmap('gray'), filepath=os.getcwd(), polygoncallback=None): '''For plotting Image as an image Input a 2D array to plot as an image, and an axis to plot the image on Optional arguments: define an axis to put a colourbar in, define the filepath to save images to''' self.axis = axis self.colourbar_axis = colourbar_axis self.cmap = cmap self.Image = image self.axis.set_axis_off() self.filepath = filepath self.PlottedImage = self.axis.imshow(self.Image.data, cmap=self.cmap, interpolation='none') if self.colourbar_axis: self.cbar = self.AddColourbar() if image.calibration != 0: self.scalebar = ScaleBar(self.Image.calibration) self.scalebar.box_alpha = 0.5 self.axis.add_artist(self.scalebar) if polygoncallback: self.polygoncallback = polygoncallback else: self.polygoncallback = self.keyboard_press self.PolygonGroups = PolygonGrouper.PolygonGroupManager(self.axis) self.Lines = LineDraw.LineDraw(self.axis) self.canvas = self.axis.figure.canvas self.connect() self.creator = None self.mover = None
def LineTo(ser, start, end): penPosition = start steps = LineDraw.get_deltas(start[0], start[1], end[0], end[1]) for delta in steps: MotorInterface.MoveDelta(ser, delta) penPosition[0] += delta[0] penPosition[1] += delta[1] return penPosition
def MoveTo(ser, start, end): penPosition = start MotorInterface.PenUp(ser) steps = LineDraw.get_deltas(start[0], start[1], end[0], end[1]) for delta in steps: MotorInterface.MoveDelta(ser, delta) penPosition[0] += delta[0] penPosition[1] += delta[1] if ((end[0] != 0) or (end[1] != 0)): MotorInterface.PenDown(ser) return penPosition
def CurveTo(ser, start, cp1, cp2, end): penPosition = start t = 0.05 while t < 1.01: currX = end[0]*(t**3) + 3*cp2[0]*((t**2)*(1-t)) + 3*cp1[0]*(t*((1-t)**2)) + start[0]*((1-t)**3) currY = end[1]*(t**3) + 3*cp2[1]*((t**2)*(1-t)) + 3*cp1[1]*(t*((1-t)**2)) + start[1]*((1-t)**3) steps = LineDraw.get_deltas(penPosition[0], penPosition[1], currX, currY) for delta in steps: MotorInterface.MoveDelta(ser, delta) penPosition[0] += delta[0] penPosition[1] += delta[1] t += .05 return penPosition
def setUp(self): self.linedraw = LineDraw.Linedraw()