-let load (filePath: string) : DocumentData =
- use file = ZipFile.Open(filePath, ZipArchiveMode.Read)
-
- let mainEntry = file.GetEntry(mainEntryName)
- use mainEntryReader = new StreamReader(mainEntry.Open())
- let info = JsonConvert.DeserializeObject<JSONInformation>(mainEntryReader.ReadToEnd())
-
- { patientID = info.patientID
- images = [ let mutable imgNum = 0
- for imgEntry in file.Entries do
- if imgEntry.Name.EndsWith(imageExtension)
- then
- let img = new Image<Bgr, byte>(new System.Drawing.Bitmap(imgEntry.Open(), false)) // FIXME: Should we dispose the bitmap?
- imgNum <- imgNum + 1
- let imgEntry = file.GetEntry(imgEntry.Name + ".json")
- use imgEntryFileReader = new StreamReader(imgEntry.Open())
- let imgInfo = JsonConvert.DeserializeObject<JSONSourceImage>(imgEntryFileReader.ReadToEnd())
- let config = ParasitemiaCore.Config.Config(imgInfo.parameters)
- config.SetRBCRadius imgInfo.RBCRadius
- yield { num = imgNum
- config = config
- dateLastAnalysis = imgInfo.dateLastAnalysis
- img = img
- rbcs = imgInfo.rbcs } ] }
\ No newline at end of file
+let load (filePath : string) (defaultConfig : ParasitemiaCore.Config.Config) : DocumentData =
+ use file = ZipFile.Open (filePath, ZipArchiveMode.Read)
+
+ let mainEntry = file.GetEntry (mainEntryName)
+ use mainEntryReader = new StreamReader (mainEntry.Open ())
+ let info = JsonConvert.DeserializeObject<JSONInformation> (mainEntryReader.ReadToEnd ())
+
+ updateDocumentData info.fileVersion currentFileVersion
+ {
+ patientID = info.patientID
+ images =
+ [
+ let mutable imgNum = 0
+ for imgEntry in file.Entries do
+ if imgEntry.Name.EndsWith (imageExtension) then
+ use bitmap = new System.Drawing.Bitmap (imgEntry.Open (), false)
+ let img = bitmap.ToImage<Bgr, byte> ()
+ imgNum <- imgNum + 1
+ let imgJSONEntry = file.GetEntry (imgEntry.Name + ".json")
+ use imgJSONFileReader = new StreamReader (imgJSONEntry.Open ())
+ let imgInfo = JsonConvert.DeserializeObject<JSONSourceImage> (imgJSONFileReader.ReadToEnd ())
+
+ let config = defaultConfig.Copy ()
+ config.Parameters <-
+ {
+ ParasitemiaCore.Config.defaultParameters with
+ resolution = imgInfo.parameters.resolution
+ }
+
+ config.SetRBCRadius imgInfo.RBCRadius
+
+ SourceImage (imgNum, imgInfo.name, config, imgInfo.dateLastAnalysis, img, imgInfo.rbcs, HealthyRBCBrightness = imgInfo.healthyRBCBrightness, InfectedRBCBrightness = imgInfo.infectedRBCBrightness)
+ ]
+ }
\ No newline at end of file