def filtered(w=250):
  """
  In this example we filter the image into several channels using gabor filters. L6 activity is used to select
  one of those channels. Only activity selected by those channels burst.
  """
  # prepare filter bank kernels
  kernels = []
  for theta in range(4):
    theta = theta / 4. * np.pi
    for sigma in (1, 3):
      for frequency in (0.05, 0.25):
        kernel = np.real(gabor_kernel(frequency, theta=theta,
                                      sigma_x=sigma, sigma_y=sigma))
        kernels.append(kernel)

  print("Initializing thalamus")

  t = Thalamus(
    trnCellShape=(w, w),
    relayCellShape=(w, w),
    inputShape=(w, w),
    l6CellCount=128*128,
    trnThreshold=15,
  )


  ff = loadImage(t)

  for i,k in enumerate(kernels):
    plotActivity(k, "kernel"+str(i)+".jpg", "Filter kernel", vmax=k.max(),
                 vmin=k.min())
    filtered0 = power(ff, k)
    ft = np.zeros((w, w))
    ft[filtered0 > filtered0.mean() + filtered0.std()] = 1.0
    plotActivity(ft, "filtered"+str(i)+".jpg", "Filtered image", vmax=1.0)

  encoder = createLocationEncoder(t, w=17)
  trainThalamusLocations(t, encoder)

  filtered0 = power(ff, kernels[3])
  ft = np.zeros((w, w))
  ft[filtered0 > filtered0.mean() + filtered0.std()] = 1.0

  # Get a salt and pepper burst ready image
  print("Getting unions")
  l6Code = list(getUnionLocations(encoder, 125, 125, 150, step=10))
  print("Num active cells in L6 union:", len(l6Code),"out of", t.l6CellCount)
  ffOutput = inferThalamus(t, l6Code, ft)
  plotActivity(t.burstReadyCells, "relay_burstReady_filtered.jpg",
               title="Burst-ready cells",
               )
  plotActivity(ffOutput, "cajal_relay_output_filtered.jpg",
               title="Filtered activity",
               cmap="Greys")

  # Get a more detailed filtered image
  print("Getting unions")
  l6Code = list(getUnionLocations(encoder, 125, 125, 150, step=3))
  print("Num active cells in L6 union:", len(l6Code),"out of", t.l6CellCount)
  ffOutput_all = inferThalamus(t, l6Code, ff)
  ffOutput_filtered = inferThalamus(t, l6Code, ft)
  ffOutput3 = ffOutput_all*0.4 + ffOutput_filtered
  plotActivity(t.burstReadyCells, "relay_burstReady_all.jpg",
               title="Burst-ready cells",
               )
  plotActivity(ffOutput3, "cajal_relay_output_filtered2.jpg",
               title="Filtered activity",
               cmap="Greys")
In this example we filter the image into several channels using gabor filters. L6 activity is used to select
  one of those channels. Only activity selected by those channels burst.