# Image to Integer

![](https://1430428134-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-Ld8QK19sjP1I9rhLouo%2Fuploads%2FjPIf9IUImUNpvwPfqvaM%2FintImg-20211018-1.gif?alt=media\&token=4fcc06c4-1ce6-4773-ac4e-674aa9a9cb85)

{% 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="<https://1430428134-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-Ld8QK19sjP1I9rhLouo%2Fuploads%2FMgKYC9ysUZyTEu4mYi6p%2FML.zip?alt=media&token=25bfc66d-339f-467c-bff9-411de1d4473a>" %}
