# Image to Integer

![](/files/bvUy6WcZDf43jr8xCskt)

{% embed url="<https://youtu.be/9sfFBX1b-pc>" %}
Inspiration for the node and source of code
{% endembed %}

```fsharp
namespace integerImage
open System.IO
module integerML =
    type Example = {
        Label : int
        Pixels : int []
    }
    
    let readExamples path = 
        path
        |> File.ReadAllLines
        |> Array.map (fun line -> line.Split ',')
        |> Array.map (fun line -> line |> Array.map int)
        |> Array.map (fun line -> {Label = line.[0]; Pixels = line.[1..]} )

    let distance (img1 : int[]) (img2 : int[]) =
        Array.map2 (fun pix1 pix2 -> abs(pix1 - pix2)) img1 img2
        |> Array.sum
    
    let classify (img : int[]) = 
        let bestMatch =
                readExamples (__SOURCE_DIRECTORY__ + "/train.csv")
                |> Array.minBy (fun x -> distance x.Pixels img)
        bestMat
```

```csharp
// Some codepublic class IntImg
{
    private IntImg() { }
    public static int intFrmImg(int[] tst)
    {
        return integerImage.integerML.classify(tst);
    }
}
```

{% embed url="<https://www.kaggle.com/rakuraku678/mnist-60000-hand-written-number-images>" %}
Training Set Source
{% endembed %}

{% file src="/files/7tp3ImOvgr3y9w0LVuEl" %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://gitbook.testingwaters.in/motion/image-to-integer.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
