\(\(\( (*\ 
      Morphological\ Stability\ in\ Anti - Color\ and\ Super - 
        Color\ Diffusion\ *) \)\(
\)\( (*\ 
      Copyright\ May\ 2, \ \(2006\ \ \ \ Doug\ Youvan\ \ \ www . youvan . 
              com\  &\)\ www . pseudocolor . 
          com\ *) \)\(
\)\( (*\ 
      3  x3\ averaging\ every\ three\ followed\ by\ 2  
        x2\ averaging\ every\ three\ rows\ and\ columns\ *) \)\(
\)\( (*\ 
      This\ needs\ more\ comments\ *) \)\(
\)\(
\)\(\(name = 
        Table[i, {i, 1, 
            512}];\)\(
\)\(
\)
    \(bckrow =. \)\(
\)
    \(bckcol =. \)\(
\)
    \(newsum =. \)\(
\)
    \(ker1sum =. \)\(
\)
    \(gsum =. \)\(
\)\(
\)
    \(bckrow = Table[{x, y}, {x, 1, 512}, {y, 1, 512}];\)\(
\)
    \(bckcol = Table[{x, y}, {x, 1, 512}, {y, 1, 512}];\)\(
\)
    \(newsum = 
        Table[{x, y}, {x, 1, 512}, {y, 1, 512}];\)\(
\)
    \(ker1sum = 
        Table[{x, y}, {x, 1, 512}, {y, 1, 
            512}];\)\(
\)\(
\)
    \(bckrow[\([All, All]\)] = {0. , 0. , 0. };\)\(
\)
    \(bckcol[\([All, All]\)] = {0. , 0. , 0. };\)\(
\)
    \(newsum[\([All, All]\)] = {0. , 0. , 0. };\)\(
\)
    \(ker1sum[\([All, All]\)] = {0. , 0. , 
          0. };\)\(
\)\(
\)
    \(tup = Tuples[{\(-5.01\), \(-0.251\), 0.25, 5.0}, 3];\)\(
\)\( (*\ 
      pretty\ thin\ lines\ for\ triangles\ that\ are\ stable\ *) \)\(
\)\(
\)
    \(For[j = 1, j ≤ 64, \(j++\), indexj\  = \ 6*j; 
        bckcol[\([All, \((indexj + 64)\)]\)] = tup[\([j]\)]];\)\(\ \ \)\(
\)
    \(For[i = 1, i ≤ 64, \(i++\), indexi = 6*i; 
        bckrow[\([\((indexi + 64)\), All]\)] = 
          tup[\([i]\)]];\)\(
\)\(
\)
    \(newsum = bckrow + bckcol;\)\(
\)
    \(ker1sum = \ newsum;\)\(
\)\(
\)
    \(gsum = 
        Graphics[RasterArray[Apply[RGBColor, newsum, {2}]], 
          AspectRatio -> \ error, \ 
          ImageSize -> {512, 
              512}];\)\(\ \ \)\(
\)\(
\)
    \(Show[gsum];\)\(
\)\(
\)
    \(For[
loop = 1, \ 
      loop ≤ 
        40, \ \(loop++\), 

For[i = 1, 
        i ≤ 512, \(i++\), 
        For[j = 1, 
          j ≤ 
            512, \(j++\), 
If[\((\((0.  > 
                    newsum[\([i, j, 1]\)])\) || \((newsum[\([i, j, 1]\)] > 
                    1. )\) || 
\((0.  > 
                    newsum[\([i, j, 2]\)])\) || \((newsum[\([i, j, 2]\)] > 
                    1. )\) || 
\((0.  > 
                    newsum[\([i, j, 3]\)])\) || \((newsum[\([i, j, 3]\)] > 
                    1. )\))\), 
\((\ 
              newsum[\([i, j, 
                    1]\)] = \(newsum[\([i, j, 
                      2]\)] = \(newsum[\([i, j, 3]\)] = 
                    0. \)\))\)]]]; \ 


      gsum = Graphics[RasterArray[Apply[RGBColor, newsum, {2}]], 
          AspectRatio -> \ error, \ ImageSize -> {512, 512}]; \ \ 

      Show[gsum]; 

Export["D:\Mathematica\" <> \ 
          ToString[name[\([loop]\)]]\  <> \ ".gif", \ gsum, \ "GIF", 
        ImageSize -> {512, 
            512}]; 

newsum = 
        ker1sum; 

sumr = 0. ; 
sumg = 0. ; 

      sumb = 0. ; 


sumr = 
        newsum[\([All, \ All, \ 1]\)]; 

      sumg = newsum[\([All, \ All, \ 2]\)]; 

      sumb = newsum[\([All, \ All, 
            3]\)]; 

 (*pick\ off\ all\ 3 
           x3\ average\ them\ and\ replace\ their\ values\ with\ the\ average\ *) 


For[i = 2, 
        i ≤ 169, \(i++\), 
        For[j = 2, j ≤ 169, \(j++\), row = 3*i; col = 3*j; 
          summat = 0; 
          summat = 
sumr[\([row - 1, col - 1]\)] + 
              sumr[\([row - 1, col]\)] + 
              sumr[\([row - 1, col + 1]\)]
 + 
              sumr[\([row, col - 1]\)] + sumr[\([row, col]\)] + 
              sumr[\([row, col + 1]\)]
 + 
              sumr[\([row + 1, col - 1]\)] + sumr[\([row + 1, col]\)] + 
              sumr[\([row + 1, 
                  col + 1]\)]; 

sumr[\([row - 1, 
                col - 1]\)] = \(sumr[\([row - 1, 
                  col]\)] = \(sumr[\([row - 1, 
                    col + 1]\)] = \(sumr[\([row, 
                      col - 1]\)] = \(sumr[\([row, 
                        col]\)] = \(sumr[\([row, 
                          col + 1]\)] = \(sumr[\([row + 1, 
                            col - 1]\)] = \(sumr[\([row + 1, 
                              col]\)] = \(sumr[\([row + 1, col + 1]\)] = 
                            summat/
                              9\)\)\)\)\)\)\)\); 

summat = 0; 
          summat = 
sumg[\([row - 1, col - 1]\)] + 
              sumg[\([row - 1, col]\)] + 
              sumg[\([row - 1, col + 1]\)]
 + 
              sumg[\([row, col - 1]\)] + sumg[\([row, col]\)] + 
              sumg[\([row, col + 1]\)]
 + 
              sumg[\([row + 1, col - 1]\)] + sumg[\([row + 1, col]\)] + 
              sumg[\([row + 1, 
                  col + 1]\)]; 

sumg[\([row - 1, 
                col - 1]\)] = \(sumg[\([row - 1, 
                  col]\)] = \(sumg[\([row - 1, 
                    col + 1]\)] = \(sumg[\([row, 
                      col - 1]\)] = \(sumg[\([row, 
                        col]\)] = \(sumg[\([row, 
                          col + 1]\)] = \(sumg[\([row + 1, 
                            col - 1]\)] = \(sumg[\([row + 1, 
                              col]\)] = \(sumg[\([row + 1, col + 1]\)] = 
                            summat/
                              9\)\)\)\)\)\)\)\); 

summat = 0; 
          summat = 
sumb[\([row - 1, col - 1]\)] + 
              sumb[\([row - 1, col]\)] + 
              sumb[\([row - 1, col + 1]\)]
 + 
              sumb[\([row, col - 1]\)] + sumb[\([row, col]\)] + 
              sumb[\([row, col + 1]\)]
 + 
              sumb[\([row + 1, col - 1]\)] + sumb[\([row + 1, col]\)] + 
              sumb[\([row + 1, 
                  col + 1]\)]; 

sumb[\([row - 1, 
                col - 1]\)] = \(sumb[\([row - 1, 
                  col]\)] = \(sumb[\([row - 1, 
                    col + 1]\)] = \(sumb[\([row, 
                      col - 1]\)] = \(sumb[\([row, 
                        col]\)] = \(sumb[\([row, 
                          col + 1]\)] = \(sumb[\([row + 1, 
                            col - 1]\)] = \(sumb[\([row + 1, 
                              col]\)] = \(sumb[\([row + 1, col + 1]\)] = 
                            summat/
                              9\)\)\)\)\)\)\)\)]]; 

 (*\ 
        2  x2\ averaging\ of\ four\ 3  x3' 
          s\ corners\ *) 

For[i = 2, 
        i ≤ 169, \(i++\), 
        For[j = 2, j ≤ 169, \(j++\), row = 3*i; 
          col = 3*j; 
summat = 0; 
          summat = 
sumr[\([row + 1, col + 1]\)] + 
              sumr[\([row + 1, col + 2]\)] + sumr[\([row + 2, col + 1]\)] + 
              sumr[\([row + 2, col + 2]\)]; 
sumr[\([row + 
                  1, col + 1]\)] = \(sumr[\([row + 1, 
                  col + 2]\)] = \(sumr[\([row + 2, 
                    col + 1]\)] = \(sumr[\([row + 2, col + 2]\)] = 
                  summat/4\)\)\); 

summat = 0; 
          summat = 
sumg[\([row + 1, col + 1]\)] + 
              sumg[\([row + 1, col + 2]\)] + sumg[\([row + 2, col + 1]\)] + 
              sumg[\([row + 2, col + 2]\)]; 
sumg[\([row + 
                  1, col + 1]\)] = \(sumg[\([row + 1, 
                  col + 2]\)] = \(sumg[\([row + 2, 
                    col + 1]\)] = \(sumg[\([row + 2, col + 2]\)] = 
                  summat/4\)\)\); 

summat = 0; 
          summat = 
sumb[\([row + 1, col + 1]\)] + 
              sumb[\([row + 1, col + 2]\)] + sumb[\([row + 2, col + 1]\)] + 
              sumb[\([row + 2, col + 2]\)]; 
sumb[\([row + 
                  1, col + 1]\)] = \(sumb[\([row + 1, 
                  col + 2]\)] = \(sumb[\([row + 2, 
                    col + 1]\)] = \(sumb[\([row + 2, col + 2]\)] = 
                  summat/4\)\)\);

]]; 

For[i = 1, i ≤ 510, \(i++\), 
        For[j = 1, 
          j ≤ 
            510, \(j++\), 
newsum[\([i, 
                j]\)] = {sumr[\([i, j]\)], sumg[\([i, j]\)], 
              sumb[\([i, 
                  j]\)]}]]; 

ker1sum = 
        newsum;

]\)\( (*\ 
      end\ of\ big\ loop\ *) \)\)\)\)