Simple Cell Demo
This is a demo project to make a neuron, a webcam and a loudspeaker interact in (approx) real-time. The goal is to conduct in computo what was done in vivo by Hubel & Wiesel.
Download the .app (Snow Leopard only).
The principle is that when you launch the script, the input flow coming from your iSight gets converted through a dummy retina (the big image on the right below represents the silhouette of a guy in front of the computer). The first frame is the receptive-field of the neuron (the small image on the bottom, here a sharp edge produced by showing the border of a sheet of paper). The membrane of the neuron is directly the instantaneous correlation coefficient between the RF and the present image, but modulated by a response curve "à la" Laughlin (1981) (see section 4 from Publications/Perrinet08spie ). (Note: The last version of the demo shows only the "webcam" pictures).
Basically the algorithm is :
1 def onTimer(self, evt): 2 im = retina(self.cam.get_frame()) # get a frame (snap 3 corr = numpy.sum(im[:] * self.RF[:]) # compute correlation 4 corr /= numpy.sqrt(numpy.sum(im[:]**2) * numpy.sum(self.RF[:]**2)) # normalize to a cosinus 5 6 if cumhist[int(((corr+1)/2) * self.quant)] > .8: # spike! 7 self.stream.write(self.spike) 8 9 # updates the histogram (computed over self.quant bins at rate self.rate: 10 self.hist[ int(((corr+1)/2) * self.quant) ] += self.rate 11 self.hist /= numpy.sum(self.hist) 12 13 14 def retina(image): 15 """ 16 dummy retina: 17 - color > grayscale 18 - smooth 19 - derive 20 21 """ 22 image = numpy.array(numpy.sum(image, axis =2),dtype='float') 23 image = scipy.ndimage.gaussian_filter(image, sigma = 2.) 24 image = scipy.ndimage.laplace(image) 25 return image
- This demo is written in python (I love python) + OpenCV.
check that it works with an interactive webcam
depends on !OpenCV which installs fine with MacPorts
sudo port install -u opencv +python26 +tbb
for the audio output, you will need to install the portaudio library:
svn co https://www.portaudio.com/repos/portaudio/trunk portaudio cd portaudio/ ./configure make sudo make install sudo /usr/bin/install -c -m 644 -m 644 ./include/pa_mac_core.h /usr/local/include/pa_mac_core.h
and the pyaudio module:
sudo easy_install pyaudio
- Simon B. Laughlin. A simple coding procedure enhances a neuron's information capacity. Zeitung für Naturforschung, 9--10(36):910--2, 1981 abstractThe contrast-response function of a class of first order interneurons in the fly's compound eye approximates to the cumulative probability distribution of contrast levels in natural scenes. Elementary information theory shows that this matching enables the neurons to encode contrast fluctuations most efficiently..