コード例 #1
0
ファイル: topographica_based.py プロジェクト: teogale/mozaik
    def frames(self):
        num_frames = 0
        while True:

            d = imagen.RawRectangle(offset=self.background_luminance,
                                    scale=self.background_luminance *
                                    (self.relative_luminance - 0.5),
                                    bounds=BoundingBox(radius=self.size_x / 2),
                                    xdensity=self.density,
                                    ydensity=self.density,
                                    x=self.x,
                                    y=self.y,
                                    orientation=self.orientation,
                                    size=self.width,
                                    aspect_ratio=self.length / self.width)()

            b = imagen.Constant(scale=self.background_luminance,
                                bounds=BoundingBox(radius=self.size_x / 2),
                                xdensity=self.density,
                                ydensity=self.density)()

            num_frames += 1
            if (num_frames - 1) * self.frame_duration < self.flash_duration:
                yield (d, [1])
            else:
                yield (b, [0])
コード例 #2
0
ファイル: topographica_based.py プロジェクト: teogale/mozaik
    def frames(self):
        self.current_phase = 0
        while True:
            a = imagen.SineGrating(orientation=self.orientation,
                                   frequency=self.spatial_frequency,
                                   phase=self.current_phase,
                                   bounds=BoundingBox(radius=self.size_x / 2),
                                   offset=self.background_luminance *
                                   (100.0 - self.contrast) / 100.0,
                                   scale=2 * self.background_luminance *
                                   self.contrast / 100.0,
                                   xdensity=self.density,
                                   ydensity=self.density)()

            b = imagen.Constant(scale=self.background_luminance,
                                bounds=BoundingBox(radius=self.size_x / 2),
                                xdensity=self.density,
                                ydensity=self.density)()
            c = imagen.Disk(smoothing=0.0,
                            size=self.radius * 2,
                            scale=1.0,
                            bounds=BoundingBox(radius=self.size_x / 2),
                            xdensity=self.density,
                            ydensity=self.density)()
            d1 = numpy.multiply(a, c)
            d2 = numpy.multiply(b, -(c - 1.0))
            d = numpy.add.reduce([d1, d2])
            yield (d, [self.current_phase])
            self.current_phase += 2 * pi * (self.frame_duration /
                                            1000.0) * self.temporal_frequency
コード例 #3
0
ファイル: topographica_based.py プロジェクト: teogale/mozaik
 def frames(self):
     while True:
         yield (imagen.Constant(scale=self.background_luminance,
                                bounds=BoundingBox(radius=self.size_x / 2),
                                xdensity=self.density,
                                ydensity=self.density)(),
                [self.frame_duration])
コード例 #4
0
ファイル: topographica_based.py プロジェクト: teogale/mozaik
 def frames(self):
     # the size length of square edge is given by half the period
     size = 1. / (2 * self.spatial_frequency)
     # if a separation size is provided we use it, otherwise we use the same as size
     if self.separated:
         halfseparation = self.separation / 2.
     else:
         halfseparation = size
     # if the separation is less than the size of a square, the two squares will overlap and the luminance will be too much
     if halfseparation < size / 2.:
         halfseparation = size / 2.
     # flashing squares with a temporal frequency of 6Hz are happening every 1000/6=167ms
     time = self.duration / self.frame_duration
     stim_period = time / self.temporal_frequency
     t = 0
     t0 = 0
     # total time of the stimulus
     while t <= time:
         # frequency tick
         if (t - t0) >= stim_period:
             t0 = t
         # Squares presence on screen is half of the period.
         # Since the two patterns will be added together,
         # the offset level is half it should be, to sum into the required level,
         # and the scale level is twice as much, in order to overcome the presence of the other pattern
         if t <= t0 + (stim_period / 2):
             a = imagen.RawRectangle(
                 x=-halfseparation,
                 y=0,
                 orientation=self.orientation,
                 bounds=BoundingBox(radius=self.size_x / 2),
                 offset=0.5 * self.background_luminance *
                 (100.0 - self.contrast) / 100.0,
                 scale=2 * self.background_luminance * self.contrast /
                 100.0,
                 xdensity=self.density,
                 ydensity=self.density,
                 size=size)()
             b = imagen.RawRectangle(
                 x=halfseparation,
                 y=0,
                 orientation=self.orientation,
                 bounds=BoundingBox(radius=self.size_x / 2),
                 offset=0.5 * self.background_luminance *
                 (100.0 - self.contrast) / 100.0,
                 scale=2 * self.background_luminance * self.contrast /
                 100.0,
                 xdensity=self.density,
                 ydensity=self.density,
                 size=size)()
             yield (numpy.add(a, b), [t])
         else:
             yield (imagen.Constant(scale=self.background_luminance *
                                    (100.0 - self.contrast) / 100.0,
                                    bounds=BoundingBox(radius=self.size_x /
                                                       2),
                                    xdensity=self.density,
                                    ydensity=self.density)(), [t])
         # time
         t += 1
コード例 #5
0
ファイル: texture_based.py プロジェクト: RCagnol/mozaik
    def frames(self):
        fieldsize_x = self.size_x * self.density
        fieldsize_y = self.size_y * self.density
        folder_name = Global.root_directory + "/TextureImagesStimuli"
        libpath = __file__.replace(
            "/texture_based.py",
            "") + "/textureLib"  #path to the image processing library
        matlabPyrToolspath = os.path.join(libpath, "textureSynth",
                                          "matlabPyrTools")
        if not os.path.isdir(matlabPyrToolspath):
            raise IOError(
                "matlabPyrTools should be downloaded from https://github.com/LabForComputationalVision/matlabPyrTools and its content should be put in the directory "
                + matlabPyrToolspath)

        octave.addpath(libpath)
        im = octave.textureBasedStimulus(self.texture_path, self.stats_type,
                                         self.seed, fieldsize_x, fieldsize_y,
                                         libpath)
        scale = 2. * self.background_luminance / (numpy.max(im) -
                                                  numpy.min(im))
        im = (im - numpy.min(im)) * scale

        if not os.path.exists(folder_name):
            os.mkdir(folder_name)

        assert (im.shape == (fieldsize_x, fieldsize_y)
                ), "Image dimensions do not correspond to visual field size"

        b = imagen.Constant(scale=self.background_luminance,
                            bounds=BoundingBox(radius=self.size_x / 2),
                            xdensity=self.density,
                            ydensity=self.density)()
        c = imagen.Disk(smoothing=0.0,
                        size=self.radius * 2,
                        scale=1.0,
                        bounds=BoundingBox(radius=self.size_x / 2),
                        xdensity=self.density,
                        ydensity=self.density)()

        d1 = numpy.multiply(im, c)
        d2 = numpy.multiply(b, -(c - 1.0))
        d = numpy.add.reduce([d1, d2])

        d = d.astype(numpy.uint8)
        IM = Image.fromarray(d)
        IM.save(folder_name + "/" + self.texture + "sample" +
                str(self.sample) + "type" + str(self.stats_type) + 'radius' +
                str(self.radius) + '.pgm')

        while True:
            yield (d, [0])
コード例 #6
0
ファイル: topographica_based.py プロジェクト: teogale/mozaik
    def frames(self):
        num_frames = 0

        while True:
            length = self.length / 2 - self.gap_length / 2.0
            shift = length / 2.0 + self.gap_length / 2.0

            r1 = imagen.Rectangle(
                x=shift * numpy.cos(self.right_angle),
                y=shift * numpy.sin(right_angle),
                offset=self.background_luminance,
                scale=2 * self.background_luminance *
                (self.relative_luminance - 0.5),
                orientation=numpy.pi / 2 + self.right_angle,
                smoothing=0,
                aspect_ratio=self.width / length,
                size=length,
                bounds=BoundingBox(radius=self.size_x / 2),
            )

            r2 = imagen.Rectangle(
                x=shift * numpy.cos(self.left_angle),
                y=shift * numpy.sin(left_angle),
                offset=self.background_luminance,
                scale=2 * self.background_luminance *
                (self.relative_luminance - 0.5),
                orientation=numpy.pi / 2 + self.left_angle,
                smoothing=0,
                aspect_ratio=self.width / length,
                size=length,
                bounds=BoundingBox(radius=self.size_x / 2),
            )

            r = imagen.Composite(generators=[r1, r2],
                                 x=self.x,
                                 y=self.y,
                                 bounds=BoundingBox(radius=self.size_x / 2),
                                 orientation=self.orientation,
                                 xdensity=self.density,
                                 ydensity=self.density)

            b = imagen.Constant(scale=self.background_luminance,
                                bounds=BoundingBox(radius=self.size_x / 2),
                                xdensity=self.density,
                                ydensity=self.density)()

            num_frames += 1
            if (num_frames - 1) * self.frame_duration < self.flash_duration:
                yield (r(), [1])
            else:
                yield (b, [0])
コード例 #7
0
ファイル: topographica_based.py プロジェクト: teogale/mozaik
    def frames(self):
        self.current_phase = 0
        while True:
            center = imagen.SineGrating(
                mask_shape=imagen.Disk(smoothing=0.0,
                                       size=self.center_radius * 2.0),
                orientation=self.center_orientation,
                frequency=self.spatial_frequency,
                phase=self.current_phase,
                bounds=BoundingBox(radius=self.size_x / 2.0),
                offset=0,
                scale=2 * self.background_luminance * self.contrast / 100.0,
                xdensity=self.density,
                ydensity=self.density)()
            r = (self.center_radius + self.surround_radius + self.gap) / 2.0
            t = (self.surround_radius - self.center_radius - self.gap) / 2.0
            surround = imagen.SineGrating(
                mask_shape=imagen.Ring(thickness=t * 2.0,
                                       smoothing=0.0,
                                       size=r * 2.0),
                orientation=self.surround_orientation,
                frequency=self.spatial_frequency,
                phase=self.current_phase,
                bounds=BoundingBox(radius=self.size_x / 2.0),
                offset=0,
                scale=2 * self.background_luminance * self.contrast / 100.0,
                xdensity=self.density,
                ydensity=self.density)()

            offset = imagen.Constant(
                mask_shape=imagen.Disk(smoothing=0.0,
                                       size=self.surround_radius * 2.0),
                bounds=BoundingBox(radius=self.size_x / 2.0),
                scale=self.background_luminance * (100.0 - self.contrast) /
                100.0,
                xdensity=self.density,
                ydensity=self.density)()

            background = (imagen.Disk(
                smoothing=0.0,
                size=self.surround_radius * 2.0,
                bounds=BoundingBox(radius=self.size_x / 2.0),
                xdensity=self.density,
                ydensity=self.density)() - 1) * -self.background_luminance

            yield (numpy.add.reduce(
                [numpy.maximum(center, surround), offset,
                 background]), [self.current_phase])
            self.current_phase += 2 * pi * (self.frame_duration /
                                            1000.0) * self.temporal_frequency
コード例 #8
0
ファイル: topographica_based.py プロジェクト: teogale/mozaik
    def frames(self):
        num_frames = 0
        while True:

            z = self.gap_length / 4.0 + self.length / 4.0

            d1 = imagen.RawRectangle(
                offset=self.background_luminance,
                scale=2 * self.background_luminance *
                (self.relative_luminance - 0.5),
                bounds=BoundingBox(radius=self.size_x / 2),
                xdensity=self.density,
                ydensity=self.density,
                x=self.x + numpy.cos(self.orientation) * (z),
                y=self.y + numpy.sin(self.orientation) * (z),
                orientation=self.orientation + self.disalignment,
                size=self.width,
                aspect_ratio=(self.length - self.gap_length) / 2 /
                self.width)()

            d2 = imagen.RawRectangle(
                offset=self.background_luminance,
                scale=2 * self.background_luminance *
                (self.relative_luminance - 0.5),
                bounds=BoundingBox(radius=self.size_x / 2),
                xdensity=self.density,
                ydensity=self.density,
                x=self.x + numpy.cos(self.orientation) * (-z),
                y=self.y + numpy.sin(self.orientation) * (-z),
                orientation=self.orientation + self.disalignment,
                size=self.width,
                aspect_ratio=(self.length - self.gap_length) / 2 /
                self.width)()

            b = imagen.Constant(scale=self.background_luminance,
                                bounds=BoundingBox(radius=self.size_x / 2),
                                xdensity=self.density,
                                ydensity=self.density)()

            num_frames += 1
            if (num_frames - 1) * self.frame_duration < self.flash_duration:
                if self.relative_luminance > 0.5:
                    yield (numpy.maximum(d1, d2), [1])
                else:
                    yield (numpy.minimum(d1, d2), [1])
            else:
                yield (b, [0])
コード例 #9
0
ファイル: topographica_based.py プロジェクト: teogale/mozaik
    def frames(self):
        num_frames = 0
        while True:

            d1 = imagen.RawRectangle(
                offset=0,
                scale=2 * self.background_luminance,
                bounds=BoundingBox(radius=self.size_x / 2),
                xdensity=self.density,
                ydensity=self.density,
                x=self.x - (self.occlusion_bar_width / 2) -
                (self.length - self.occlusion_bar_width) / 4,
                y=self.y,
                orientation=self.orientation,
                size=self.background_bar_width,
                aspect_ratio=(self.length - self.occlusion_bar_width) / 2 /
                self.background_bar_width)()

            d2 = imagen.RawRectangle(
                offset=0,
                scale=2 * self.background_luminance,
                bounds=BoundingBox(radius=self.size_x / 2),
                xdensity=self.density,
                ydensity=self.density,
                x=self.x + (self.occlusion_bar_width / 2) +
                (self.length - self.occlusion_bar_width) / 4,
                y=self.y,
                orientation=self.orientation,
                size=self.background_bar_width,
                aspect_ratio=(self.length - self.occlusion_bar_width) / 2 /
                self.background_bar_width)()

            b = imagen.Constant(scale=0,
                                bounds=BoundingBox(radius=self.size_x / 2),
                                xdensity=self.density,
                                ydensity=self.density)()

            num_frames += 1
            if (num_frames - 1) * self.frame_duration < self.flash_duration:
                yield (numpy.add(d1, d2), [1])
            else:
                yield (b, [0])
コード例 #10
0
ファイル: topographica_based.py プロジェクト: teogale/mozaik
    def frames(self):
        self.current_phase = 0
        while True:
            r = (self.inner_appareture_radius +
                 self.outer_appareture_radius) / 2.0
            t = (self.outer_appareture_radius -
                 self.inner_appareture_radius) / 2.0
            ring = imagen.SineGrating(
                mask_shape=imagen.Ring(thickness=t * 2.0,
                                       smoothing=0.0,
                                       size=r * 2.0),
                orientation=self.orientation,
                frequency=self.spatial_frequency,
                phase=self.current_phase,
                bounds=BoundingBox(radius=self.size_x / 2.0),
                offset=0,
                scale=2 * self.background_luminance * self.contrast / 100.0,
                xdensity=self.density,
                ydensity=self.density)()

            bg = imagen.Constant(bounds=BoundingBox(radius=self.size_x / 2.0),
                                 scale=self.background_luminance,
                                 xdensity=self.density,
                                 ydensity=self.density)()

            correction = imagen.Ring(smoothing=0.0,
                                     thickness=t * 2.0,
                                     size=r * 2.0,
                                     scale=-self.background_luminance,
                                     bounds=BoundingBox(radius=self.size_x /
                                                        2.0),
                                     xdensity=self.density,
                                     ydensity=self.density)()

            yield (numpy.add.reduce([ring, bg,
                                     correction]), [self.current_phase])
            self.current_phase += 2 * pi * (self.frame_duration /
                                            1000.0) * self.temporal_frequency
コード例 #11
0
class PatternCombine(TransferFn):
    """
    Combine the supplied pattern with one generated using a
    PatternGenerator.

    Useful for operations like adding noise or masking out lesioned
    items or around the edges of non-rectangular shapes.
    """

    generator = param.ClassSelector(imagen.PatternGenerator,
                                    default=imagen.Constant(),
                                    doc="""
        Pattern to combine with the supplied matrix.""")

    operator = param.Parameter(np.multiply,
                               precedence=0.98,
                               doc="""
        Binary Numeric function used to combine the two patterns.

        Any binary Numeric array "ufunc" returning the same type of
        array as the operands and supporting the reduce operator is
        allowed here.  See topo.pattern.Composite.operator for more
        details.
        """)

    def __call__(self, x):
        ###JABHACKALERT: Need to set it up to be independent of
        #density; right now only things like random numbers work
        #reasonably
        rows, cols = x.shape
        bb = BoundingBox(points=((0, 0), (rows, cols)))
        generated_pattern = self.generator(bounds=bb, xdensity=1,
                                           ydensity=1).transpose()
        new_pattern = self.operator(x, generated_pattern)
        x *= 0.0
        x += new_pattern
コード例 #12
0
    def frames(self):
        num_frames = 0
        while True:

            d1 = imagen.RawRectangle(offset=self.background_luminance,
                                     scale=2 * self.background_luminance *
                                     (self.relative_luminance - 0.5),
                                     bounds=BoundingBox(radius=self.size_x /
                                                        2),
                                     xdensity=self.density,
                                     ydensity=self.density,
                                     x=self.x,
                                     y=self.y,
                                     orientation=self.orientation,
                                     size=self.width,
                                     aspect_ratio=self.length / self.width)()

            d2 = imagen.RawRectangle(
                offset=1,
                scale=-1,
                bounds=BoundingBox(radius=self.size_x / 2),
                xdensity=self.density,
                ydensity=self.density,
                x=self.x,
                y=self.y,
                orientation=self.orientation,
                size=self.width,
                aspect_ratio=self.gap_length / self.width)()

            d3 = imagen.RawRectangle(
                offset=0,
                scale=self.background_luminance,
                bounds=BoundingBox(radius=self.size_x / 2),
                xdensity=self.density,
                ydensity=self.density,
                x=self.x,
                y=self.y,
                orientation=self.orientation,
                size=self.width,
                aspect_ratio=self.gap_length / self.width)()

            d4 = imagen.RawRectangle(
                offset=self.background_luminance,
                scale=2 * self.background_luminance *
                (self.relative_luminance - 0.5),
                bounds=BoundingBox(radius=self.size_x / 2),
                xdensity=self.density,
                ydensity=self.density,
                x=self.x,
                y=self.y,
                orientation=self.orientation + numpy.pi / 2,
                size=self.width,
                aspect_ratio=0.8 / self.width)()

            b = imagen.Constant(scale=self.background_luminance,
                                bounds=BoundingBox(radius=self.size_x / 2),
                                xdensity=self.density,
                                ydensity=self.density)()

            num_frames += 1
            if (num_frames - 1) * self.frame_duration < self.flash_duration:
                if self.relative_luminance > 0.5:
                    #yield (numpy.maximum(d4,numpy.add(numpy.multiply(d1,d2),d3)),[1])
                    yield (d4, [1])
                else:
                    yield (d4, [1])
                    #yield (numpy.minimum(d4,numpy.add(numpy.multiply(d1,d2),d3)),[1])
            else:
                yield (b, [0])