Count the number of a number in the picture area Your goal is to write a full program or function that takes 5 positive integers   and a string with an image filename as input [X1,Y1], [X2,Y2], N, image.jpg in any reasonable format, where:


First couple [X1,Y1] are the top left X,Y coordinates (&lt;=20) of the blue rectangle area in the example picture (16,11).
Second couple [X2,Y2] are the bottom right X,Y coordinates (&lt;=20) of the blue rectangle area in the example picture (20,22).
Fifth number N such 0 &lt;= N &lt;= 9 is the number that has to be found.
Sixth parameter is a string with the filename of this JPG picture.


Output how many of N's are present in the indicated area (outlined in blue in the picture for this example):



Click here to obtain a bigger clean version of the same image.

In the picture there are 500 numbers from 0 to 9 (included) arranged in 20 columnns per 25 rows, in monospaced Courier New font.
Each different number has a different color (you can take advantage of this fact or ignore it and consider or convert the image in monocrome if that helps you).

Test cases:

[4,4],[13,5],1,image.jpg    &gt; 4  (outlined in red)
[4,4],[13,5],4,image.jpg    &gt; 2  (outlined in red)
[17,5],[17,5],2,image.jpg   &gt; 1  (outlined in magenta)
[17,5],[17,5],9,image.jpg   &gt; 0  (outlined in magenta)
[20,8],[20,9],3,image.jpg   &gt; 1  (outlined in cyan)
[20,8],[20,9],2,image.jpg   &gt; 0  (outlined in cyan)
[16,11],[20,22],0,image.jpg &gt; 8  (outlined in blue)
[16,11],[20,22],3,image.jpg &gt; 9  (outlined in blue)
[3,14],[11,20],7,image.jpg  &gt; 6  (outlined in green)
[3,14],[11,20],5,image.jpg  &gt; 6  (outlined in green)
[3,14],[11,20],8,image.jpg  &gt; 8  (outlined in green)
[1,1],[20,25],0,image.jpg   &gt; 47 (whole picture)
[1,1],[20,25],8,image.jpg   &gt; 50 (whole picture)
[1,1],[20,25],1,image.jpg   &gt; 55 (whole picture)


Rules:


This is code-golf so the shortest code wins.
You must take as input this JPG file.
You are not allowed to hardcode the matrix of numbers represented in the JPG, or the results.
Standard loopholes are forbidden.
Mathematica, 92 bytes

Count[Take[Characters@StringSplit@TextRecognize@Binarize[Import@#4,.9],#2,#],ToString@#3,2]&amp;


Unnamed function taking the arguments in this format: [{X1,X2}, {Y1,Y2}, N, "image.jpg"]. (Indeed, the fourth argument can be either the local file name or the URL http://i67.tinypic.com/6qh5lj.jpg.)

Import@#4 imports the image file, Binarize[...,.9] darkens all of the numbers to black, and TextRecognize (the function clearly doing the heavy lifting here!) extracts a multi-line string from the resulting image, which is split into a nested list of characters with Characters@.

Take[...,#2,#] keeps only the characters corresponding to the outlined rectangle, and Count[...,ToString@#3,2] counts the number of occurrences of N in the result.