[Question]
  [
Given a non-empty rectangular array of integers from `0` to `9`, output the amount of cells that are `8` and do not have a neighbour that is `8`. Neighbouring is here understood in the [Moore sense](https://en.wikipedia.org/wiki/Moore_neighborhood), that is, including diagonals. So each cell has `8` neighbours, except for cells at the edges of the array.
For example, given the input
```
8 4 5 6 5
9 3 8 4 8
0 8 6 1 5
6 7 9 8 2
8 8 7 4 2
```
the output should be `3`. The three qualifying cells would be the following, marked with an asterisk (but only the amount of such entries should be output):
```
* 4 5 6 5
9 3 8 4 *
0 8 6 1 5
6 7 9 * 2
8 8 7 4 2
```
## Additional rules
* You can optionally take two numbers defining the size of the array as additional inputs.
* Input can be taken by [any reasonable means](https://codegolf.meta.stackexchange.com/questions/2447/default-for-code-golf-input-output-methods). The format is flexible as usual. For example, it can be a 2D character array, or a list of lists of numbers, or a flat list.
* [Programs or functions](http://meta.codegolf.stackexchange.com/a/2422/36398) are allowed, in any [programming language](https://codegolf.meta.stackexchange.com/questions/2028/what-are-programming-languages/2073#2073). [Standard loopholes](https://codegolf.meta.stackexchange.com/questions/1061/loopholes-that-are-forbidden-by-default) are forbidden.
* Shortest code in bytes wins.
## Test cases
1. Input:
```
8 4 5 6 5
9 3 8 4 8
0 8 6 1 5
6 7 9 8 2
8 8 7 4 2
```
Output: `3`
2. Input
```
8 8
2 3
```
Output: `0`
3. Input:
```
5 3 4
2 5 2
```
Output: `0`
4. Input:
```
5 8 3 8
```
Output: `2`
5. Input:
```
8
0
8
```
Output: `2`.
6. Input:
```
4 2 8 5
2 6 1 8
8 5 5 8
```
Output: `1`
7. Input:
```
4 5 4 3 8 1 8 2
8 2 7 7 8 3 9 3
9 8 7 8 5 4 2 8
4 5 0 2 1 8 6 9
1 5 4 3 4 5 6 1
```
Output `3`.
8. Input:
```
8
```
Output: `1`
9. Input:
```
8 5 8 1 6 8 7 7
9 9 2 8 2 7 8 3
2 8 4 9 7 3 2 7
9 2 9 7 1 9 5 6
6 9 8 7 3 1 5 2
1 9 9 7 1 8 8 2
3 5 6 8 1 4 7 5
```
Output: `4`.
10. Input:
```
8 1 8
2 5 7
8 0 1
```
Output: `3`.
Inputs in MATLAB format:
```
[8 4 5 6 5; 9 3 8 4 8; 0 8 6 1 5; 6 7 9 8 2; 8 8 7 4 2]
[8 8; 2 3]
[5 3 4; 2 5 2]
[5 8 3 8]
[8; 0; 8]
[4 2 8 5; 2 6 1 8; 8 5 5 8]
[4 5 4 3 8 1 8 2; 8 2 7 7 8 3 9 3; 9 8 7 8 5 4 2 8; 4 5 0 2 1 8 6 9; 1 5 4 3 4 5 6 1]
[8]
[8 5 8 1 6 8 7 7; 9 9 2 8 2 7 8 3; 2 8 4 9 7 3 2 7; 9 2 9 7 1 9 5 6; 6 9 8 7 3 1 5 2; 1 9 9 7 1 8 8 2; 3 5 6 8 1 4 7 5]
[8 1 8; 2 5 7; 8 0 1]
```
Inputs in Python format:
```
[[8, 4, 5, 6, 5], [9, 3, 8, 4, 8], [0, 8, 6, 1, 5], [6, 7, 9, 8, 2], [8, 8, 7, 4, 2]]
[[8, 8], [2, 3]]
[[5, 3, 4], [2, 5, 2]]
[[5, 8, 3, 8]]
[[8], [0], [8]]
[[4, 2, 8, 5], [2, 6, 1, 8], [8, 5, 5, 8]]
[[4, 5, 4, 3, 8, 1, 8, 2], [8, 2, 7, 7, 8, 3, 9, 3], [9, 8, 7, 8, 5, 4, 2, 8], [4, 5, 0, 2, 1, 8, 6, 9], [1, 5, 4, 3, 4, 5, 6, 1]]
[[8]]
[[8, 5, 8, 1, 6, 8, 7, 7], [9, 9, 2, 8, 2, 7, 8, 3], [2, 8, 4, 9, 7, 3, 2, 7], [9, 2, 9, 7, 1, 9, 5, 6], [6, 9, 8, 7, 3, 1, 5, 2], [1, 9, 9, 7, 1, 8, 8, 2], [3, 5, 6, 8, 1, 4, 7, 5]]
[[8, 1, 8], [2, 5, 7], [8, 0, 1]]
```
Outputs:
```
3, 0, 0, 2, 2, 1, 3, 1, 4, 3
```
  
[Answer]
# [R](https://www.r-project.org/), ~~117 63~~ 59 bytes
```
function(m)sum(colSums(as.matrix(dist(which(m==8,T)))<2)<2)
```
[Try it online!](https://tio.run/##hVJdb5wwEHznV6zoi1F9bew750DKPfa9StOny6lKKAdIfAkbhVPb335dr23SNkiVANm7ntmZMeP1HXy@mKrvNtpcmgLqbpgMmB7uoX0yYz1Hw5CXcoS7DZynLjd137E5gR8RwGyLpZ6eWQwxj2M@J1jtvo39i7atpuhKU2k2FiVy5VWh2cyhxG0xDyOLHx@PMYc5SRLYgCBo3jcEZf/D8oB8DyKBj36q5ZhaYtBmNH3Npq6ptWG400NTG@bk5j9xNr4nZImJiVsHyIcMzjezRNzzci@Nw/MF93CAh/uvn5LoVxSdD9cllzbRU8vw4BfEsif9wVN9txJeqjqvWHs4pPwBB91J@1zPzOXL4uMx5bDjoDjc4vfE4Zhx2HJw5dQWbmiHbeFP4HLPIaOytIWUlnuCyNMJLUX/jCAiicxvu4rm7fwBtcqgaICVtcJOGknG26YVRFjl@Z2N1KtW9KzjFNlxUYi/vEryug@abGA@uDSUHVj6SY7thgoipJnZjvhjznINYs3kWqoqiLsNo/deSBZ8y0WoD8BdbEblret7jAxlQQurxd/24mzrfgIfhTu3YNLXkLbBipO3oyNq1YN4/TmU15JSVi6F628 "R – Try It Online")
`dist` computes distances (default is Euclidean) among rows of a matrix. `which` with second argument `TRUE` returns the coordinates where the predicate is true. 
Coordinates are neighbours if the distance between them is not more than the square root of 2, but the inner `<2` is good enough because the possible distance jumps from `sqrt(2)` ro `2`.
[Answer]
# [APL (Dyalog Classic)](https://www.dyalog.com/), ~~29~~ ~~28~~ 25 bytes
```
≢∘⍸16=2⊥¨3,⌿3,/8=(⍉0,⌽)⍣4
```
[Try it online!](https://tio.run/##TVHBSsNAFLz3K/aWBFLM7mbTjdCPCZVKMVCxvYh4ESm2GtGD4FVF6A8IIojgp7wfiTMbS0Ng895kdmbeS3VaD4/Oq3p@PJzU1WIxm7Ry/zSby@oha6c4Zf0qN8/SfOpibGTz/ru1qdz92PTAj2Np1hm670Sat7xtl@BfSPMh65czlFNpvg6j@Ukkt9fRtJrVEQB8Prsc2KU0W1k9xl7lyqlCuSQulVVsfRJnKAqliRZqpEq0JgHXo8lRDrL9fdCNsj3IQScn6Mg0OziVzZWDAkz6KK6nWcL3QO9AWIDoqMEUntYODzh2z3GIwsR6l84g3Sg4YBTO40NLnqEIr2QodZiuTGL9r9GtQPcSMCwj5fs5XbAqguiI6mVIaTpLZuXySrSWIBkmtBon9LnKLpLlZhmZXzqG72awIQh9csAu6f8n3W3aUdpjDsQd/gE "APL (Dyalog Classic) – Try It Online")
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), ~~18~~ 15 bytes
```
8=µ+Ż+ḊZµ⁺ỊṖḋµS
```
[Try it online!](https://tio.run/##VVG7bcMwEO09BXuzMCmdRRaewp0FlWkCL5AyaQI4faZIK8CfToYHkRdhyHd3VAIYBvV473d8fTke31IKu2lcP27r@Xw6TOPz/TrfTvPlez5/TeM@3T@fHz8p9X0frGmtIWu2@X@wpo/WNNYwHAqwwVe@djKRj501EbAvQMCxA8UPw8pCFmSf1Rgh6LYCUp0kkIulMOEJWQaKKGZIuBwliDPht8wSYnAF9y@jR8ZO/UpRKRwUZrIXdVbbAHC6hVhu3B@fuj6nBXQDpCG2atGJYdROvgaScrz4CLjhe@F4hR0OxVNeozZo@JGkMs9VTliW0WhkjtdihGputzweiX/AHnLD4Rc "Jelly – Try It Online")
### How it works
```
8=µ+Ż+ḊZµ⁺ỊṖḋµS    Main link (monad). Input: digit matrix
8=              1) Convert elements by `x == 8`
  µ             2) New chain:
   +Ż+Ḋ              x + [0,*x] + x[1:] (missing elements are considered 0)
                     Effectively, vertical convolution with [1,1,1]
       Z             Transpose
        µ⁺      3) Start new chain, apply 2) again
          ỊṖ       Convert elements by `|x| <= 1` and remove last row
            ḋ      Row-wise dot product with result of 1)
             µS 4) Sum
```
# Previous solution, 18 bytes
```
æc7B¤ZḊṖ
8=µÇÇỊḋµS
```
[Try it online!](https://tio.run/##VVE7TgMxEO1zCh/ARezdie2ChivQsdoK0aBcgJZmpdBzAkRFGyko3e5JNhcx9psZL0hR5H2e9xu/PB@PrzkvX0/hfv58XC@n9edjF@/m8zIt03o9rZf3@fyQl@n29p3zMAzRmt4asuZQ/kdrhmRNZw3DsQJ7fJVrJxPlGKxJgH0FIo4BFD@OOwtZkH1RY4Sg2wtIbZJArpbChCdkGaiimCHhcpQozoTfNkuIwRXcv4weGYP61aJSOCrMZC/qrLYH4HQLqd64Pz5tfU4L6AZIQxzUIohh0k6@BZJyvPgEuON74XiFHQ7VU16jNej4kaQyzzVO3JbRaWSO12OEWm63PR6Jf8QeSsPxFw "Jelly – Try It Online")
Wanted to share another approach, though this is 1 byte longer than [Jonathan Allan's solution](https://codegolf.stackexchange.com/a/175727/78410).
### How it works
```
æc7B¤ZḊṖ    Auxiliary link (monad). Input: integer matrix
æc7B¤       Convolution with [1,1,1] on each row
     ZḊṖ    Zip (transpose), remove first and last elements
8=µÇÇỊḋµS    Main link (monad). Input: digit matrix
8=           Convert 8 to 1, anything else to 0 (*A)
  µÇÇ        Apply aux.link twice (effective convolution with [[1,1,1]]*3)
     Ịḋ      Convert to |x|<=1, then row-wise dot product with A
       µS    Sum the result
```
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), 17 [bytes](https://github.com/DennisMitchell/jelly/wiki/Code-page)
```
=8ŒṪµŒcZIỊȦƲƇẎ⁸ḟL
```
**[Try it online!](https://tio.run/##y0rNyan8/9/W4uikhztXHdp6dFJylOfD3V0nlh3bdKz94a6@R407Hu6Y7/P/4e4tD3dsetS0Juxw@///JgqmCiYKxgoWCoZAbMQFxArmQGgBFLNUMOayBLJAPJAqIwULLpB6AyALpNpMwZLLEKofJG6mYAgA "Jelly – Try It Online")** Or see the [test-suite](https://tio.run/##VVE7TgMxEO05hQ/gIvbuZO2CAyBxAlZboTRRLkAJTSQKilyAjgJRIUVKoCNKlGtsLmLsNzNekKLI@zzvN14uVquHlK7DcTPu33@2x8393c34/Xx@O32e1uPXy@VxN@5eb9NhfXn6SKnv@2BNaw1ZM8//gzV9tKaxhuFQgBm@8rWTiXzsrImAfQECjh0ofhiuLGRB9lmNEYJuKyDVSQK5WAoTnpBloIhihoTLUYI4E37TLCEGV3D/Mnpk7NSvFJXCQWEme1FntRkAp1uI5cb98anrc1pAN0AaYq4WnRhG7eRrICnHi4@AG74XjlfY4VA85TVqg4YfSSrzXOWEaRmNRuZ4LUao5nbT45H4B@whNxx@AQ "Jelly – Try It Online").
### How?
```
=8ŒṪµŒcZIỊȦƲƇẎ⁸ḟL - Link: list of lists of integers (digits)
=8                - equals 8?
  ŒṪ              - multidimensional truthy indices (pairs of row & column indices of 8s)
    µ             - start a new monadic chain
     Œc           - all pairs (of the index-pairs) 
            Ƈ     - filter keep if:  (keep those that represent adjacent positions)
           Ʋ      -   last four links as a monad:
       Z          -     transpose
        I         -     incremental differences
         Ị        -     insignificant? (abs(x) <= 1)
          Ȧ       -     all?
             Ẏ    - tighten (to a list of all adjacent 8's index-pairs, at least once each)
              ⁸   - chain's left argument (all the index-pairs again)
               ḟ  - filter discard (remove those found to be adjacent to another)
                L - length (of the remaining pairs of indices of single 8s)
```
[Answer]
# [JavaScript (Node.js)](https://nodejs.org), ~~88~~ 85 bytes
```
a=>g=(x,y=0,c=0)=>a.map(p=>p.map((q,j)=>c+=q-8?0:1/x?(x-j)**2+y*y<3:g(j,-y)<2)&--y)|c
```
[Try it online!](https://tio.run/##dVHbboMwDH3fh0wJNR1JCISqoR@CeECsRUVdoes0gbR/Z7ZBe5kiJOL7Ocfum@/m2X5ex6/4Pryfl4tfGl92Xkww@wRan0hfNvuPZhSjL0c2xAN6jLY7/4jdKTmot@kkpriXUaR3czQfzaETPcSzPGr5GuP70y7tcH8Ot/P@NnTiIqrKQQoWMrA1VAUYIN@hnaCVgeJ4BjkU6Gu0Hb451ui6lkLKl//zqFuDCeQtYqRcYYMzLGIgkxACsSMmgTxyw37LGKTAMWuLX7jDoiLSrv5UalSZMw/cCu/GsU@VmmdSV4K24k0VGFHbnHWjKsg/tDnLDDJGyhmzYC16ZcKK6D4F@oaiXKPZV/hHVL7WytXQ9VgN5dYat@kzzJDQUozbICO1XdMylkO9m6rlFw "JavaScript (Node.js) – Try It Online")
Thank Arnauld for 2 bytes
[Answer]
# [J](http://jsoftware.com/),43, 40 37 bytes
-3 bytes thanks to Bubbler
```
1#.1#.3 3(16=8#.@:=,);._3(0|:@,|.)^:4
```
[Try it online!](https://tio.run/##RVDLasMwELz7K4ZGkBiM0NORVQz5kvZQakovOeSafrs7u7YjsKzd2d2ZWf2uy2O2cKhwqz9ZfhHx4se5nOytzkP/bj/jxT3rbXja/qOmte/eLM7LbM8Y8FexPLru@@vnjgUZ2RQk3iPPhAjJCukLEa/4lXhB4CmME8IxHBBM0VJsUDSZLOzi7KvTIxEuQn9AEd6oTgOSSSrDQRUvGufWwtCI16Q@/e4q0NVVySc9RbOMjUz6HSOvG026U1KHsptvDmnnSDhvhEE0RuWTN5heaqK1cU/MomJSlczzL8zj7iSqYlB8q@9Ppl2ikIjm9grRHKtllXLw6z8 "J – Try It Online")
## Explanation:
The first part of the algorithm assures that we can apply a 3x3 sliding window to he input. This is achieved by prepending a row of zeroes and 90 degrees rotation, repeated 4 times.
```
1#.1#.3 3(16=8#.@:=,);._3(0|:@,|.)^:4
                         (       )^:4 - repeat 4 times
                          0|:@,|.     - reverse, prepend wit a row of 0 and transpose
                     ;._3             - cut the input (already outlined with zeroes)
      3 3                             - into matrices with size 3x3
         (          )                 - and for each matrix do
                   ,                  - ravel (flatten)
             8    =                   - check if each item equals 8
              #.@:                    - and convert the list of 1s and 0s to a decimal
          16=                         - is equal to 16?
   1#.                                - add (the result has the shape of the input)
1#.                                   - add again
```
[Answer]
# Java 8, ~~181~~ ~~157~~ ~~156~~ ~~149~~ 147 bytes
```
(M,R,C)->{int z=0,c,f,t;for(;R-->0;)for(c=C;c-->0;z+=f%9/8)for(f=t=9;M[R][c]==8&t-->0;)try{f-=M[R+t/3-1][c+t%3-1]%9/8;}finally{continue;}return z;}
```
-24 bytes thanks to *@OlivierGrégoire*  
-2 bytes thanks to *@ceilingcat*.
Takes the dimensions as additional parameters `R` (amount of rows) and `C` (amount of columns).
The cells are checked pretty similar as I did in [my *Fryer simulator* answer](https://codegolf.stackexchange.com/a/154563/52210).
[Try it online.](https://tio.run/##hVRNj5swEL3nV1grbQWKyfIRJxDEXnLqIVspe0QcWC9s2YITgUmVIH57OjakrbrLNJGM7XmeefPGnvf0lFrvrz@uvEybhuzSQnQzQgohszpPeUae1FJvEG7AGCdxQnZUb@yHz9YMAdPPYGhkKgtOnoggEbkaO7qnW9N67BTsEtmU05zKMD/URri3rEc7NNWcR9uQ6@VlHuX3wYOvt/NIRkG4i/dJzJMo8r/I4Yisz11uRWCYywfPcsA8l/dqoo6GfV6ItCzPHT8IWYg2C/s6k20tyCXsr6GieWxfSqA5sj0dildSQebGs6wL8QYJpuaQtswaaYjsJxkz7zqfLimjK8p6qhEffl1APapQ/iTCBvuKOoiPFV3TAFDuJMIH6xqiuH2v5f@c6zQHl3rISQY5LJGzDI3LgBtogDGb1mY6Y8Qf6AAxGcJY6e0jajL44xEYqK0q6/ynLi7UZa0VgJuA3BJfo5RXF2Gm4tqAcPSdCSZxzshvuJ0Oqj12Y5jOcKXZrRH2gVbcHTJFdFcvIQCUp7CIP1ejHBiBP/IuBt089XqQKig/gz8frZan1VIZLwHNUGUc9DUxJDsfKniryN9tUjceHerWWKux7zyfG5lVi0MrF0doSbIUxt1XcWzlhtyNFFWHPKU1qTe3Q3/2Tpva/M3lX1/GafTwaZjR1k/S@NbKgcdcLLhRUVItyky8ye8wi@1kXJijn6kI/ay//gI)
**Explanation:**
```
(M,R,C)->{                  // Method with integer-matrix as parameter & integer return
  int z=0,                  //  Result-counter, starting at 0
      c,f,t;                //  Temp-integers, starting uninitialized
  for(;R-->0;)              //  Loop over the rows:
    for(c=C;c-->0           //   Inner loop over the columns:
           ;                //     After every iteration:
            z+=f%9/8)       //      If the digit in this cell is 8:
                            //       Increase the result-counter by 1
                            //      Else: leave it the same
      for(f=t=9;            //    Reset the flag to 9
          M[R][c]==8&       //    If the current cell contains an 8:
            t-->0;)         //     Inner loop `t` in the range (9, 0]:
        try{f-=             //      Decrease the flag by:
               M[R+t/3-1]   //       If `t` is 0, 1, or 2: Look at the previous row
                            //       Else-if `t` is 3, 4, or 5: Look at the current row
                            //       Else (`t` is 6, 7, or 8): Look at the next row
                [c+t%3-1]   //       If `t` is 0, 3, or 6: Look at the previous column
                            //       Else-if `t` is 1, 4, or 7: Look at the current column
                            //       Else (`t` is 2, 5, or 8): Look at the next column
                %9/8;       //       And if the digit in this cell is 8:
                            //        Decrease the flag-integer by 1
                            //       Else: leave it the same
        }finally{continue;} //      Catch and ignore ArrayIndexOutOfBoundsExceptions
                            //      (try-finally saves bytes in comparison to if-checks)
  return z;}                //  And finally return the counter
```
[Answer]
# [MATL](https://github.com/lmendo/MATL), ~~21~~ ~~17~~ 10 bytes
```
8=t3Y6Z+>z
```
[Try it online!](https://tio.run/##y00syfn/38K2xDjSLErbrur//2gLBRMFUwUzBVNrBUsFYwUQ18JawQDIMFMwBImaKZgDZSwUjKyBhAWQY6JgFAsA "MATL – Try It Online")
Thanks to Luis Mendo for help in chat, and for suggesting 2D convolution. 
Explanation:
```
	#implicit input, m
8=	#equal to 8? matrix of 1 where m is 8, 0 otherwise
t	#duplicate
3Y6	#push [1 1 1; 1 0 1; 1 1 1], "neighbor cells" for convolution
Z+	#2D convolution; each element is replaced by the number of neighbors that are 8
>	#elementwise greater than -- matrix of 1s where an 8 is single, 0s otherwise
z	#number of nonzero elements -- number of single eights
	#implicit output
```
[Answer]
# [Retina 0.8.2](https://github.com/m-ender/retina/wiki/The-Language/a950ad7d925ec9316e3e2fb2cf5d49fd15d23e3d), 84 bytes
```
.+
_$&_
m`(?<!(?(1).)^(?<-1>.)*.?.?8.*¶(.)*.|8)8(?!8|.(.)*¶.*8.?.?(?<-2>.)*$(?(2).))
```
[Try it online!](https://tio.run/##FYsxDsIwEAR7/yJShOwgTrpz7NuTEP4JgYKCAgqUMu/KA/IxY3c7o9nfa31/n7XS2S3jaXGfhy/XwRfPgcK97QvfKExUqICmY/cdNgT4MmCjjsdOE3rQa@n12P7S/qFWJHCGqjMTiCI6wWwapRkxZUvZZYNGTuLYmgHExZTBs6Y/ "Retina 0.8.2 – Try It Online") Explanation:
```
.+
_$&_
```
Wrap each line in non-`8` characters so that all `8`s have at least one character on each side.
```
m`
```
This is the last stage, so counting matches is implied. The `m` modifier makes the `^` and `$` characters match at the start or end of any line.
```
(?<!...|8)
```
Don't match a character directly after an 8, or...
```
(?(1).)^(?<-1>.)*.?.?8.*¶(.)*.
```
... a character below an 8; the `(?(1).)^(?<-1>.)*` matches the same column as the `¶(.)*` on the next line, but the `.?.?` allows the `8` to be 1 left or right of the character after the `.` on the next line.
```
8
```
Match `8`s.
```
(?!8|...)
```
Don't match an 8 immediately before an 8, or...
```
.(.)*¶.*8.?.?(?<-2>.)*$(?(2).)
```
... a character with an 8 in the line below; again, the `(?<-2>.)*$(?(2).)` matches the same column as the `(.)*¶` on the previous line, but the `.?.?` allows the `8` to be 1 left or right of the `8` before the `.` on the previous line.
[Answer]
# J, 42 bytes
```
[:+/@,8=]+[:+/(<:3 3#:4-.~i.9)|.!.0(_*8&=)
```
[Try it online!](https://tio.run/##VVFBTsQwDLzzigEkdst6Q5MmTRpRCQmJEyeuCHFArIALH0B8vYydIu0qamuP3Zmx87VcuM0Bc8UGgh6Vz97h/unxYXmuu5s7KfPLTqPtbR0wXNa4d7@fbup@3Lnrt6/X5Wrulu7s/e3jGwNmHFAQkTAiCSZCmhblLsS8oiMyKwUBUvkpTCNCo@hXiqK1gOEYTWSLUgODtTsYLjWxn0onoCPW/2PeMKoQpINgVopUZjzl2L6aj@bbq0cxo5lHJTiQmHdNUyMU@6Vn6G3GSapfOdoi/LEHjqVTNyiu0yZTG403q8BkTkNTFUsiwUzO0DqCpZ5vSuhOm6tBV6yuvbFk86RjVJaSSXhSZaTTK9NtQDeb7U56@OUP "J – Try It Online")
# explanation
The high-level approach here is similar to the one used in the classic APL solution to the game of life: <https://www.youtube.com/watch?v=a9xAKttWgP4>.
In that solution, we shift our matrix in the 8 possible neighbor directions, creating 8 duplicates of the input, stack them up, and then add the "planes" together to get our neighbor counts.
Here, we use a "multiply by infinity" trick to adapt the solution for this problem.
```
[: +/@, 8 = ] + [: +/ (neighbor deltas) (|.!.0) _ * 8&= NB. 
                                                        NB.
[: +/@,                                                 NB. the sum after flattening
        8 =                                             NB. a 0 1 matrix created by
                                                        NB. elmwise testing if 8
                                                        NB. equals the matrix
            (the matrix to test for equality with 8   ) NB. defined by...
            ] +                                         NB. the original input plus
                [: +/                                   NB. the elmwise sum of 8
                                                        NB. matrices defined by
                                                _ *     NB. the elmwise product of 
                                                        NB. infinity and
                                                    8&= NB. the matrix which is 1
                                                        NB. where the input is 8
                                                        NB. and 0 elsewhere, thus
                                                        NB. creating an infinity-0
                                                        NB. matrix
                                        (|.!.0)         NB. then 2d shifting that 
                                                        NB. matrix in the 8 possible
                                                        NB. "neighbor" directions
                      (neighbor deltas)                 NB. defined by the "neighbor
                                                        NB. deltas" (see below)
                                                        NB. QED.
                                                        NB. ***********************
                                                        NB. The rest of the
                                                        NB. explanation merely
                                                        NB. breaks down the neighbor
                                                        NB. delta construction.
                      (neighbor deltas  )               NB. the neighbor deltas are
                                                        NB. merely the cross product
                                                        NB. of _1 0 1 with itself,
                                                        NB. minus "0 0"
                      (<: 3 3 #: 4 -.~ i.9)             NB. to create that...
                       <:                               NB. subtract one from
                          3 3 #:                        NB. the base 3 rep of
                                       i.9              NB. the numbers 0 - 8
                                 4 -.~                  NB. minus the number 4
                                                        NB.
                                                        NB. All of which produces
                                                        NB. the eight "neighbor"
                                                        NB. deltas:
                                                        NB. 
                                                        NB.       _1 _1
                                                        NB.       _1  0
                                                        NB.       _1  1
                                                        NB.        0 _1
                                                        NB.        0  1
                                                        NB.        1 _1
                                                        NB.        1  0
                                                        NB.        1  1
```
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), 12 bytes
```
œẹ8ạṀ¥þ`’Ạ€S
```
[Try it online!](https://tio.run/##VVExjsIwEOx5hR/gAjtZYr/jKhRFuuaaEx@gQzT3ACo6KK7jA6SgAPGQ8BGfPbvrcFKUbMY7OzPr76/NZpvS8zCN1zCN5@m6u/8@bp@v3XEaT6/95SM9fvJnnVLf98Ga1hqyZpXfgzV9tKaxhuFQgCX@8rGTjlx21kTAvgABZQeKH4aFxViQfZ7GCGFuKyDVTgK5SAoTmhjLQBmKHhIuWwmiTHjmXoINjuD@efTw2KleCSqBg8JM9jKdpy0BON1CLCfuTaeuz2kA3QCpiZVKdCIYNZOvhiQcLz4CbvhcOF5hh6Joym3UBA1fkkTmvsoJ8zIatcz2WrRQ9e3myyPRD9hDTjj8AQ "Jelly – Try It Online")
### How it works
```
œẹ8ạṀ¥þ`’Ạ€S  Main link. Argument: M (matrix)
œẹ8           Find all multidimensional indices of 8, yielding an array A of pairs.
      þ`      Table self; for all pairs [i, j] and [k, l] in A, call the link to the
              left. Return the results as a matrix.
   ạ              Absolute difference; yield [|i - k|, |j - l|].
    Ṁ             Take the maximum.
        ’     Decrement all the maxmima, mapping 1 to 0.
         Ạ€   All each; yield 1 for each row that contains no zeroes.
           S  Take the sum.
```
[Answer]
# [05AB1E](https://github.com/Adriandmen/05AB1E/wiki/Commands), 27 [bytes](https://github.com/Adriandmen/05AB1E/wiki/Codepage)
```
8Q2Fø0δ.ø}2Fø€ü3}˜9ôʒÅs}OΘO
```
[Try it online](https://tio.run/##yy9OTMpM/f/fItDI7fAOg3Nb9A7vqAUxHzWtObzHuPb0HMvDW05NOtxaXOt/bob////R0RY6JjqmOmY6prE60ZY6xjogvgWQbQBkmekYgsXNdMx1LIF8IyDbAkibA9UYxcYCAA) or [verify all test cases](https://tio.run/##PVC7TsNAEOz5Csv1gnxnn31HE9HQGmrLRQAXlqIQJTaSCzdI/AAVBZ9AGaFIUMUdSPkIfsTMrh@K5Ozszs7M7eNueVcW/ZN/dV/Vy5VXrjd1den5i4bO/JttUVXN@WZbrqviYZ5Rc/zCNK2rCff2Vl93h@C0v@gOLZd/zx/dd9j@vrtu//Paveza9PSW9nT8XPRZllmKyFBMJqfMUUiMLeoAVUxK@jEl5IA1aov/BByd5@TxOpM1hQM0UIikYSaGwQJkRzors8oAIYOpkQU2s2Jg8JsJBl6cSs3@Gv6JiCKvpLaCmalFgrcC1Ere4NBRo87wVjWFGZ9gRD8WnUQUnQTTg4/E47s44JC7wtGCFb7QlCsNSUK@mmTl2cCxY/pQ/NktQt9MAdR4RSPSFuERMf8H).
**Explanation:**
```
8Q       # Check for each inner value in the (implicit) input-matrix if it's an 8
         # (1 if 8; 0 if not)
2Fø0δ.ø} # Add a border of 0s around the matrix:
2F     } #  Loop 2 times:
  ø      #   Zip/transpose; swapping rows/columns
    δ    #   Map over each inner list:
   0 .ø  #    Surround it with a leading/trailing 0
2Fø€ü3}  # Then get all overlapping 3x3 blocks of this modified matrix:
2F    }  #  Loop 2 times again:
  ø      #   Zip/transpose again
   €     #   Map over each inner list again:
    ü3   #    Split it into overlapping triplets
˜        # Flatten the entire list of lists of lists of lists of integers
         # (aka the list of lists of 3x3 blocks)
 9ô      # Split it into parts of size 9
         # (so we now have a single list with flattened 3x3 blocks)
ʒÅs}     # Keep the (flattened) 3x3 blocks with a 1 in the center:
ʒ  }     # Filter over the list of flattened 3x3 blocks:
 Ås      #  Pop the list and push its center value
O        # Sum the inner lists of any remaining flattened 3x3 block
 Θ       # Check for each sum whether it's equal to 1 (1 if 1; 0 otherwise)
  O      # Sum those together again
         # (after which this sum is output implicitly as result)
```
[Answer]
# [Python 2](https://docs.python.org/2/), 130 bytes
```
lambda a:sum(sum(u[~-c*(c>0):c+2].count(8)for u in a[~-r*(r>0):r+2])*8==8==a[r][c]for r in range(len(a))for c in range(len(a[0])))
```
[Try it online!](https://tio.run/##lVPNjtowED6vn2IkDrFpuoqdOHGQ6HFfwutDmoUWCQIKcOilr07HYzth/6StZMD@5vuZccLpz@X3cVC37fr5tu8OP1866Fbn64H7z9X@/d4vef@jEKv@m3KP/fE6XLgR2@MIV9gN0CFjXPLRM0ZkiKVZr3F1dnS2d543et7YDb82fL8ZeCdI3b9BbeGEELeXzRae@Fms2EMHa7CH7sR3wyUfH8@n/e7ChYDJ8xyx7HnIhGMPpxGZsMUExp54lmUGKtBQg2YtlOBPhhX4W4NErIYGWjwpZvC7wapCzaw1yJJMoVKCuat4z4r8ZFQrVDe4L9GvZC25GWIpTPT8AneSklsmoz70JoNz6D1bLBYZY37Czk9owVqTQ5WDzqHGb5eDbXMocwiw8UBBJyzLyMBtk0NLsPKAoW1DEuVczsiWxArdAqLJt4qgnpiaxD4yKimTbAPgTYmjoza0YmKypjVzNbURRpCvelTUY5Py/KBxYJPgIFbRPbgVBMh0C62vyLuc6fpkGiDdgE5N1CmiiYFtmklNDcXhwsW3BJehHjUqwZI2PjM@jWmCMjykOHLgTRozX0aZWg7tVUTRU99yfng65hu6B5wQ3Or@r3Cz/v2QVA3L751jhM8rvkhypgRgFpNG0tGvuV68YqfTHPk@7KO8d5afib/Q6eeM/2zpDptg@TbvwwQK@Qc "Python 2 – Try It Online")
[Answer]
# Powershell, 121 bytes
```
param($a)(($b='='*4*($l=($a|% Le*)[0]))+($a|%{"!$_!"})+$b|sls "(?<=[^8]{3}.{$l}[^8])8(?=[^8].{$l}[^8]{3})" -a|% m*).Count
```
Less golfed test script:
```
$f = {
param($a)
$length=($a|% Length)[0]
$border='='*4*$length
$pattern="(?<=[^8]{3}.{$length}[^8])8(?=[^8].{$length}[^8]{3})"
$matches=$border+($a|%{"!$_!"})+$border |sls $pattern -a|% Matches
$matches.count
}
@(
,(3,"84565","93848","08615","67982","88742")
,(0,"88","23")
,(0,"534","252")
,(2,"5838")
,(2,"8","0","8")
,(1,"4285","2618","8558")
,(3,"45438182","82778393","98785428","45021869","15434561")
,(1,"8")
,(4,"85816877","99282783","28497327","92971956","69873152","19971882","35681475")
,(3,"818","257","801")
,(0,"")
) | % {
    $expected,$a = $_
    $result = &$f $a
    "$($result-eq$expected): $result : $a"
}
```
Output:
```
True: 3 : 84565 93848 08615 67982 88742
True: 0 : 88 23
True: 0 : 534 252
True: 2 : 5838
True: 2 : 8 0 8
True: 1 : 4285 2618 8558
True: 3 : 45438182 82778393 98785428 45021869 15434561
True: 1 : 8
True: 4 : 85816877 99282783 28497327 92971956 69873152 19971882 35681475
True: 3 : 818 257 801
True: 0 : 
```
Explanation:
First, the script calculates a length of the first string.
Second, it adds extra border to strings. Augmended ~~reality~~ string likes:
```
....=========!84565! !93848! !08615! !67982! !88742!===========....
```
represents the multiline string:
```
...=====
=======
!84565!
!93848!
!08615!
!67982!
!88742!
=======
========...
```
Note 1: the number of `=` is sufficient for a string of any length.
Note 2: a large number of `=` does not affect the search for eights.
Next, the regular expression `(?<=[^8]{3}.{$l}[^8])8(?=[^8].{$l}[^8]{3})` looks for the digit `8` with the preceding non-eights `(?<=[^8]{3}.{$l}[^8])` and the following non-eights `(?=[^8].{$l}[^8]{3})`:
```
.......
<<<....
<8>....
>>>....
.......
```
Finally, the number of matches is returned as a result.
[Answer]
# JavaScript (ES6), 106 bytes
```
a=>a.map((r,y)=>r.map((v,x)=>k+=v==8&[...'12221000'].every((d,i,v)=>(a[y+~-d]||0)[x+~-v[i+2&7]]^8)),k=0)|k
```
[Try it online!](https://tio.run/##dVHbboMwDH3fh7SJcFESCISH9EeiTEItnbp2paITaiW0X2e2QXsZCCn4@HqO/Vn39ePQne/fu1t7bMaTH2u/r9Ov@i5EBy/p990EengiuCS@995tQpqmW22M0UqpbUybvuleQhzhDD2miTq8kp/dMQ6DkuGJZh/OidmUMb47KeHilRwu46G9Pdprk17bD3ESITjIwUIBNkKoIAPCDm2FVgGa/QWUUCE2aDv8l5hjYpTy7X83qjWQLUYt9s85blfqLXZHDsu9iRUxWIwiI6y13J14O@Zq8VvLt6iC9Oo/ZQaVlcwAN8H7cIwp03BHqlJoa95OhR4995m2qFeYL@/K8vSCp5Q8r2IVZmLBWugeFeKMvJxjGGt8cSJfZ@KZ0bVYCcWmHDdry5gdTcvRb1f46Pl6lic5VMp6xl8 "JavaScript (Node.js) – Try It Online")
---
# Bitwise approach, 110 bytes
```
a=>a.map(r=>r.map(v=>x=x*2|v==8,x=k=0)|x).map((n,y,b)=>a[0].map((_,x)=>(n^1<<x|b[y-1]|b[y+1])*2>>x&7||k++))&&k
```
[Try it online!](https://tio.run/##dVHbboMwDH3fhyBS3IoEAkFq@BGUTbRrp40OKjqhVOLfmW3QXgZCIr4en2N/1UP9OPef9599271fpqudalvWh@/6Hva27NkYbOmt36lxsNaAt42NxegF58IWnnAS2FPFbo68gUc/bF/l8ejHU/XcS0dPJJ3YqbL0QT6OTRQJEQTNdO7aR3e7HG7dR3gNq8pAChoy0A6qAhIg36Ado5WB5HgGORToK7QNvjnWKOeEePmPRr0KktWsRvyU83qjXyM6cljHJlbEYDWLjLBXMzrxNsxV47dVr1EF6ZV/yhQqy5kBboL3YdinSsWI1BWjLXk7BUbkgjNvUW4wX9@V5ukZT8l5XsEq1MyCtdA9CvQTinKNYl/iHyfydWaeCV2LlVBurjGLtoTZ0bQU43qDj1yup3mSQaWsZ/oF "JavaScript (Node.js) – Try It Online")
[Answer]
# [Clojure](https://clojure.org/), ~~227~~ 198 bytes
```
(fn[t w h](let[c #(for[y(range %3 %4)x(range % %2)][x y])e #(= 8(get-in t(reverse %)0))m(fn[[o p]](count(filter e(c(dec o)(+ o 2)(dec p)(+ p 2)))))](count(filter #(= 1(m %))(filter e(c 0 w 0 h))))))
```
Ouch. Definitely not the shortest here by any means. 54 bytes of parenthesis is killer. I'm still relatively happy with it though.
**-29 bytes** by creating a helper function that generates a range since I was doing that twice, changing the `reduce` to a `(count (filter` setup, and getting rid of the threading macro after golfing. 
```
(defn count-single-eights [td-array width height]
  ; Define three helper functions. One generates a list of coords for a given range of dimensions, another checks if an eight is
  ; at the given coord, and the other counts how many neighbors around a coord are an eight
  (letfn [(coords [x-min x-max y-min y-max]
            (for [y (range y-min y-max)
                  x (range x-min x-max)]
              [x y]))
          (eight? [[x y]] (= 8 (get-in td-array [y x] 0)))
          (n-eights-around [[cx cy]]
            (count (filter eight?
                           (coords (dec cx) (+ cx 2), (dec cy) (+ cy 2)))))]
    ; Gen a list of each coord of the matrix
    (->> (coords 0 width, 0 height)
         ; Remove any coords that don't contain an eight
         (filter eight?)
         ; Then count how many "neighborhoods" only contain 1 eight
         (filter #(= 1 (n-eights-around %)))
         (count))))
(mapv #(count-single-eights % (count (% 0)) (count %))
      test-cases)
=> [3 0 0 2 2 1 3 1 4 3]
```
Where `test-cases` is an array holding all the "Python test cases"
[Try it online!](https://tio.run/##XZDdSsQwFIRfZUAK52CEbrt1u4hPEnKx1NMfaZOSTXX36WsSFcRchPNNZiYh3ezeNy87rX6yYbagnXqrAz4xGpol6A4P1Duv7@QvdhAUNYoj334JRcVG33A3LNH5ipYGCU@TRSAvH@Kv0cQl85J6tcNqDHVus4H6aQ7iIdTRm3RwTI9wqDjTmmiNlNa/RLrmQEvs5T8lKOOjS4w5wbvWrcJRoVF4jrtR0GeFWuFbbpNQZorHhx9HHE8K5yxXSWjzeMqRyhg0aJjxghoXP2yL2HDFKPEDvwA "Clojure – Try It Online")
]