def onClick(self,event): """ This function adds labels and auto advances to the next label. """ x1 = event.xdata y1 = event.ydata if event.button == 3: if self.individualrdb.GetStringSelection() =="single": self.norm,self.colorIndex = self.image_panel.getColorIndices(self.img,self.uniquebodyparts) if self.uniquebodyparts[self.rdb.GetSelection()] in self.buttonCounter[self.individual_names[self.individualrdb.GetSelection()]]: wx.MessageBox('%s is already annotated for %s. \n Select another body part to annotate.' % (str(self.uniquebodyparts[self.rdb.GetSelection()]),str(self.individual_names[self.individualrdb.GetSelection()])), 'Error!', wx.OK | wx.ICON_ERROR) else: color = self.colormap(self.norm(self.colorIndex[self.rdb.GetSelection()])) circle = [patches.Circle((x1, y1), radius = self.markerSize, fc=color, alpha=self.alpha)] self.num.append(circle) self.axes.add_patch(circle[0]) self.dr = auxfun_drag_label_multiple_individuals.DraggablePoint(circle[0],self.individual_names[self.individualrdb.GetSelection()],self.uniquebodyparts[self.rdb.GetSelection()]) self.dr.connect() self.buttonCounter[self.individual_names[self.individualrdb.GetSelection()]].append(self.uniquebodyparts[self.rdb.GetSelection()]) self.dr.coords = [[x1,y1,self.individual_names[self.individualrdb.GetSelection()],self.uniquebodyparts[self.rdb.GetSelection()]]] self.drs.append(self.dr) self.updatedCoords.append(self.dr.coords) if self.rdb.GetSelection() < len(self.uniquebodyparts) - 1: self.rdb.SetSelection(self.rdb.GetSelection() + 1) else: self.rdb.SetSelection(0) if self.individualrdb.GetSelection() < len(self.individual_names) -1: self.individualrdb.SetSelection(self.individualrdb.GetSelection() + 1) MainFrame.select_individual(self,event) else: self.norm,self.colorIndex = self.image_panel.getColorIndices(self.img,self.multibodyparts) if self.multibodyparts[self.rdb.GetSelection()] in self.buttonCounter[self.individual_names[self.individualrdb.GetSelection()]]: wx.MessageBox('%s is already annotated for %s. \n Select another body part to annotate.' % (str(self.multibodyparts[self.rdb.GetSelection()]),str(self.individual_names[self.individualrdb.GetSelection()])), 'Error!', wx.OK | wx.ICON_ERROR) else: color = self.colormap(self.norm(self.colorIndex[self.rdb.GetSelection()])) circle = [patches.Circle((x1, y1), radius = self.markerSize, fc=color, alpha=self.alpha)] self.num.append(circle) self.axes.add_patch(circle[0]) self.dr = auxfun_drag_label_multiple_individuals.DraggablePoint(circle[0],self.individual_names[self.individualrdb.GetSelection()],self.multibodyparts[self.rdb.GetSelection()]) self.dr.connect() self.buttonCounter[self.individual_names[self.individualrdb.GetSelection()]].append(self.multibodyparts[self.rdb.GetSelection()]) self.dr.coords = [[x1,y1,self.individual_names[self.individualrdb.GetSelection()],self.multibodyparts[self.rdb.GetSelection()]]] self.drs.append(self.dr) self.updatedCoords.append(self.dr.coords) if self.rdb.GetSelection() < len(self.multibodyparts) - 1: self.rdb.SetSelection(self.rdb.GetSelection() + 1) else: self.rdb.SetSelection(0) if self.individualrdb.GetSelection() < len(self.individual_names) -1: self.individualrdb.SetSelection(self.individualrdb.GetSelection() + 1) MainFrame.select_individual(self,event) self.canvas.mpl_disconnect(self.onClick)
def plot(self,img): """ Plots and call auxfun_drag class for moving and removing points. """ self.drs= [] self.updatedCoords = [] for ind in self.individual_names: image_points = [] for bpindex, bp in enumerate(self.bodyparts): color = self.colormap(self.norm(self.colorIndex[bpindex])) image_points = [[self.dataFrame[self.scorer][ind][bp]['x'].values[self.iter],self.dataFrame[self.scorer][ind][bp]['y'].values[self.iter],ind,bp]] self.points = [self.dataFrame[self.scorer][ind][bp]['x'].values[self.iter],self.dataFrame[self.scorer][ind][bp]['y'].values[self.iter]] circle = [patches.Circle((self.points[0], self.points[1]), radius=self.markerSize, fc = color, alpha=self.alpha)] self.axes.add_patch(circle[0]) self.dr = auxfun_drag_label_multiple_individuals.DraggablePoint(circle[0],ind,self.bodyparts[bpindex]) self.dr.connect() self.dr.coords = image_points # self.dr.coords = MainFrame.getLabels(self,ind,self.iter)[bpindex] self.drs.append(self.dr) self.updatedCoords.append(self.dr.coords) if np.isnan(self.points)[0] == False: self.buttonCounter[ind].append(self.bodyparts[bpindex]) MainFrame.saveEachImage(self) self.figure.canvas.draw() return(self.buttonCounter)
def plot(self, img): """ Plots and call auxfun_drag class for moving and removing points. """ self.drs = [] self.updatedCoords = [] # print(self.dataFrame) for j, ind in enumerate(self.individual_names): image_points = [] idcolor = self.idmap(j) if ind == "single": for c, bp in enumerate(self.uniquebodyparts): image_points = [[ self.dataFrame[self.scorer][ind][bp]["x"].values[ self.iter], self.dataFrame[self.scorer][ind][bp]["y"].values[ self.iter], ind, bp, ]] self.points = [ self.dataFrame[self.scorer][ind][bp]["x"].values[ self.iter], self.dataFrame[self.scorer][ind][bp]["y"].values[ self.iter], ] self.norm, self.colorIndex = self.image_panel.getColorIndices( self.img, self.uniquebodyparts) color = self.colormap(self.norm(self.colorIndex[c])) circle = patches.Circle( (self.points[0], self.points[1]), radius=self.markerSize, fc=color, ec=idcolor, lw=self.edgewidth, alpha=self.alpha, ) self.axes.add_patch(circle) self.dr = auxfun_drag_label_multiple_individuals.DraggablePoint( circle, ind, self.uniquebodyparts[c]) self.dr.connect() self.dr.coords = image_points self.drs.append(self.dr) self.updatedCoords.append(self.dr.coords) if np.isnan(self.points)[0] == False: self.buttonCounter[ind].append(self.uniquebodyparts[c]) else: for c, bp in enumerate(self.multibodyparts): image_points = [[ self.dataFrame[self.scorer][ind][bp]["x"].values[ self.iter], self.dataFrame[self.scorer][ind][bp]["y"].values[ self.iter], ind, bp, ]] self.points = [ self.dataFrame[self.scorer][ind][bp]["x"].values[ self.iter], self.dataFrame[self.scorer][ind][bp]["y"].values[ self.iter], ] self.norm, self.colorIndex = self.image_panel.getColorIndices( self.img, self.multibodyparts) color = self.colormap(self.norm(self.colorIndex[c])) circle = patches.Circle( (self.points[0], self.points[1]), radius=self.markerSize, fc=color, ec=idcolor, lw=self.edgewidth, alpha=self.alpha, ) self.axes.add_patch(circle) self.dr = auxfun_drag_label_multiple_individuals.DraggablePoint( circle, ind, self.multibodyparts[c]) self.dr.connect() self.dr.coords = image_points self.drs.append(self.dr) self.updatedCoords.append(self.dr.coords) if np.isnan(self.points)[0] == False: self.buttonCounter[ind].append(self.multibodyparts[c]) MainFrame.saveEachImage(self) self.figure.canvas.draw() return self.buttonCounter