Exemplo n.º 1
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
Exemplo n.º 2
0
    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
def Ring(x, y, BlackBackground, jetter, Bound):
    s = [0.5, 0.25]
    paras = zip([0] * 2, s, [1] * 2)

    if jetter:
        paras = pert.modulation(s, 'Ring')

    CR = np.empty(len(paras), dtype=np.object)
    idx = 0
    for par in paras:
        CR[idx] = ig.Ring(bounds=Bound,
                          smoothing=0.015,
                          aspect_ratio=par[2],
                          size=par[1],
                          thickness=0.05,
                          orientation=par[0],
                          xdensity=x,
                          ydensity=y)()
        if BlackBackground:
            assert CR[idx].max() <= 1.0 and CR[idx].min >= 0
            CR[idx] = 1 - CR[idx]
        idx += 1
    return CR
Exemplo n.º 4
0
ipython.magic("load_ext holoviews.ipython")
ipython.magic("opts Layout [vertical_spacing=0.0 horizontal_spacing=0.0] Image [show_xaxis=None show_yaxis=None show_frame=False show_title=False padding=0]")

def illusion(pat): 
    h, w = 256, 256
    uni = Image.new('RGB', (h,w))
    for i in range(0, w, bw):
        for j in range(0, h, bh):
            uni.paste(pat, (i, j))
    box = (50, 50, h-50, w-50)
    blur = uni.filter(ImageFilter.BLUR)
    blur = blur.crop(box)
    uni.paste(blur, box)
    return uni

shapes = [ig.Rectangle(), ig.RawRectangle(), ig.Ring(), ig.Disk()]
c = 0
for shape in shapes: 
    for i in range(-0.95, 0.01, 0.95):
        for j in range(-0.95,0.01, 0.95):
            shape.x = i
            shape.y = j

            c += 1
            hv.save(shape[:], 'illusion_image/blur/uniform/{}.png'.format(c));
            pat = Image.open('illusion_image/blur/uniform/{}.png'.format(c))
            pat = pat.resize((16,16))
            pat.save('illusion_image/blur/uniform/{}.png'.format(c))
            ill_0 = illusion(pat)
            ill_0.save('illusion_image/blur/blurred/{}.png'.format(c))