Example #1
0
    def plot(self, img):
        """
        Plots and call auxfun_drag class for moving and removing points.
        """
        self.drs = []
        self.updatedCoords = []
        for bpindex, bp in enumerate(self.bodyparts):
            color = self.colormap(self.norm(self.colorIndex[bpindex]))
            self.points = [
                self.dataFrame[self.scorer][bp]["x"].values[self.iter],
                self.dataFrame[self.scorer][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.DraggablePoint(circle[0],
                                                 self.bodyparts[bpindex])
            self.dr.connect()
            self.dr.coords = MainFrame.getLabels(self, self.iter)[bpindex]
            self.drs.append(self.dr)
            self.updatedCoords.append(self.dr.coords)
            if not np.isnan(self.points)[0]:
                self.buttonCounter.append(bpindex)
        self.figure.canvas.draw()

        return self.buttonCounter
 def add_point(self, center, animal, bodypart, **kwargs):
     circle = patches.Circle(center, **kwargs)
     self.ax1.add_patch(circle)
     dp = auxfun_drag.DraggablePoint(
         circle, bodypart, animal,
     )
     dp.connect()
     self.dps.append(dp)
Example #3
0
    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.rdb.GetSelection() in self.buttonCounter:
                wx.MessageBox(
                    "%s is already annotated. \n Select another body part to annotate."
                    % (str(self.bodyparts[self.rdb.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.DraggablePoint(
                    circle[0], self.bodyparts[self.rdb.GetSelection()]
                )
                self.dr.connect()
                self.buttonCounter.append(self.rdb.GetSelection())
                self.dr.coords = [
                    [
                        x1,
                        y1,
                        self.bodyparts[self.rdb.GetSelection()],
                        self.rdb.GetSelection(),
                    ]
                ]
                self.drs.append(self.dr)
                self.updatedCoords.append(self.dr.coords)
                if self.rdb.GetSelection() < len(self.bodyparts) - 1:
                    self.rdb.SetSelection(self.rdb.GetSelection() + 1)
                self.figure.canvas.draw()

        self.canvas.mpl_disconnect(self.onClick)
        self.canvas.mpl_disconnect(self.onButtonRelease)
Example #4
0
    def plot(self, im):
        """
        Plots and call auxfun_drag class for moving and removing points.
        """
        # small hack in case there are any 0 intensity images!
        im = io.imread(im)
        maxIntensity = np.max(im)
        if maxIntensity == 0:
            maxIntensity = np.max(im) + 255
        self.drs = []
        for bpindex, bp in enumerate(self.bodyparts):
            color = self.colormap(self.norm(self.colorIndex[bpindex]))
            if "CollectedData_" in self.fileName:
                self.points = [
                    self.Dataframe[self.scorer][bp]["x"].values[self.iter],
                    self.Dataframe[self.scorer][bp]["y"].values[self.iter],
                    1.0,
                ]
                self.likelihood = self.points[2]
            else:
                self.points = [
                    self.Dataframe[self.scorer][bp]["x"].values[self.iter],
                    self.Dataframe[self.scorer][bp]["y"].values[self.iter],
                    self.Dataframe[self.scorer][bp]["likelihood"].values[
                        self.iter],
                ]
                self.likelihood = self.points[2]

            if self.move2corner:
                ny, nx = np.shape(im)[0], np.shape(im)[1]
                if self.points[0] > nx or self.points[0] < 0:
                    self.points[0] = self.center[0]
                if self.points[1] > ny or self.points[1] < 0:
                    self.points[1] = self.center[1]

            if (not ("CollectedData_" in self.fileName)
                    and self.likelihood < self.threshold):
                circle = [
                    patches.Circle(
                        (self.points[0], self.points[1]),
                        radius=self.markerSize,
                        facecolor="None",
                        edgecolor=color,
                    )
                ]
            else:
                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.DraggablePoint(circle[0],
                                                 bp,
                                                 likelihood=self.likelihood)
            self.dr.connect()
            self.dr.coords = MainFrame.getLabels(self, self.iter)[bpindex]
            self.drs.append(self.dr)
            self.updatedCoords.append(self.dr.coords)
        self.figure.canvas.draw()
    def plot(self, im):
        """
        Plots and call auxfun_drag class for moving and removing points.
        """
        # small hack in case there are any 0 intensity images!
        img = io.imread(im)
        maxIntensity = np.max(img)
        if maxIntensity == 0:
            maxIntensity = np.max(img) + 255

        divider = make_axes_locatable(self.axes)
        cax = divider.append_axes("right", size="5%", pad=0.05)
        self.drs = []

        if (self.visualization_rdb.GetSelection() == 0
            ):  # i.e. for color scheme for individuals
            self.Colorscheme = visualization.get_cmap(
                len(self.individual_names), self.cfg["colormap"])
            self.norm, self.colorIndex = self.image_panel.getColorIndices(
                im, self.individual_names)
            cbar = self.figure.colorbar(self.ax,
                                        cax=cax,
                                        spacing="proportional",
                                        ticks=self.colorIndex)
            cbar.set_ticklabels(self.individual_names)
        else:  # i.e. for color scheme for all bodyparts
            self.Colorscheme = visualization.get_cmap(len(self.all_bodyparts),
                                                      self.cfg["colormap"])
            self.norm, self.colorIndex = self.image_panel.getColorIndices(
                im, self.all_bodyparts)
            cbar = self.figure.colorbar(self.ax,
                                        cax=cax,
                                        spacing="proportional",
                                        ticks=self.colorIndex)
            cbar.set_ticklabels(self.all_bodyparts)

        for ci, ind in enumerate(self.individual_names):
            col_idx = (
                0  # variable for iterating through the colorscheme for all bodyparts
            )
            image_points = []
            if ind == "single":
                if self.visualization_rdb.GetSelection() == 0:
                    for c, bp in enumerate(self.uniquebodyparts):
                        self.points = [
                            self.Dataframe[self.scorer][ind][bp]["x"].values[
                                self.iter],
                            self.Dataframe[self.scorer][ind][bp]["y"].values[
                                self.iter],
                            self.Dataframe[self.scorer][ind][bp]
                            ["likelihood"].values[self.iter],
                        ]
                        self.likelihood = self.points[2]

                        # fix move to corner
                        if self.move2corner:
                            ny, nx = np.shape(img)[0], np.shape(img)[1]
                            if self.points[0] > nx or self.points[0] < 0:
                                print("fixing x for ", bp)
                                self.points[0] = self.center[0]
                            if self.points[1] > ny or self.points[1] < 0:
                                print("fixing y for ", bp)
                                self.points[1] = self.center[1]

                        if self.likelihood < self.threshold:
                            self.circle = [
                                patches.Circle(
                                    (self.points[0], self.points[1]),
                                    radius=self.markerSize,
                                    facecolor="None",
                                    edgecolor=self.Colorscheme(ci),
                                    alpha=self.alpha,
                                )
                            ]
                        else:
                            self.circle = [
                                patches.Circle(
                                    (self.points[0], self.points[1]),
                                    radius=self.markerSize,
                                    fc=self.Colorscheme(ci),
                                    alpha=self.alpha,
                                )
                            ]
                        self.axes.add_patch(self.circle[0])
                        self.dr = auxfun_drag.DraggablePoint(
                            self.circle[0],
                            bp,
                            individual_names=ind,
                            likelihood=self.likelihood,
                        )
                        self.dr.connect()
                        self.dr.coords = MainFrame.getLabels(
                            self, self.iter, ind, self.uniquebodyparts)[c]
                        self.drs.append(self.dr)
                        self.updatedCoords.append(self.dr.coords)
                else:
                    for c, bp in enumerate(self.uniquebodyparts):
                        self.points = [
                            self.Dataframe[self.scorer][ind][bp]["x"].values[
                                self.iter],
                            self.Dataframe[self.scorer][ind][bp]["y"].values[
                                self.iter],
                            self.Dataframe[self.scorer][ind][bp]
                            ["likelihood"].values[self.iter],
                        ]
                        self.likelihood = self.points[2]

                        # fix move to corner
                        if self.move2corner:
                            ny, nx = np.shape(img)[0], np.shape(img)[1]
                            if self.points[0] > nx or self.points[0] < 0:
                                print("fixing x for ", bp)
                                self.points[0] = self.center[0]
                            if self.points[1] > ny or self.points[1] < 0:
                                print("fixing y for ", bp)
                                self.points[1] = self.center[1]

                        if self.likelihood < self.threshold:
                            self.circle = [
                                patches.Circle(
                                    (self.points[0], self.points[1]),
                                    radius=self.markerSize,
                                    fc="None",
                                    edgecolor=self.Colorscheme(col_idx),
                                    alpha=self.alpha,
                                )
                            ]
                        else:
                            self.circle = [
                                patches.Circle(
                                    (self.points[0], self.points[1]),
                                    radius=self.markerSize,
                                    fc=self.Colorscheme(col_idx),
                                    alpha=self.alpha,
                                )
                            ]
                        self.axes.add_patch(self.circle[0])
                        col_idx = col_idx + 1
                        self.dr = auxfun_drag.DraggablePoint(
                            self.circle[0],
                            bp,
                            individual_names=ind,
                            likelihood=self.likelihood,
                        )
                        self.dr.connect()
                        self.dr.coords = MainFrame.getLabels(
                            self, self.iter, ind, self.uniquebodyparts)[c]
                        self.drs.append(self.dr)
                        self.updatedCoords.append(self.dr.coords)
            else:
                if self.visualization_rdb.GetSelection() == 0:
                    for c, bp in enumerate(self.multianimalbodyparts):
                        self.points = [
                            self.Dataframe[self.scorer][ind][bp]["x"].values[
                                self.iter],
                            self.Dataframe[self.scorer][ind][bp]["y"].values[
                                self.iter],
                            self.Dataframe[self.scorer][ind][bp]
                            ["likelihood"].values[self.iter],
                        ]
                        self.likelihood = self.points[2]

                        # fix move to corner
                        if self.move2corner:
                            ny, nx = np.shape(img)[0], np.shape(img)[1]
                            if self.points[0] > nx or self.points[0] < 0:
                                print("fixing x for ", bp)
                                self.points[0] = self.center[0]
                            if self.points[1] > ny or self.points[1] < 0:
                                print("fixing y for ", bp)
                                self.points[1] = self.center[1]

                        if self.likelihood < self.threshold:
                            self.circle = [
                                patches.Circle(
                                    (self.points[0], self.points[1]),
                                    radius=self.markerSize,
                                    fc="None",
                                    edgecolor=self.Colorscheme(ci),
                                    alpha=self.alpha,
                                )
                            ]
                        else:
                            self.circle = [
                                patches.Circle(
                                    (self.points[0], self.points[1]),
                                    radius=self.markerSize,
                                    fc=self.Colorscheme(ci),
                                    alpha=self.alpha,
                                )
                            ]
                        self.axes.add_patch(self.circle[0])
                        self.dr = auxfun_drag.DraggablePoint(
                            self.circle[0],
                            bp,
                            individual_names=ind,
                            likelihood=self.likelihood,
                        )
                        self.dr.connect()
                        self.dr.coords = MainFrame.getLabels(
                            self, self.iter, ind, self.multianimalbodyparts)[c]
                        self.drs.append(self.dr)
                        self.updatedCoords.append(self.dr.coords)
                else:
                    for c, bp in enumerate(self.multianimalbodyparts):
                        self.points = [
                            self.Dataframe[self.scorer][ind][bp]["x"].values[
                                self.iter],
                            self.Dataframe[self.scorer][ind][bp]["y"].values[
                                self.iter],
                            self.Dataframe[self.scorer][ind][bp]
                            ["likelihood"].values[self.iter],
                        ]
                        self.likelihood = self.points[2]

                        # fix move to corner
                        if self.move2corner:
                            ny, nx = np.shape(img)[0], np.shape(img)[1]
                            if self.points[0] > nx or self.points[0] < 0:
                                print("fixing x for ", bp)
                                self.points[0] = self.center[0]
                            if self.points[1] > ny or self.points[1] < 0:
                                print("fixing y for ", bp)
                                self.points[1] = self.center[1]

                        if self.likelihood < self.threshold:
                            self.circle = [
                                patches.Circle(
                                    (self.points[0], self.points[1]),
                                    radius=self.markerSize,
                                    fc="None",
                                    edgecolor=self.Colorscheme(col_idx),
                                    alpha=self.alpha,
                                )
                            ]
                        else:
                            self.circle = [
                                patches.Circle(
                                    (self.points[0], self.points[1]),
                                    radius=self.markerSize,
                                    fc=self.Colorscheme(col_idx),
                                    alpha=self.alpha,
                                )
                            ]
                        self.axes.add_patch(self.circle[0])
                        col_idx = col_idx + 1
                        self.dr = auxfun_drag.DraggablePoint(
                            self.circle[0],
                            bp,
                            individual_names=ind,
                            likelihood=self.likelihood,
                        )
                        self.dr.connect()
                        self.dr.coords = MainFrame.getLabels(
                            self, self.iter, ind, self.multianimalbodyparts)[c]
                        self.drs.append(self.dr)
                        self.updatedCoords.append(self.dr.coords)
        self.figure.canvas.draw()