Пример #1
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])
def Bar(x, y, BlackBackground, jetter, Bound):
    orientations = [i * np.pi / 18 for i in range(18)] * 2
    sizes = [0.5] * 18 + [0.25] * 18
    ratio = [0.1] * 18 + [0.2] * 18
    paras = zip(orientations, sizes, ratio)

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

    Ba = np.empty(len(paras), dtype=np.object)
    idx = 0
    for par in paras:
        Ba[idx] = ig.Rectangle(bounds=Bound,
                               smoothing=0.015,
                               aspect_ratio=par[2],
                               size=par[1],
                               orientation=par[0],
                               xdensity=x,
                               ydensity=y)()
        if BlackBackground:
            assert Ba[idx].max() <= 1.0 and Ba[idx].min >= 0
            Ba[idx] = 1 - Ba[idx]
        idx += 1

    return Ba
    def function(self, p):
        gens = [
            ig.Rectangle(orientation=0,
                         smoothing=p.smoothing,
                         aspect_ratio=p.thickness / p.size,
                         size=p.size),
            ig.Rectangle(orientation=np.pi / 2,
                         smoothing=p.smoothing,
                         aspect_ratio=2 * p.thickness / p.size,
                         size=p.size / 2,
                         x=p.size / 4)
        ]

        return ig.Composite(generators=gens,
                            bounds=p.bounds,
                            orientation=p.orientation,
                            xdensity=p.xdensity,
                            ydensity=p.ydensity)()
def Bar(x, y, BlackBackground, jetter, Bound):
    orientations = [i * np.pi / 18 for i in range(18)]
    sizes = [0.5, 0.25]
    paras = list(itertools.product(orientations, sizes))
    if jetter:
        paras = pert.modulation_of_jetter(paras, 'Bar')

    Ba = np.empty(len(paras), dtype=np.object)
    idx = 0
    for par in paras:
        Ba[idx] = ig.Rectangle(bounds=Bound,
                               smoothing=0.015,
                               aspect_ratio=0.1,
                               size=par[1],
                               orientation=par[0],
                               xdensity=x,
                               ydensity=y)()
        if BlackBackground:
            assert Ba[idx].max() <= 1.0 and Ba[idx].min >= 0
            Ba[idx] = 1 - Ba[idx]
        idx += 1

    return Ba
Пример #5
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))