Ejemplo n.º 1
0
    def plot_rectification(self):
        import matplotlib.pyplot as plt
        image = retrieve_image(self._model.images,
                               channel=0,
                               number_of_channels=self._model.nChannels,
                               zstack=self._model.zstack,
                               number_of_zstacks=self._model.nZstack,
                               frame=0)

        rows, cols = image.shape[0], image.shape[1]
        out = self.rectify(image)

        fig, (ax1, ax2) = plt.subplots(2,
                                       1,
                                       gridspec_kw={'height_ratios': [4, 1]})
        ax1.imshow(image, origin='lower')
        # ax1.plot(self.src[:, 0], self.src[:, 1], '.b')
        ax1.axis((0, cols, rows, 0))

        ax2.imshow(out, origin='lower')
        # ax2.plot(self.transform.inverse(self.src)[:, 0], self.transform.inverse(self.src)[:, 1], '.b')
        ax2.axis((0, self.out_cols, self.out_rows, 0))

        fig = plt.figure()
        ax = fig.gca()
        # ext = [0, t_dom.max(), dl_dom.max() * 2, 0]
        plt.imshow(out, origin='lower', aspect='auto')  # , extent=ext)
        ax.set_title('Image rectification using piecewise linear transform')

        plt.show(block=False)
Ejemplo n.º 2
0
    def paint_measures(self):
        logger.debug("painting measurement")
        data = retrieve_image(self.images,
                              channel=self._actch,
                              number_of_channels=self.nChannels,
                              zstack=self.zstack,
                              number_of_zstacks=self.nZstack,
                              frame=0)
        self.dwidth, self.dheight = data.shape
        # print(data.shape, self.dwidth, self.dheight)

        # map the data range to 0 - 255
        img8bit = ((data - data.min()) / (data.ptp() / 255.0)).astype(np.uint8)

        for me in self.measurements:
            r0, c0, r1, c1 = np.array(list(me['ls0']) +
                                      list(me['ls1'])).astype(int)
            rr, cc = draw.line(r0, c0, r1, c1)
            img8bit[cc, rr] = 255
            rr, cc = draw.circle(r0, c0, 3)
            img8bit[cc, rr] = 255

        qtimage = QtGui.QImage(img8bit.repeat(4), self.dwidth, self.dheight,
                               QtGui.QImage.Format_RGB32)
        self.imagePixmap = QPixmap(qtimage)
        self.setPixmap(self.imagePixmap)
        return
Ejemplo n.º 3
0
 def rngimage(self):
     if self._rngimage is None:
         if self.file is not None:
             self._rngimage = retrieve_image(
                 self.images,
                 channel=self.rngChannel,
                 number_of_channels=self.nChannels,
                 zstack=self.zstack,
                 number_of_zstacks=self.nZstack,
                 frame=0)
             self._rngpixmap = None
     return self._rngimage
Ejemplo n.º 4
0
    def actChannel(self, value):
        if value is not None:
            self._actch = int(value)

            if self.file is not None:
                self._actimage = retrieve_image(
                    self.images,
                    channel=self._actch,
                    number_of_channels=self.nChannels,
                    zstack=self.zstack,
                    number_of_zstacks=self.nZstack,
                    frame=0)
                if self.activeCh == "act":
                    self._repaint()
Ejemplo n.º 5
0
 def zstack(self, value):
     if value is not None:
         self._zstack = int(value)
         self._boudaries = None
         if self.images is not None:
             self._dnaimage = retrieve_image(
                 self.images,
                 channel=self._dnach,
                 number_of_channels=self.nChannels,
                 zstack=self.zstack,
                 number_of_zstacks=self.nZstack,
                 frame=0)
             self._actimage = retrieve_image(
                 self.images,
                 channel=self._actch,
                 number_of_channels=self.nChannels,
                 zstack=self.zstack,
                 number_of_zstacks=self.nZstack,
                 frame=0)
         if self.selNuc is not None:
             p = self.selNuc.centroid
             self._measure(p.x, p.y)
         self._repaint()
Ejemplo n.º 6
0
    def drawMeasurements(self, ax, pal):
        if self._selNuc is None: return
        from matplotlib import cm
        from shapely import affinity
        import plots as p

        act_img = retrieve_image(self.images,
                                 channel=self.rngChannel,
                                 number_of_channels=self.nChannels,
                                 zstack=self.zstack,
                                 number_of_zstacks=self.nZstack,
                                 frame=0)

        ext = [
            0, self.dwidth / self.pix_per_um, self.dheight / self.pix_per_um, 0
        ]

        ax.imshow(act_img, interpolation='none', extent=ext, cmap=cm.gray_r)

        for n in [e["boundary"] for e in self._boudaries]:
            n_um = affinity.scale(n,
                                  xfact=self.um_per_pix,
                                  yfact=self.um_per_pix,
                                  origin=(0, 0, 0))
            p.render_polygon(n_um, zorder=10, ax=ax)

        for me, c in zip(self.measurements, pal):
            ax.plot([
                me['ls0'][0] / self.pix_per_um, me['ls1'][0] / self.pix_per_um
            ], [
                me['ls0'][1] / self.pix_per_um, me['ls1'][1] / self.pix_per_um
            ],
                    linewidth=1,
                    linestyle='-',
                    color=c,
                    alpha=1)

        w = 20
        c = self._selNuc.centroid
        x0, y0 = c.x / self.pix_per_um - w, c.y / self.pix_per_um - w
        ax.set_xlim([x0, x0 + 2 * w])
        ax.set_ylim([y0, y0 + 2 * w])

        ax.plot([x0 + 2, x0 + 12], [y0 + 2, y0 + 2], c='w', lw=4)
        ax.text(x0 + 5, y0 + 3.5, '10 um', color='w', fontdict={'size': 7})
Ejemplo n.º 7
0
    def paintEvent(self, event):
        if self.dataHasChanged:
            self.dataHasChanged = False
            ch = self.actChannel if self.activeCh == "act" else self.dnaChannel
            data = retrieve_image(self.images,
                                  channel=ch,
                                  number_of_channels=self.nChannels,
                                  zstack=self.zstack,
                                  number_of_zstacks=self.nZstack,
                                  frame=0)
            self.dwidth, self.dheight = data.shape

            # map the data range to 0 - 255
            img_8bit = ((data - data.min()) / (data.ptp() / 255.0)).astype(
                np.uint8)
            qtimage = QtGui.QImage(img_8bit.repeat(4), self.dwidth,
                                   self.dheight, QtGui.QImage.Format_RGB32)
            self.imagePixmap = QPixmap(qtimage)
            if self.render:
                self._drawMeasurements()
            self.setPixmap(self.imagePixmap)

        return QtGui.QLabel.paintEvent(self, event)
Ejemplo n.º 8
0
    def plot_grid(self):
        import matplotlib.pyplot as plt
        import plots as p

        fig = plt.figure()
        ax = fig.gca()

        c = self._poly.centroid
        xdata, ydata = self._poly.exterior.xy
        ax.set_xlim([
            min(xdata) - 2 * self.pix_per_um,
            max(xdata) + 2 * self.pix_per_um
        ])
        ax.set_ylim([
            min(ydata) - 2 * self.pix_per_um,
            max(ydata) + 2 * self.pix_per_um
        ])

        dna_ch = 0
        act_ch = 2
        image = retrieve_image(self.images,
                               channel=dna_ch,
                               number_of_channels=self.nChannels,
                               zstack=self.zstack,
                               number_of_zstacks=self.nZstack,
                               frame=0)
        ax.imshow(image, origin='lower', cmap='gray')

        p.render_polygon(self._poly, zorder=10, ax=ax)
        pts = np.array(
            [self.f(_t) for _t in np.linspace(0, 2 * np.pi, num=len(xdata))])
        ax.plot(pts[:, 0], pts[:, 1], linewidth=1, linestyle='-', c='blue')
        ax.set_title("Grid on image")

        theta = np.linspace(0, 2 * np.pi, num=20)
        fx, fy = self.f(theta)
        ax.scatter(fx,
                   fy,
                   linewidth=1,
                   marker='o',
                   edgecolors='yellow',
                   facecolors='none',
                   label='x')

        # plot normals and tangents
        dl_arr = np.linspace(-1, 1, num=5) * self.pix_per_um
        # dl_arr = np.linspace(0, 1, num=3) * self.pix_per_um
        for i, t in enumerate(theta):
            x0, y0 = self.f(t)

            o = self.normal_angle(t)
            fnx, fny = np.array([(x0 + dl * np.cos(o), y0 + dl * np.sin(o))
                                 for dl in dl_arr]).T
            ax.plot(fnx,
                    fny,
                    linewidth=1,
                    linestyle='-',
                    c='white',
                    marker='o',
                    ms=1)

            th = self.tangent_angle(t)
            ftx, fty = np.array([(x0 + dl * np.cos(th), y0 + dl * np.sin(th))
                                 for dl in dl_arr]).T
            ax.plot(ftx, fty, linewidth=1, linestyle='-', c='red')

            plt.annotate((f"{i} ({t:.2f}): "
                          f"T{np.rad2deg(th):.0f}º  "
                          f"N{np.rad2deg(o):.0f}º "
                          f"{np.sin(o):.2f} {np.cos(o):.2f}"), (x0, y0),
                         (min(xdata) if x0 < c.x else max(xdata), y0),
                         color="red",
                         horizontalalignment='right' if x0 < c.x else 'left',
                         arrowprops=dict(facecolor='white', shrink=0.05))

        plt.show(block=False)