From abedfb2fe5f11bbc047495d244edf5a5e7a68de9 Mon Sep 17 00:00:00 2001 From: Juraj Skripsky Date: Tue, 4 Mar 2014 20:39:50 +0100 Subject: [PATCH 1/2] Add script that builds an html page showing all sample images. --- Organizer/Sample-Viewer/createHtmlPage.fsx | 39 ++++++++++++++++ Organizer/Sample-Viewer/digits.css | 49 ++++++++++++++++++++ Organizer/Sample-Viewer/digits.html.template | 24 ++++++++++ 3 files changed, 112 insertions(+) create mode 100644 Organizer/Sample-Viewer/createHtmlPage.fsx create mode 100644 Organizer/Sample-Viewer/digits.css create mode 100644 Organizer/Sample-Viewer/digits.html.template diff --git a/Organizer/Sample-Viewer/createHtmlPage.fsx b/Organizer/Sample-Viewer/createHtmlPage.fsx new file mode 100644 index 0000000..32f7bf9 --- /dev/null +++ b/Organizer/Sample-Viewer/createHtmlPage.fsx @@ -0,0 +1,39 @@ +open System.IO +open System.Drawing +open System.Drawing.Imaging + +let (width, height) = (28, 28) +let digitsPerRow = 100 + +let offset idx = (idx % digitsPerRow * width), (idx / digitsPerRow * height) + +// Store array of digits as a single PNG image. +let saveAsPng (digits: Observation[]) (fileName: string) = + let len = digits.Length + let rows = (len + digitsPerRow - 1) / digitsPerRow + + use bmp = new Bitmap(digitsPerRow * width, rows * height) + let drawDigit digit (x, y) = + let colors = [|0..255|] |> Array.map (fun c -> Color.FromArgb (c, c, c)) + let drawPixel i p = bmp.SetPixel (x + i % width, y + i / width, colors.[p]) + digit.Pixels |> Array.iteri drawPixel + + digits |> Array.iteri (fun i d -> drawDigit d (offset i)) + bmp.Save(fileName, ImageFormat.Png) + +saveAsPng training "training.png" +saveAsPng validation "validation.png" + +// Create HTML page by populating the template. +let populateWithDigits digits name (text: string) = + let items = digits |> Array.mapi (fun i d -> + let (x, y) = offset i + sprintf "
  • " x y d.Label) + text.Replace (sprintf "{%s}" name, String.concat "\n" items) + +let html = + File.ReadAllText("digits.html.template") + |> populateWithDigits training "training" + |> populateWithDigits validation "validation" + +File.WriteAllText("digits.html", html) diff --git a/Organizer/Sample-Viewer/digits.css b/Organizer/Sample-Viewer/digits.css new file mode 100644 index 0000000..185586d --- /dev/null +++ b/Organizer/Sample-Viewer/digits.css @@ -0,0 +1,49 @@ +body { + font: 14px Verdana; +} + +h2 { + clear: left; + font-weight: normal; + margin-top: 8px; + margin-bottom: 8px; +} + +div.container { + height: 40%; + width: 98%; + padding: 8px; + overflow-y: scroll; + background-color: #f0f0f0; + border: 1px solid gray; + margin-bottom: 24px; +} + +ol { + padding-left: 0; + margin: 0; +} + +li { + display: block; + float: left; + width: 28px; + height: 48px; + margin-bottom: 10px; + border: 1px solid gray; + background: white; + margin-right: -1px; +} + +li div { + width: 28px; + height: 28px; + border-bottom: 1px solid gray; +} + +li label { + display: block; + text-align: center; + width: 28px; +} + diff --git a/Organizer/Sample-Viewer/digits.html.template b/Organizer/Sample-Viewer/digits.html.template new file mode 100644 index 0000000..48f4d8d --- /dev/null +++ b/Organizer/Sample-Viewer/digits.html.template @@ -0,0 +1,24 @@ + + + + + + +

    Training sample

    +
    +
      + {training} +
    +
    + +

    Validation sample

    +
    +
      + {validation} +
    +
    + + From a77c9b91356589644d35e5a48e2eb78d1c4650f5 Mon Sep 17 00:00:00 2001 From: Juraj Skripsky Date: Tue, 4 Mar 2014 21:59:54 +0100 Subject: [PATCH 2/2] Add usage notes. --- Organizer/Sample-Viewer/createHtmlPage.fsx | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/Organizer/Sample-Viewer/createHtmlPage.fsx b/Organizer/Sample-Viewer/createHtmlPage.fsx index 32f7bf9..83eca72 100644 --- a/Organizer/Sample-Viewer/createHtmlPage.fsx +++ b/Organizer/Sample-Viewer/createHtmlPage.fsx @@ -1,3 +1,13 @@ +// Running the following lines in F# interactive will create three files: +// - training.png +// - validation.png +// - digits.html +// +// Note: +// - run "PossibleSolution.fsx" before running this script +// - the file "digits.html.template" is expected to be in the current directory +// - the new files will be created in the current directory + open System.IO open System.Drawing open System.Drawing.Imaging