Retinal Model: Static Eye, X Cells

This is a model of the retina.  The current assumptions are that the eye is perfectly still and that the x cells, the only current cells modeled, can be characterized by DOG functions.

To start using this model, input any 8bit bitmapped image.  The size is limited by the power of your computer and your patience in waiting for output.  Give the path for the image.  But first load this matrix manipulation function.

<< LinearAlgebra`MatrixManipulation`

The Definition of a Ganglion Cell

This model is based upone the ganglion cells being modelled as 2-dimensional difference of gaussians function.
      The variable se is the standard deviation for the excitatory portion of the gaussian in the 2D DOG.
      The variable si is the standard deviation for the inhibitory protion of the gausian the the 2D DOG.
      width is the radius of the receptive field in x and y (or i and j).  It is sensitive to the size of the inhibitory region.  So currently these cells are all on center cells.

se  =  2; si = 6; width = 3*si

This step builds the model of the ganglion cell.  It is a two dimensional matrix giving a discrete approximation of the DOG function.  In this attempt to make the function work I am multiplying the amplitude by the ratio of the standard deviations (inhibitory/excitatory)  of the fields of the center to make up for the smaller area  of the central field.  This ratio adjusts the model to work for the added dimension.

ganglion = 
        Table[(((si/se))/((se)*(Sqrt[2*Pi]))) 
                Exp[-((((((i - width))^2) + (((j - width))^2)))/((2*
                            (se^2))))] - (1/((si)*(Sqrt[2*Pi]))) 
                Exp[-((((((i - width))^2) + (((j - width))^2)))/((2*(((si))^2))))] // N, {i, 2*width + 1}, {j, 2*width + 1}];

This step shows the size of the ganglion matrix.

Dimensions[ganglion]

You can output the ganglion cell if you wish with the text step.

Export["c:/mydocu~1/thefro~1/e2i6ganglioninversesquare.txt", 
      ganglion, "Table"]

This next next step plots your ganglion cell.

Show[SurfaceGraphics[ganglion], 
      PlotRange -> {Min[ganglion], Max[ganglion]}]

Filtering Through the Ganglion Cells

Below is the filtering of the input image through the retina.  A sub section is taken out of the input that matches the ganglion cell in size.  A point by point multiplication of the input by the DOG is done and then this output is summed up for one point on OpticNerve array.  Currently each gaglion cell is displayced by 5 steps first along the horzontal and then the vertical axes.

Input a Test Image

inpic = Import["c:/mydocu~1/thefro~1/circle.bmp"]; 
    retarray = inpic[[1, 1] ]; 
    Print["Dimensions of Input Array",  Dimensions[retarray]]; 
    bigdim = Dimensions[retarray]; 
    upi = IntegerPart[(bigdim[[1]] - (2*width + 1))/5]; 
    upj = IntegerPart[(bigdim[[2]] - (2*width + 1))/
          5];

Or Calculate a test Image

retarray = 
      Table[If[(Sqrt[(((i - 200))^2) + (((j - 200))^2)]) ≤ 38, 
          200, If[(Sqrt[(((i - 200))^2) + (((j - 200))^2)]) ≥ 
              180.75, 163, 
            209.5 - ((Sqrt[(((i - 200))^2) + (((j - 200))^2)]))/4]], {i, 
          400}, {j, 400}]; 
    Print["Dimensions of Input Array ",  Dimensions[retarray]]; 
    bigdim = Dimensions[retarray]; 
    upi = IntegerPart[(bigdim[[1]] - (2*width + 1))/5]; 
    upj = IntegerPart[(bigdim[[2]] - (2*width + 1))/
          5];

Max[retarray]
Min[retarray]

Show[
        SurfaceGraphics[retarray, ViewPoint  ->  {0, 0, 1000}, 
          Mesh -> False, Lighting -> False, 
          PlotRange -> {Min[retarray], Max[retarray]}]];

The command below output the input matrix in a space delimited table that can be used by other programs for analysis.

Export["c:/mydocu~1/thefro~1/JFin.txt", 
        retarray, "Table"];

The equation below calculates the ouput for each ganglion cell (currently spaced 5 receptors appart).  A submatix is taken out of the input that is the same size as the ganglion cell matrix.  A point by point mulitplicaiton (ganglion*SubMatrix[...]) is made and then those values are summed (thw two Apply[Plus, ...] commands, first columns then the resulting row).
Q is a variable to correct for the size of the ganglion cell.  As the spatial scale goes up, each larger cell will have more inputs thus in the sum it will have a larger sum just by that fact.  The dividing by the radius squared (width+.5 is the radius of the DOG). Corrects for this difference.  The 68 is a constant just to scale the output to convenient numbers.  I hope to make this value scale to more physiologically meaningful values eventually.

Q = (68/(((width +  .5))^2)); 
    OpticNerve = 
      Table[Q*Apply[Plus, 
            Apply[Plus, 
              ganglion*
                SubMatrix[
                  retarray, {(i - 1)*5 + 1, (j - 1)*5 + 
                      1}, {2*width + 1, 2*width + 1}]]], {i, 1, upi}, {j, 1, 
          upj}]; Print["Output of the Retina"]; 
    Show[SurfaceGraphics[OpticNerve]];

Max[OpticNerve]
Min[OpticNerve]

Show[SurfaceGraphics[OpticNerve], ViewPoint  ->  {0, 0, 1000}, 
        Mesh -> False, Lighting -> False];

This command will output the OpticNerve matrix as a space delimited text file.

Export["c:/mydocu~1/thefro~1/JFout.txt", 
      OpticNerve, "Table"]

If you want to see the input image, use the command below.

Print["Input Image"]; Show[inpic];

If you want to see a plot of the input image array, use the command below.

Show[SurfaceGraphics[retarray]];