def _doMorph(self):
        """Apply a gaussian blur and then a tophat."""
        tophatKernel = im.makeCircularKernel(self._featureRadius)

        morphed = []
        for image in self._images:
            scaled = im.forceRange(image, 0.0, 1.0) # scale pixel values to 0-1
            blurred = cv2.GaussianBlur(scaled, (0, 0), self._blurSigma)
            tophat = cv2.morphologyEx(blurred, cv2.MORPH_TOPHAT, tophatKernel)
            # maximize contrast by forcing the range to be 0-1 again
            morphed.append(im.forceRange(tophat, 0.0, 1.0))

        self._morphed = morphed
    def run(self):
        images = self._import(im.LoadImages, "images")
        ellipses = self._import(pt.FindParticlesViaMorph, "ellipses")
        color = self._param(RENDER_ELLIPSES_COLOR)

        drawn = []
        drawn2 = []
        for image, group in zip(images, pt.groupEllipsesByFrame(ellipses)):
            self.context.debug("Group len={0}", len(group))
            canvas = cv2.imread(".\\Misc\\Base.tif")
            canvas2 = im.toColor(im.forceRange(image, 0, 255))

            for row in group:
                cv2.ellipse(
                    canvas2,
                    tuple(map(int, ellipses[row]["position"])),
                    tuple(map(int, ellipses[row]["axes"])),
                    ellipses[row]["angle"] * _TO_DEGREES,
                    0,
                    360,
                    color,
                    1,
                    cv2.CV_AA,
                    0,
                )
                cv2.ellipse(
                    canvas,
                    tuple(map(int, ellipses[row]["position"])),
                    tuple(map(int, ellipses[row]["axes"])),
                    ellipses[row]["angle"] * _TO_DEGREES,
                    0,
                    360,
                    color,
                    1,
                    cv2.CV_AA,
                    0,
                )
            drawn.append(canvas)
            drawn2.append(canvas2)
        self._save(drawn)
        self._render(drawn2)
 def run(self):
     diffs = self._import(im.ComputeForegroundMasks, "diffs")
     mapping = lambda image: im.forceRange(image*(image > 0), 0, 255)\
                             .astype(np.uint8)
     self._render(diffs, mapping)
    def run(self):
        images = self._import(im.LoadImages, "images")
        ellipses = self._import(pt.FindParticlesViaMorph, "ellipses")
        tracks = self._import(pt.TrackParticles, "tracksrender")

        ellipse_color = self._param(RENDER_ELLIPSES_COLOR)
        N = 200  # np.max(tracks[:]["trackID"])
        HSV_tuples = [(x * 1.0 / N, 0.99, 0.99) for x in range(N)]
        tracks_color = map(lambda x: colorsys.hsv_to_rgb(*x), HSV_tuples)
        # print tracks_color
        arrow_color = self._param(RENDER_TRACKS_COLOR)

        drawn = []
        for image, group_ellipse, group_tracks in zip(
            images, pt.groupEllipsesByFrame(ellipses), pt.groupEllipsesByFrame(tracks)
        ):
            self.context.debug("Ellipse len={0}", len(group_ellipse))
            self.context.debug("Track len={0}", len(group_tracks))
            canvas = im.toColor(im.forceRange(image, 0, 255))

            for row in group_ellipse:
                cv2.ellipse(
                    canvas,
                    tuple(map(int, ellipses[row]["position"])),
                    tuple(map(int, ellipses[row]["axes"])),
                    ellipses[row]["angle"] * _TO_DEGREES,
                    0,
                    360,
                    ellipse_color,
                    1,
                    cv2.CV_AA,
                    0,
                )
            for row in group_tracks:
                angle = tracks[row]["angle"]
                radius = tracks[row]["axes"][0]
                color = tracks_color[int(tracks[row]["trackID"] - 1) % 200]
                color = map(lambda x: 255 * x, color)
                # print int(tracks[row]["trackID"]%200),color
                cv2.ellipse(
                    canvas,
                    tuple(map(int, tracks[row]["position"])),
                    tuple(map(int, [radius, radius])),
                    tracks[row]["angle"] * _TO_DEGREES,
                    0,
                    360,
                    color,
                    2,
                    cv2.CV_AA,
                    0,
                )
                cv2.line(
                    canvas,
                    tuple(map(int, tracks[row]["position"])),
                    tuple(map(int, tracks[row]["position"] + 10 * np.array([math.cos(angle), math.sin(angle)]))),
                    (arrow_color),
                    1,
                    cv2.CV_AA,
                    0,
                )
            drawn.append(canvas)

        self._render(drawn)