Recognize ASCII art numbers Challenge

Recognize ASCII art numbers. To make things interesting, three random points in the image might be flipped. For example:

 ***** 
 *  ** 
    ** 

   **  
  **   
 **    


Input

A 7x7 ASCII art number generated by the below Python script.

Output

A digit.

Testing script

Here's a Python script (2.6+) to generate the test cases:

import random

digits = '''\
  ***  
 ** ** 
**   **
**   **
**   **
 ** ** 
  ***  

   *   
 ***   
   *   
   *   
   *   
   *   
 ***** 

  ***  
 *  ** 
     * 
    ** 
   **  
  **   
 ******

  ***  
 *  ** 
     * 
  ***  
     * 
 *  ** 
  ***  

   **  
  ***  
 * **  
*  **  
****** 
   **  
   **  

 ***** 
 **    
 ****  
     * 
     * 
 *   * 
  ***  

  **** 
 **    
 ***** 
 *   * 
 **  **
 **  * 
  **** 

 ***** 
    ** 
    ** 
   **  
   **  
  **   
 **    

  **** 
 **  **
 **  **
  **** 
 **  **
 **  **
  **** 

  ***  
 ** ** 
**   **
 **  * 
  **** 
    ** 
 ****  '''.split('\n\n')

def speckle(image, num_speckles):
    grid = [list(row) for row in image.split('\n')]

    for i in range(num_speckles):
        row = random.choice(grid)
        row[random.randint(0, 6)] = random.choice([' ', '*'])

    return '\n'.join([''.join(row) for row in grid])

digit = random.choice(digits)

print(speckle(digit, 3))
APL (87 85)

1-⍨⊃⍒(,↑{7↑'*'=⍞}¨⍳7)∘(+.=)¨{49↑,(16/2)⊤⎕UCS⍵}¨↓10 3⍴'嵝䍝뫂傁ဣ␋䠁䊫낫䢝䊅넂垵僡ᑨ嘙쐅嘹䜝䪀슪퀪岹亝尵䌧뮢'


Explanation:

Each possible ASCII number is encoded in 48 bits. (The 49th bit is always zero anyway). The string 嵝䍝뫂傁ဣ␋䠁䊫낫䢝䊅넂垵僡ᑨ嘙쐅嘹䜝䪀슪퀪岹亝尵䌧뮢 has three characters per ASCII number, each of which encodes 16 bits.


↓10 3⍴: split the data string into 10 3-char groups, each of which encodes a number.
{...}¨: for each of the groups:

(16/2)⊤⎕UCS⍵: get the first 16 bits of each of the three characters
,: concatenate the bit arrays into one array
49↑: take the first 49 elements. There are only 48, so this is equivalent to adding a 0 at the end.

,↑{7↑'*'=⍞}¨⍳7: read 7 lines of 7 characters from the keyboard, make a bit array for each line where 1 means the character was a *, and join them together.
(+.=)¨: for each possible digit, calculate how much bits the input had in common with the digit.
⍒: get the indices for a downwards sort of that list, so that the first item in the result is the index of the largest number in the previous list.
⊃: take the first item, which is the index of the digit
1-⍨: subtract one, because APL indices are 1-based.