> For the complete documentation index, see [llms.txt](https://gitbook.testingwaters.in/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://gitbook.testingwaters.in/motion/image-to-integer.md).

# 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" %}
