{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Misc notes" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Barry's data is mostly from from 3 deg to 8 deg of eccentricity; most cells around 5 deg eccentricity. There is a nonlinear relationships between retinal eccentricity (in $mm$) and visual angle (in $deg$) in macaque, see see https://www.ncbi.nlm.nih.gov/pmc/articles/PMC50193/. A polynomial fit is given by\n", "\\begin{eqnarray}\n", "A = a + b E + c E^2\n", "\\end{eqnarray}\n", "with, $a = 0.1$, $b = 4.21$, and $c = 0.038$. Here A is eccentricity in $deg$, and E is eccentricity in $mm$. Using this equation, the cells are situated between $0.7$mm to $1.8$mm, mostly around $1.2$mm.\n", "\n", "Taking the derivative of the quation, one gets the magnification factor\n", "\\begin{eqnarray}\n", "\\frac{dA}{dE} = b + 2cE \\qquad\\text{ in deg/mm}\n", "\\end{eqnarray}\n", "Evaluating this at $E=1.2\\,[0.7,\\,1.8]$mm, the range of manification factors is $4.30\\,[4.26,\\,4.35]$deg/mm. Inverting yields \n", "\\begin{eqnarray}\n", " s = 0.232 [0.235,0.230] \\text{mm/deg}\n", "\\end{eqnarray}\n", "\n", "The field of view is 256 px and 4.6degree across. Therefore\n", "* 256px are 4.6deg $\\to$ 56px per 1deg\n", "* 256px are $s*4.6\\text{deg}=1.07[1.06, 1.08]$mm $\\to$ 48px are 0.2mm" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "import numpy as np\n", "import cv2 as cv2\n", "import pylab as pl\n", "from matplotlib import cm" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "# Import the movie to show in comparison" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [], "source": [ "frame_raw = np.ones((3,256,256,4500))\n", "\n", "vidcap = cv2.VideoCapture('../../1x10_256.mpg')\n", "success, image = vidcap.read()\n", "counter = 0\n", "success = True\n", "while success and (counter < 4500): # 4500 to only process first 2.5 min *60sec *30fps in the mpg -> 30sec ret video\n", " success, image = vidcap.read()\n", " \n", " #Raw RGB values\n", " im_rgb = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)\n", "\n", " red = np.double(im_rgb[:,:,0])\n", " green = np.double(im_rgb[:,:,1])\n", " blue = np.double(im_rgb[:,:,2])\n", " \n", " #Save luminance frame\n", " frame_raw[:,:,:,counter] = np.array([red/256., green/256., blue/256.])\n", " counter += 1" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [], "source": [ "# Parse the npy file to show model prediction" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [], "source": [ "filtered_frames = np.load(\"./Gon-19829503-frames.npy\")" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [], "source": [ "startframe = 600 #1sec before video begins at 150fps\n", "\n", "for idx in range(startframe,4500):\n", " \n", "\n", " cell_frame = filtered_frames[:,:,idx]\n", " cell_frame[230:240,180:(180+48)] = 10 # 0.2 mm\n", "\n", " fig, axes = pl.subplots(nrows=1, ncols=2, figsize=(7, 4))\n", " \n", " r = np.reshape(frame_raw[0,:,:,idx],(256, 256))\n", " g = np.reshape(frame_raw[1,:,:,idx],(256, 256))\n", " b = np.reshape(frame_raw[2,:,:,idx],(256, 256))\n", "\n", " img = np.zeros((256,256,3))\n", " img[:,:,0] = np.array(r, dtype = np.float)\n", " img[:,:,1] = np.array(g, dtype = np.float)\n", " img[:,:,2] = np.array(b, dtype = np.float)\n", "\n", " img[230:240,180:(180+56),0] = 1 # 1 deg scale bar\n", " img[230:240,180:(180+56),1] = 1\n", " img[230:240,180:(180+56),2] = 1\n", " \n", " axes[0].imshow(img)\n", " axes[0].set_title(\"Video\")\n", " axes[0].axes.xaxis.set_ticklabels([])\n", " axes[0].axes.yaxis.set_ticklabels([])\n", " axes[0].text(x=182,y=220, s = \"1 deg\", fontsize=15, color = 'w')\n", "\n", " axes[1].imshow(cell_frame, vmin=0, vmax=1, cmap=cm.Greys_r)\n", " axes[1].set_title(\"PC-Gon-cell\")\n", " axes[1].axes.xaxis.set_ticklabels([])\n", " axes[1].axes.yaxis.set_ticklabels([])\n", " axes[1].text(x=20,y=30, s = \"time = \"+str(np.floor((idx-startframe)/150*1000)/1000)+\"s\", fontsize=15,color = 'w')\n", " axes[1].text(x=170,y=220, s = \"0.2 mm\", fontsize=15, color = 'w')\n", "\n", " fig.tight_layout()\n", "\n", " pl.savefig(\"./video_frames/file%04d.png\" % (idx-startframe))\n", " pl.close()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Make into movie:\n", "\n", "ffmpeg -r 60 -f image2 -s 504x288 -i ./video_frames/file%04d.png -vcodec libx264 -crf 5 -pix_fmt yuv420p simulation.mp4" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.7.8" } }, "nbformat": 4, "nbformat_minor": 2 }