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
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])
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])
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])
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])
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))