{"id":16,"date":"2010-01-26T01:16:49","date_gmt":"2010-01-25T23:16:49","guid":{"rendered":"http:\/\/blog.teleranek.org\/?p=16"},"modified":"2025-06-29T12:29:29","modified_gmt":"2025-06-29T10:29:29","slug":"as3-pixelbender-and-neuro-science-experimentation","status":"publish","type":"post","link":"https:\/\/blog.teleranek.org\/?p=16","title":{"rendered":"AS3 PixelBender and Neuro Science experimentation"},"content":{"rendered":"<p>Several experiments with flash pixel bender kernels and neuroscience math.<br \/>\nFirst is the 2D grid of coupled neural oscillators ( the neuroscientific equivalent of usual coupled oscillators descripted by some differential equations. Nice example is a <a href=\"http:\/\/www.youtube.com\/watch?v=z3W5aw-VKKA\" target=\"_blank\" rel=\"noopener noreferrer\">double pendulum<\/a> on youtube ).<br \/>\nSo every pixel behaves like an oscillator and gives its energy to neighboring pixels. I&#8217;ve decided to store the energy in alpha component of 32 pixel.<br \/>\nOn every render action, I&#8217;m stripping this alpha component and showing only 24 bit pixels:<br \/>\n<code><br \/>\nmainBmp.bitmapData.applyFilter( mainBmp.bitmapData , mainBmp.bitmapData.rect , pt , shader );<br \/>\nbufBmp.bitmapData.copyPixels( mainBmp.bitmapData , mainBmp.bitmapData.rect , pt , null , null , false );<br \/>\n<\/code><br \/>\nThe last argument of copyPixels function tells flash to skip the alpha component. &#8220;shader&#8221; ( last argument of mainBmp&#8217;s applyFilter ) is the pixel bender filter.<br \/>\nThis is the .as source: <a href='http:\/\/exp.teleranek.org\/neuro_stuff\/bender_bio\/sine_pixel.as' target=\"_blank\" rel=\"noopener noreferrer\">sine_pixel.as<\/a><br \/>\nAnd this is the kernel source: <a href='http:\/\/exp.teleranek.org\/neuro_stuff\/bender_bio\/neur.pbk' target=\"_blank\" rel=\"noopener noreferrer\">neur.pbk<\/a><br \/>\nCompiled kernel: <a href='http:\/\/exp.teleranek.org\/neuro_stuff\/bender_bio\/neur.pbj' target=\"_blank\" rel=\"noopener noreferrer\">neur.pbj<\/a><\/p>\n<p><a href='http:\/\/exp.teleranek.org\/neuro_stuff\/bender_bio\/sine-lo.swf' target=\"_blank\" rel=\"noopener noreferrer\">CLICK<\/a> to see online simulation. Pretty cpu demanding, but it&#8217;s 256&#215;256 oscillators grid. Click and drag on the stage like you were drawing, to start oscillation ( in the beginning the grid is synchronized ).<br \/>\nThis is how it behaves in pure actionscript( flash player 10 needed, because I&#8217;ve optimized it using the Vector class ): <a href=\"http:\/\/exp.teleranek.org\/neuro_stuff\/bender_bio\/sine_waves.swf\" target=\"_blank\" rel=\"noopener noreferrer\">sine_waves.swf<\/a> &#8230; it has lower resolution though, 100&#215;100. ( <a href=\"http:\/\/exp.teleranek.org\/neuro_stuff\/bender_bio\/sine_waves.as\" target=\"_blank\" rel=\"noopener noreferrer\">source<\/a> )<\/p>\n<p>The big resolution version ( 512&#215;512 ): <a href=\"http:\/\/exp.teleranek.org\/neuro_stuff\/bender_bio\/sine-hi.swf\" target=\"_blank\" rel=\"noopener noreferrer\">sine-hi.swf<\/a>. CPU burning shader. I didn&#8217;t optimize it too much, maybe something can be changed to speed it up even more.<\/p>\n<p>Ok, so that was the oscillation. There&#8217;s one more thing &#8211; grid of Sodium-Potassium neurons from previous post. I wanted to check if it&#8217;s going to be faster with pixel bender. And indeed &#8211; it is.<br \/>\nThis is the <a href=\"http:\/\/exp.teleranek.org\/neuro_stuff\/bender_bio\/model.as\" target=\"_blank\" rel=\"noopener noreferrer\">source<\/a> . I&#8217;m simulating current and the neuron response:<br \/>\n<code><br \/>\nmainBmp.bitmapData.applyFilter( mainBmp.bitmapData , mainBmp.bitmapData.rect , pt , shader );<br \/>\n\t\t\tvBmp.bitmapData.copyChannel( mainBmp.bitmapData , mainBmp.bitmapData.rect , pt , BitmapDataChannel.RED, BitmapDataChannel.RED );<br \/>\n\t\t\tnBmp.bitmapData.copyChannel( mainBmp.bitmapData , mainBmp.bitmapData.rect , pt , BitmapDataChannel.BLUE, BitmapDataChannel.BLUE );<br \/>\n<\/code><br \/>\nOn every frame, I&#8217;m applying the shader on bitmap. Red component of pixel is the neuron response, green is the input current and blue is the gating variable. This time, I&#8217;m leaving alpha component alone. Because of this approach, I must copy RED channel from shaded bitmap to output bitmap, to see the graphical illustration of neuron response. The same thing happens with BLUE channel, which I copy to another bitmap. This is the kernel source: <a href=\"http:\/\/exp.teleranek.org\/neuro_stuff\/bender_bio\/model.pbk\" target=\"_blank\" rel=\"noopener noreferrer\">model.pbk<\/a>. And this is the compiled kernel: <a href=\"http:\/\/exp.teleranek.org\/neuro_stuff\/bender_bio\/model.pbj\" target=\"_blank\" rel=\"noopener noreferrer\">model.pbj<\/a><\/p>\n<p>Finally, 4 online demos. Try clicking the stage to generate some input current.<br \/>\n<a href=\"http:\/\/exp.teleranek.org\/neuro_stuff\/bender_bio\/n_v_small.swf\" target=\"_blank\" rel=\"noopener noreferrer\">256&#215;256 grid, first bitmap illustrates neuron response, second &#8211; gating var<\/a> ( click the left bitmap )<br \/>\n<a href=\"http:\/\/exp.teleranek.org\/neuro_stuff\/bender_bio\/n_v_big.swf\" target=\"_blank\" rel=\"noopener noreferrer\">The same as previous, but 512&#215;512 grid<\/a><br \/>\n<a href=\"http:\/\/exp.teleranek.org\/neuro_stuff\/bender_bio\/v_only.swf\" target=\"_blank\" rel=\"noopener noreferrer\">512&#215;512 neuron response grid<\/a><br \/>\n<a href=\"http:\/\/exp.teleranek.org\/neuro_stuff\/bender_bio\/n_only.swf\" target=\"_blank\" rel=\"noopener noreferrer\">512&#215;512 gating var grid<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Several experiments with flash pixel bender kernels and neuroscience math. First is the 2D grid of coupled neural oscillators ( the neuroscientific equivalent of usual coupled oscillators descripted by some differential equations. Nice example is a double pendulum on youtube ). So every pixel behaves like an oscillator and gives its energy to neighboring pixels. [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[18,44,43,47,46,42,45],"class_list":["post-16","post","type-post","status-publish","format-standard","hentry","category-flash-experiments","tag-as3","tag-kernel","tag-neuron-model","tag-neuroscience","tag-oscillators","tag-pixel-bender","tag-shader"],"_links":{"self":[{"href":"https:\/\/blog.teleranek.org\/index.php?rest_route=\/wp\/v2\/posts\/16","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.teleranek.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.teleranek.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.teleranek.org\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.teleranek.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=16"}],"version-history":[{"count":1,"href":"https:\/\/blog.teleranek.org\/index.php?rest_route=\/wp\/v2\/posts\/16\/revisions"}],"predecessor-version":[{"id":358,"href":"https:\/\/blog.teleranek.org\/index.php?rest_route=\/wp\/v2\/posts\/16\/revisions\/358"}],"wp:attachment":[{"href":"https:\/\/blog.teleranek.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=16"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.teleranek.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=16"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.teleranek.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=16"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}