{"id":2030,"date":"2012-03-06T04:15:03","date_gmt":"2012-03-06T09:15:03","guid":{"rendered":"http:\/\/labrigger.com\/blog\/?p=2030"},"modified":"2012-03-03T14:57:00","modified_gmt":"2012-03-03T19:57:00","slug":"mouse-visual-stim","status":"publish","type":"post","link":"http:\/\/labrigger.com\/blog\/2012\/03\/06\/mouse-visual-stim\/","title":{"rendered":"Visual stimuli for mice"},"content":{"rendered":"<p align=\"center\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/labrigger.com\/blog\/wp-content\/uploads\/2012\/02\/fisheye.jpg\" alt=\"\" title=\"visStimMonitor\" width=\"600\" height=\"399\" class=\"aligncenter size-full wp-image-2045\" srcset=\"http:\/\/labrigger.com\/blog\/wp-content\/uploads\/2012\/02\/fisheye.jpg 600w, http:\/\/labrigger.com\/blog\/wp-content\/uploads\/2012\/02\/fisheye-300x199.jpg 300w\" sizes=\"auto, (max-width: 600px) 100vw, 600px\" \/><\/p>\n<p>By virtue of their small eyes, mice enjoy a large depth of field. In a classic experiment (buried in the methods section) <a href=\"http:\/\/www.ncbi.nlm.nih.gov\/pubmed\/7143036\">Balkema and Pinto<\/a> put +6, 0, and -7 diopter lenses in front of mouse eyes and measured no change in retinal ganglion cell receptive field sizes. Clearly there isn&#8217;t much of a need for accomodation with such depth of field, and indeed, an attempt to stain for ciliary accomodation muscles in mouse eyes came up with zip (<a href=\"http:\/\/www.ncbi.nlm.nih.gov\/pubmed\/13302815\">ref<\/a>). Therefore, visual stimuli can be placed over a large range of distances in front of mice and remain in focus.<\/p>\n<p>Since everything is in focus, it&#8217;s possible to place a visual stimulus monitor right in front of a mouse and cover a large amount of visual space. However, since the monitor is flat rather than spherical, the image will appear distorted from the mouse&#8217;s point of view. For example, a circle with a 100-pixel diameter in the middle of the screen will look larger and more circular than a 100-pixel diameter circle at the top left of the screen.<\/p>\n<p>It&#8217;s related to a simple <a href=\"http:\/\/en.wikipedia.org\/wiki\/Distortion_(optics)#Radial_distortion\">fisheye lens distortion<\/a>, like the photograph above, but a bit more complex since the monitor is tilted towards the animal. So we can&#8217;t apply a simple pincushion distortion (which is the inverse of a fisheye distortion) to correct for it. I&#8217;ve found that a straightforward approach is to simply model the monitor. At first, I thought this would be rather inelegant, but in practice, it&#8217;s very simple.<\/p>\n<p>Here I offer some MATLAB code that applies a corrective distortion to visual stimuli to cancel out the distortion caused by using a flat monitor to cover a large range of visual angle. With this code, you can treat the X-Y coordinates of a source image as angles of azimuth and elevation. The corrective distortion will change the image so that horizontal lines are mapped to isoelevation lines and vertical lines are mapped to isoazimuth lines.<\/p>\n<p><strong>Step one<\/strong> is to generate a 3D model of the monitor using some measurements that are easy to take. In the image below, on the left we have mapped pixel locations on the monitor in Cartesian coordinates relative to the mouse&#8217;s eye. On the right, we have re-mapped these to spherical coordinates. Using this data, we will generate an interpolation that applies the distortion.<\/p>\n<p align=\"center\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/labrigger.com\/blog\/wp-content\/uploads\/2012\/02\/monitormodel.png\" alt=\"\" title=\"monitormodel\" width=\"600\" height=\"517\" class=\"aligncenter size-full wp-image-2049\" srcset=\"http:\/\/labrigger.com\/blog\/wp-content\/uploads\/2012\/02\/monitormodel.png 600w, http:\/\/labrigger.com\/blog\/wp-content\/uploads\/2012\/02\/monitormodel-300x258.png 300w\" sizes=\"auto, (max-width: 600px) 100vw, 600px\" \/><\/p>\n<p><strong>Step two<\/strong> is to apply the distortion using interpolation. Here are a couple of example corrective distortions. On the left is the source image, on the right is the image after the corrective distortion. The curved lines will look straight from the mouse&#8217;s point of view.<\/p>\n<p align=\"center\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/labrigger.com\/blog\/wp-content\/uploads\/2012\/03\/eg1.png\" alt=\"\" title=\"eg1\" width=\"500\" height=\"169\" class=\"aligncenter size-full wp-image-2078\" srcset=\"http:\/\/labrigger.com\/blog\/wp-content\/uploads\/2012\/03\/eg1.png 500w, http:\/\/labrigger.com\/blog\/wp-content\/uploads\/2012\/03\/eg1-300x101.png 300w\" sizes=\"auto, (max-width: 500px) 100vw, 500px\" \/><\/p>\n<p align=\"center\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/labrigger.com\/blog\/wp-content\/uploads\/2012\/03\/eg2.png\" alt=\"\" title=\"eg2\" width=\"500\" height=\"166\" class=\"aligncenter size-full wp-image-2079\" srcset=\"http:\/\/labrigger.com\/blog\/wp-content\/uploads\/2012\/03\/eg2.png 500w, http:\/\/labrigger.com\/blog\/wp-content\/uploads\/2012\/03\/eg2-300x99.png 300w\" sizes=\"auto, (max-width: 500px) 100vw, 500px\" \/><\/p>\n<p>By the way, using similar code, you can check and see how the visual stimuli would appear to the mouse if it went uncorrected. Here are a couple of examples.<\/p>\n<p align=\"center\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/labrigger.com\/blog\/wp-content\/uploads\/2012\/03\/egB1.png\" alt=\"\" title=\"egB1\" width=\"500\" height=\"167\" class=\"aligncenter size-full wp-image-2086\" srcset=\"http:\/\/labrigger.com\/blog\/wp-content\/uploads\/2012\/03\/egB1.png 500w, http:\/\/labrigger.com\/blog\/wp-content\/uploads\/2012\/03\/egB1-300x100.png 300w\" sizes=\"auto, (max-width: 500px) 100vw, 500px\" \/><\/p>\n<p align=\"center\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/labrigger.com\/blog\/wp-content\/uploads\/2012\/03\/egB2.png\" alt=\"\" title=\"egB2\" width=\"500\" height=\"166\" class=\"aligncenter size-full wp-image-2087\" srcset=\"http:\/\/labrigger.com\/blog\/wp-content\/uploads\/2012\/03\/egB2.png 500w, http:\/\/labrigger.com\/blog\/wp-content\/uploads\/2012\/03\/egB2-300x99.png 300w\" sizes=\"auto, (max-width: 500px) 100vw, 500px\" \/><\/p>\n<p><a href=\"http:\/\/labrigger.com\/blog\/tag\/visual-stimuli\/\">More Labrigger posts on visual stimuli<\/a><\/p>\n<p><strong>Click through to get the MATLAB code\u2026.<\/strong><br \/>\n<!--more--><\/p>\n<p>This code will map the monitor coordinates into spherical coordinates from the mouse&#8217;s point of view. You can modify it with your own measurements.<\/p>\n<pre>\r\n<font size=0>\r\nclear all\r\n\r\n% Monitor size and position variables\r\nw = 56.69;  % width of screen, in cm\r\nh = 34.29;  % height of screen, in cm\r\ncx = w\/2;   % eye x location, in cm\r\ncy = 11.42; % eye y location, in cm\r\n\r\n% Distance to bottom of screen, along the horizontal eye line\r\nzdistBottom = 24.49;     % in cm\r\nzdistTop    = 14.18;     % in cm\r\n\r\n% Alternatively, you can specify the angle of the screen\r\n%screenAngle = 72.5;   % in degrees, measured from table surface in front of screen to plane of screen\r\n%zdistTop = zdistBottom - (h*sin(deg2rad(90-screenAngle)));\r\n\r\npxXmax = 200; % number of pixels in an image that fills the whole screen, x\r\npxYmax = 150; % number of pixels in an image that fills the whole screen, y\r\n\r\n% Internal conversions\r\ntop = h-cy;\r\nbottom = -cy;\r\nright = cx;\r\nleft = cx - w;\r\n\r\n% Convert Cartesian to spherical coord\r\n% In image space, x and y are width and height of monitor and z is the\r\n% distance from the eye. I want Theta to correspond to azimuth and Phi to\r\n% correspond to elevation, but these are measured from the x-axis and x-y\r\n% plane, respectively. So I need to exchange the axes this way, prior to\r\n% converting to spherical coordinates:\r\n% orig (image) -> for conversion to spherical coords\r\n% Z -> X\r\n% X -> Y\r\n% Y -> Z\r\n\r\n[xi,yi] = meshgrid(1:pxXmax,1:pxYmax);\r\ncart_pointsX = left + (w\/pxXmax).*xi;\r\ncart_pointsY = top - (h\/pxYmax).*yi;\r\ncart_pointsZ = zdistTop + ((zdistBottom-zdistTop)\/pxYmax).*yi;\r\n[sphr_pointsTh sphr_pointsPh sphr_pointsR] ...\r\n            = cart2sph(cart_pointsZ,cart_pointsX,cart_pointsY);\r\n\r\n% view results\r\nfigure\r\nsubplot(3,2,1)\r\nimagesc(cart_pointsX)\r\ncolorbar\r\ntitle('image\/cart coords, x')\r\nsubplot(3,2,3)\r\nimagesc(cart_pointsY)\r\ncolorbar\r\ntitle('image\/cart coords, y')\r\nsubplot(3,2,5)\r\nimagesc(cart_pointsZ)\r\ncolorbar\r\ntitle('image\/cart coords, z')\r\n\r\nsubplot(3,2,2)\r\nimagesc(rad2deg(sphr_pointsTh))\r\ncolorbar\r\ntitle('mouse\/sph coords, theta')\r\nsubplot(3,2,4)\r\nimagesc(rad2deg(sphr_pointsPh))\r\ncolorbar\r\ntitle('mouse\/sph coords, phi')\r\nsubplot(3,2,6)\r\nimagesc(sphr_pointsR)\r\ncolorbar\r\ntitle('mouse\/sph coords, radius')\r\n<\/font>\r\n<\/pre>\n<p>And here&#8217;s the code to try the distortion out.<\/p>\n<pre>\r\n<font size=0>\r\n%% try a distortion\r\n\r\n% make source image\r\ncheckSize = 5; % pixels per side of each check\r\nw = 100; % width, in pixels\r\nh = 75; % height, in pixels\r\nI = double(checkerboard(checkSize,round(h\/checkSize),round(w\/checkSize))>0.5);\r\n\r\n% alternate source image\r\n%I = zeros(150*4,200*4);\r\n%I(105*4:125*4,:)=0.2;\r\n%I(20*4:40*4,:)=0.4;\r\n\r\n% Rescale the Cartesian maps into dimensions of radians\r\nxmaxRad = max(sphr_pointsTh(:));\r\nymaxRad = max(sphr_pointsPh(:));\r\n\r\nfx = xmaxRad\/max(cart_pointsX(:));\r\nfy = ymaxRad\/max(cart_pointsY(:));\r\n\r\n% Apply the distortion via interpolation\r\nZI = interp2(cart_pointsX.*fx,cart_pointsY.*fy,I,sphr_pointsTh,sphr_pointsPh);\r\n\r\nh=figure;\r\nsubplot(1,2,1)\r\nimshow(I)\r\nsubplot(1,2,2)\r\nimshow(ZI)\r\n<\/font>\r\n<\/pre>\n<p>Here&#8217;s the line of code to use for the reverse transformation. To see what the visual stimulus would look like from the mouse&#8217;s point-of-view (MPOV) if it were not corrected.<\/p>\n<pre>\r\n<font size=0>\r\nZI_origMPOV = griddata(sphr_pointsTh,sphr_pointsPh,I,cart_pointsX.*fx,cart_pointsY.*fy);\r\n<\/font>\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p align=\"center\">\n<p>By virtue of their small eyes, mice enjoy a large depth of field. In a classic experiment (buried in the methods section) <a href=\"http:\/\/www.ncbi.nlm.nih.gov\/pubmed\/7143036\">Balkema and Pinto<\/a> put +6, 0, and -7 diopter lenses in&#8230;<\/p>\n<div class=\"read-more\"><a href=\"http:\/\/labrigger.com\/blog\/2012\/03\/06\/mouse-visual-stim\/\">Read More<\/a><\/div><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7],"tags":[26,11],"class_list":["post-2030","post","type-post","status-publish","format-standard","hentry","category-software","tag-matlab","tag-visual-stimuli"],"_links":{"self":[{"href":"http:\/\/labrigger.com\/blog\/wp-json\/wp\/v2\/posts\/2030","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/labrigger.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/labrigger.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/labrigger.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/labrigger.com\/blog\/wp-json\/wp\/v2\/comments?post=2030"}],"version-history":[{"count":21,"href":"http:\/\/labrigger.com\/blog\/wp-json\/wp\/v2\/posts\/2030\/revisions"}],"predecessor-version":[{"id":2090,"href":"http:\/\/labrigger.com\/blog\/wp-json\/wp\/v2\/posts\/2030\/revisions\/2090"}],"wp:attachment":[{"href":"http:\/\/labrigger.com\/blog\/wp-json\/wp\/v2\/media?parent=2030"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/labrigger.com\/blog\/wp-json\/wp\/v2\/categories?post=2030"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/labrigger.com\/blog\/wp-json\/wp\/v2\/tags?post=2030"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}