Beispiel #1
0
    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])
Beispiel #2
0
    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.Null(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
Beispiel #3
0
 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
Beispiel #4
0
 def frames(self):
     self.current_phase = 0
     while True:
         center = imagen.SineGrating(
             mask_shape=imagen.pattern.Disk(smoothing=0.0,
                                            size=self.center_radius * 2),
             orientation=self.center_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)()
         r = (self.center_radius + self.surround_radius + self.gap) / 2
         t = (self.surround_radius - self.surround_radius - self.gap) / 2
         surround = imagen.SineGrating(
             mask_shape=imagen.pattern.Ring(thickness=t,
                                            smoothing=0,
                                            size=r * 2),
             orientation=self.surround_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)()
         yield (numpy.add.reduce([center, surround]), [self.current_phase])
         self.current_phase += 2 * pi * (self.frame_duration /
                                         1000.0) * self.temporal_frequency
Beispiel #5
0
    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])
Beispiel #6
0
    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])
Beispiel #7
0
    def frames(self):

        f = open(self.eye_path_location, 'r')
        self.eye_path = pickle.load(f)
        self.time = 0
        self.current_phase = 0
        while True:
            location = self.eye_path[int(
                numpy.floor(self.frame_duration * self.time /
                            self.eye_movement_period))]

            image = imagen.SineGrating(
                orientation=self.orientation,
                x=location[0],
                y=location[1],
                frequency=self.spatial_frequency,
                phase=self.current_phase,
                bounds=BoundingBox(points=((-self.size_x / 2,
                                            -self.size_y / 2),
                                           (self.size_x / 2,
                                            self.size_y / 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)()
            self.current_phase += 2 * pi * (self.frame_duration /
                                            1000.0) * self.temporal_frequency
            yield (image, [self.time])
            self.time = self.time + 1
Beispiel #8
0
    def reference_frames(
        self,
        grid_size=default_noise["grid_size"],
        size_x=default_topo["size_x"],
        grid=default_noise["grid"],
        background_luminance=default_topo["background_luminance"],
        density=default_topo["density"],
    ):

        time_per_image = default_noise["time_per_image"]
        frame_duration = default_topo["frame_duration"]
        aux = imagen.random.SparseNoise(
            grid_density=grid_size * 1.0 / size_x,
            grid=grid,
            offset=0,
            scale=2 * background_luminance,
            bounds=BoundingBox(radius=size_x / 2),
            xdensity=density,
            ydensity=density,
            random_generator=numpy.random.RandomState(seed=self.experiment_seed),
        )
        while True:
            aux2 = aux()
            for i in range(time_per_image / frame_duration):
                yield (aux2, [0])
Beispiel #9
0
 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])
Beispiel #10
0
    def frames(self):
        self.current_phase = 0
        i = 0
        t = 0
        while True:
            i += 1
            st = 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)()
            if t > self.offset_time:
                st = st * 0 + self.background_luminance
            if t < self.onset_time:
                st = st * 0 + self.background_luminance

            yield (st, [self.current_phase])
            self.current_phase += 2 * pi * (self.frame_duration /
                                            1000.0) * self.temporal_frequency
            t = t + self.frame_duration
Beispiel #11
0
    def frames(self):
        self.time = 0
        f = open(self.eye_path_location, 'r')
        self.eye_path = pickle.load(f)
        self.pattern_sampler = imagen.image.PatternSampler(
            size_normalization='fit_longest',
            whole_pattern_output_fns=[imagen.image.DivisiveNormalizeLinf()])

        while True:
            location = self.eye_path[int(
                numpy.floor(self.frame_duration * self.time /
                            self.eye_movement_period))]
            image = imagen.image.FileImage(
                filename=self.image_location,
                x=location[0],
                y=location[1],
                orientation=0,
                xdensity=self.density,
                ydensity=self.density,
                size=self.size,
                bounds=BoundingBox(points=((-self.size_x / 2,
                                            -self.size_y / 2),
                                           (self.size_x / 2,
                                            self.size_y / 2))),
                scale=2 * self.background_luminance,
                pattern_sampler=self.pattern_sampler)()
            yield (image, [self.time])
            self.time += 1
Beispiel #12
0
    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])
Beispiel #13
0
    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])
Beispiel #14
0
    def frames(self):
        self.current_phase = 0
        while True:
            d = imagen.Disk(smoothing=0.0,
                            size=self.radius * 2,
                            offset=self.background_luminance,
                            scale=self.background_luminance *
                            (self.contrast / 100.0),
                            bounds=BoundingBox(radius=self.size_x / 2),
                            xdensity=self.density,
                            ydensity=self.density)()

            yield (d, [self.current_phase])
Beispiel #15
0
    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
Beispiel #16
0
    def frames(self):
        aux = imagen.random.DenseNoise(
            grid_density=self.grid_size * 1.0 / self.size_x,
            offset=0,
            scale=2 * self.background_luminance,
            bounds=BoundingBox(radius=self.size_x / 2),
            xdensity=self.density,
            ydensity=self.density,
            random_generator=numpy.random.RandomState(
                seed=self.experiment_seed))

        while True:
            aux2 = aux()
            for i in range(self.time_per_image / self.frame_duration):
                yield (aux2, [0])
Beispiel #17
0
 def frames(self):
     self.current_phase = 0
     i = 0
     while True:
         i += 1
         yield (imagen.SquareGrating(
             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)(), [self.current_phase])
         self.current_phase += 2 * pi * (self.frame_duration /
                                         1000.0) * self.temporal_frequency
Beispiel #18
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])