1
// ParasitemIA file format.
6 open System.IO.Compression
11 open Emgu.CV.Structure
13 let extension = ".pia"
14 let filter = "PIA|*.pia"
30 sources
: ImageSource list
33 // The json type associated to a source image.
34 type JSONSourceImage = JsonProvider<"""
37 { "infected
": true, "addedManually
": false, "removed
": false, "posX
" : 42, "posY
" : 42, "width
" : 10, "height
" : 10, "stainArea
" : 10 }
42 // The json type associated to a file.
43 type JSONMainInformation = JsonProvider<"""
45 "patientID
": "1234abcd"
49 let mainFilename = "info.json"
51 let save (filePath
: string) (data
: FileData) =
52 use file = ZipFile.Open(filePath
, ZipArchiveMode.Update)
54 let mainJSON = JSONMainInformation.Root(data
.patientID
)
57 match file.GetEntry(mainFilename) with
58 | null -> file.CreateEntry(mainFilename)
61 use mainFileWriter = new StreamWriter(mainFile.Open())
62 mainJSON.JsonValue.WriteTo(mainFileWriter, JsonSaveOptions.None)
65 let load (filePath
: string) : FileData =
66 use file = ZipFile.Open(filePath
, ZipArchiveMode.Read)
68 let mainFile = file.GetEntry(mainFilename)
69 let mainJSON = JSONMainInformation.Load(mainFile.Open())
71 { sources
= []; patientID
= mainJSON.PatientId }