Пример #1
0
    def afferent(self, src_properties, dest_properties):
        channel = dest_properties['SF'] if 'SF' in dest_properties else 1

        centerg = imagen.Gaussian(
            size=0.07385 * self.sf_spacing**(channel - 1),
            aspect_ratio=1.0,
            output_fns=[transferfn.DivisiveNormalizeL1()])
        surroundg = imagen.Gaussian(
            size=(4 * 0.07385) * self.sf_spacing**(channel - 1),
            aspect_ratio=1.0,
            output_fns=[transferfn.DivisiveNormalizeL1()])
        on_weights = imagen.Composite(generators=[centerg, surroundg],
                                      operator=numpy.subtract)
        off_weights = imagen.Composite(generators=[surroundg, centerg],
                                       operator=numpy.subtract)

        #TODO: strength=+strength_scale/len(cone_types) for 'On' center
        #TODO: strength=-strength_scale/len(cone_types) for 'Off' center
        #TODO: strength=-strength_scale/len(cone_types) for 'On' surround
        #TODO: strength=+strength_scale/len(cone_types) for 'Off' surround
        return Model.SharedWeightCFProjection.params(
            delay=0.05,
            strength=2.33 * self.strength_factor,
            name='Afferent',
            nominal_bounds_template=sheet.BoundingBox(
                radius=self.lgnaff_radius * self.sf_spacing**(channel - 1)),
            weights_generator=on_weights
            if dest_properties['polarity'] == 'On' else off_weights)
Пример #2
0
    def update_ibl(self):
        num = len(self.ibls)
        if num == 0:
            black = np.zeros((256, 512, 3))
            self.set_img(black)
            return

        gs = ig.Composite(operator=np.add,
                          generators=[
                              ig.Gaussian(
                                  size=self.ibls[i].radius,
                                  scale=self.ibls[i].scale,
                                  x=self.ibls[i].pos[0] - 0.5,
                                  y=self.ibls[i].pos[1] - 0.5,
                                  aspect_ratio=1.0,
                              ) for i in range(num)
                          ],
                          xdensity=512)

        self.ibl_img = np.repeat(gs()[:, :, np.newaxis], 3, axis=2)

        w = self.ibl_img.shape[1]
        tmp = self.ibl_img.copy()
        ret = tmp.copy()
        ret[:, :w // 2], ret[:, w // 2:] = tmp[:, w // 2:], tmp[:, :w // 2]

        plt.imsave("test_sharp.png", np.clip(ret, 0.0, 1.0))
        self.set_img(self.ibl_img)
        self.parent_handle.render_layers()
Пример #3
0
    def get_pattern(self, w, h, num=50, scale=3.0, size=0.1, energy=3500, mitsuba=False, seed=None, dataset=False):
        if seed is None:
            seed = random.randint(0,19920208)
        else:
            seed = seed + int(time.time())

        if num == 0:
            ibl = np.zeros((256,512))
        else:
            # factor = 80/256
            factor = 1.0
            gs = ig.Composite(operator=np.add,
                            generators=[ig.Gaussian(
                                        size=size*ng.UniformRandom(seed=seed+i+4),
                                        scale=scale*(ng.UniformRandom(seed=seed+i+5)+1e-3),
                                        x=ng.UniformRandom(seed=seed+i+1)-0.5,
                                        y=(ng.UniformRandom(seed=seed+i+2)-0.5)*factor,
                                        aspect_ratio=0.7,
                                        orientation=np.pi*ng.UniformRandom(seed=seed+i+3),
                                        ) for i in range(num)],
                                position=(0, 0), 
                                xdensity=512)
            ibl = self.normalize(gs(), energy) 
        
        # prepare to fix energy inconsistent
        if dataset:
            ibl = self.to_dataset(ibl, w, h)

        if mitsuba:
            return ibl, self.to_mts_ibl(np.copy(ibl))
        else:
            return ibl
Пример #4
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])
Пример #5
0
 def get_cur_ibl(self):
     num = len(self.ibl_cmds)
     if num == 0:
         return np.zeros((256, 512, 3))
     gs = ig.Composite(operator=np.add,
                       generators=[
                           ig.Gaussian(
                               size=self.ibl_cmds[i][2],
                               scale=self.ibl_cmds[i][3],
                               x=self.ibl_cmds[i][0] - 0.5,
                               y=self.ibl_cmds[i][1] - 0.5,
                               aspect_ratio=1.0,
                           ) for i in range(num)
                       ],
                       xdensity=512)
     return np.repeat(gs()[:, :, np.newaxis], 3, axis=2)
    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)()
Пример #7
0
    def get_ibl_numpy(self):
        num = len(self.ibls)
        gs = ig.Composite(operator=np.add,
                          generators=[
                              ig.Gaussian(
                                  size=self.ibls[i].radius,
                                  scale=self.ibls[i].scale,
                                  x=self.ibls[i].pos[0] - 0.5,
                                  y=self.ibls[i].pos[1] * 0.3 + 0.2,
                                  aspect_ratio=1.0,
                              ) for i in range(num)
                          ],
                          xdensity=512)

        # rotate by 180 degree
        tmp = gs()
        h, w = tmp.shape[0], tmp.shape[1]

        ret = tmp.copy()
        ret[:, :w // 2], ret[:, w // 2:] = tmp[:, w // 2:], tmp[:, :w // 2]
        return ret
Пример #8
0
# Sheets
retina = InputSheet('Retina',2.4,25,None)
lgn_on = NoTimeconstantSheet('LGN_ON',1.6,25,None)
lgn_off = NoTimeconstantSheet('LGN_OFF',1.6,25,None)
#V1 = Sheet('V1',1.0,50,0.002,threshold=float(sys.argv[4]))
V1 = HomeostaticSheet('V1',1.0,50,0.002,init_threshold=float(sys.argv[4]),mu=float(sys.argv[5]))

print sys.argv


#Projections
# DoG weights for the LGN
centerg   = imagen.Gaussian(size=0.07385,aspect_ratio=1.0,output_fns=[DivisiveNormalizeL1()])
surroundg = imagen.Gaussian(size=0.29540,aspect_ratio=1.0,output_fns=[DivisiveNormalizeL1()])
on_weights = imagen.Composite(generators=[centerg,surroundg],operator=numpy.subtract)
off_weights = imagen.Composite(generators=[surroundg,centerg],operator=numpy.subtract)


retina_to_lgn_on = FastConnetcionFieldProjection("RetinaToLgnOn",retina,lgn_on,1.0,0.001,0.375,on_weights)
retina_to_lgn_off = FastConnetcionFieldProjection("RetinaToLgnOff",retina,lgn_off,1.0,0.001,0.375,off_weights)

lgn_on_to_V1 = FastConnetcionFieldProjection("LGNOnToV1",lgn_on,V1,0.5,0.001,0.27083,imagen.random.GaussianCloud(gaussian_size=2*0.27083))
lgn_off_to_V1 = FastConnetcionFieldProjection("LGNOffToV1",lgn_off,V1,0.5,0.001,0.27083,imagen.random.GaussianCloud(gaussian_size=2*0.27083))

center_lat  = imagen.Gaussian(size=0.05,aspect_ratio=1.0,output_fns=[DivisiveNormalizeL1()],xdensity=V1.density+1,ydensity=V1.density+1,bounds = BoundingBox(radius=V1.size/2.0))()[14:-14,14:-14]
surround_lat = imagen.Gaussian(size=0.15,aspect_ratio=1.0,output_fns=[DivisiveNormalizeL1()],xdensity=V1.density+1,ydensity=V1.density+1,bounds = BoundingBox(radius=V1.size/2.0))()[14:-14,14:-14]
center_lat = center_lat / numpy.sum(center_lat)
surround_lat = surround_lat / numpy.sum(surround_lat)

V1_lat_exc = ConvolutionalProjection("LateralExc",V1,V1,0.5*float(sys.argv[1]),0.001,center_lat)