X-Git-Url: http://git.euphorik.ch/index.cgi?a=blobdiff_plain;ds=inline;f=Parasitemia%2FParasitemiaUI%2FPiaZ.fs;h=18e9d6a4afaeae837d305c56ec993f1195faedab;hb=5d1a08f1b121d660228b08d9f931edaed619fdb9;hp=02152542d09407c37c7ecc460f5739531c557508;hpb=b87b35b922551f122228df1fd9c530bbb807935a;p=master-thesis.git
diff --git a/Parasitemia/ParasitemiaUI/PiaZ.fs b/Parasitemia/ParasitemiaUI/PiaZ.fs
index 0215254..18e9d6a 100644
--- a/Parasitemia/ParasitemiaUI/PiaZ.fs
+++ b/Parasitemia/ParasitemiaUI/PiaZ.fs
@@ -2,7 +2,6 @@
module ParasitemiaUI.PiaZ
open System
-open System.Windows
open System.IO
open System.IO.Compression
@@ -10,7 +9,6 @@ open Emgu.CV
open Emgu.CV.Structure
open Newtonsoft.Json
-open Newtonsoft.Json.Converters
open Types
@@ -56,35 +54,35 @@ let currentFileVersion = 2
///
/// If the file cannot be written
let save (filePath : string) (data : DocumentData) =
- use file = ZipFile.Open(filePath, ZipArchiveMode.Update)
+ use file = ZipFile.Open (filePath, ZipArchiveMode.Update)
for e in List.ofSeq file.Entries do // 'ofSeq' to not iterate a collection currently modified.
- e.Delete()
+ e.Delete ()
// Main JSON file.
- let mainEntry = file.CreateEntry(mainEntryName, CompressionLevel.Fastest)
- use mainEntryWriter = new StreamWriter(mainEntry.Open())
- mainEntryWriter.Write(JsonConvert.SerializeObject({ patientID = data.patientID; fileVersion = currentFileVersion }))
+ let mainEntry = file.CreateEntry (mainEntryName, CompressionLevel.Fastest)
+ use mainEntryWriter = new StreamWriter (mainEntry.Open ())
+ mainEntryWriter.Write (JsonConvert.SerializeObject ({ patientID = data.patientID; fileVersion = currentFileVersion }))
// Write each images and the associated information.
for srcImg in data.images do
- let imgFilename = (string srcImg.num) + imageExtension
- let imgEntry = file.CreateEntry(imgFilename, CompressionLevel.NoCompression) // FIXME: It seems a compression is applied to this file despite of the 'NoCompression' flag.
- srcImg.img.ToBitmap().Save(imgEntry.Open(), System.Drawing.Imaging.ImageFormat.Tiff)
-
- let imgJSONEntry = file.CreateEntry(imgFilename + ".json", CompressionLevel.Fastest)
- use imgJSONFileWriter = new StreamWriter(imgJSONEntry.Open())
- imgJSONFileWriter.Write(
- JsonConvert.SerializeObject(
+ let imgFilename = (string srcImg.Num) + imageExtension
+ let imgEntry = file.CreateEntry (imgFilename, CompressionLevel.NoCompression) // FIXME: It seems a compression is applied to this file despite of the 'NoCompression' flag.
+ srcImg.Img.ToBitmap().Save (imgEntry.Open (), System.Drawing.Imaging.ImageFormat.Tiff)
+
+ let imgJSONEntry = file.CreateEntry (imgFilename + ".json", CompressionLevel.Fastest)
+ use imgJSONFileWriter = new StreamWriter (imgJSONEntry.Open ())
+ imgJSONFileWriter.Write (
+ JsonConvert.SerializeObject (
{
- num = srcImg.num
- name = srcImg.name
- RBCRadius = srcImg.config.RBCRadius.Pixel
- parameters = srcImg.config.Parameters
- dateLastAnalysis = srcImg.dateLastAnalysis
- rbcs = srcImg.rbcs
- healthyRBCBrightness = srcImg.healthyRBCBrightness
- infectedRBCBrightness = srcImg.infectedRBCBrightness
+ num = srcImg.Num
+ name = srcImg.Name
+ RBCRadius = srcImg.Config.RBCRadius.Pixel
+ parameters = srcImg.Config.Parameters
+ dateLastAnalysis = srcImg.DateLastAnalysis
+ rbcs = srcImg.RBCs
+ healthyRBCBrightness = srcImg.HealthyRBCBrightness
+ infectedRBCBrightness = srcImg.InfectedRBCBrightness
}
)
)
@@ -93,21 +91,22 @@ let updateDocumentData (fromVersion : int) (toVersion : int) (data : DocumentDat
for v in fromVersion + 1 .. toVersion do
match v with
| 1 -> // Version 0 -> 1 : set initial brightness for rbc.
- data.images |> List.iter (fun i -> i.healthyRBCBrightness <- 1.f; i.infectedRBCBrightness <- 1.f)
+ data.images |> List.iter (fun i -> i.HealthyRBCBrightness <- 1.f; i.InfectedRBCBrightness <- 1.f)
| _ -> ()
data
///
/// Load document from a give file path.
///
-///
+/// Path to the PiaZ file
+///
/// If the file cannot be read
let load (filePath : string) (defaultConfig : ParasitemiaCore.Config.Config) : DocumentData =
- use file = ZipFile.Open(filePath, ZipArchiveMode.Read)
+ use file = ZipFile.Open (filePath, ZipArchiveMode.Read)
- let mainEntry = file.GetEntry(mainEntryName)
- use mainEntryReader = new StreamReader(mainEntry.Open())
- let info = JsonConvert.DeserializeObject(mainEntryReader.ReadToEnd())
+ let mainEntry = file.GetEntry (mainEntryName)
+ use mainEntryReader = new StreamReader (mainEntry.Open ())
+ let info = JsonConvert.DeserializeObject (mainEntryReader.ReadToEnd ())
updateDocumentData info.fileVersion currentFileVersion
{
@@ -116,15 +115,15 @@ let load (filePath : string) (defaultConfig : ParasitemiaCore.Config.Config) : D
[
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 = new Image(bitmap)
+ if imgEntry.Name.EndsWith (imageExtension) then
+ use bitmap = new System.Drawing.Bitmap (imgEntry.Open (), false)
+ let img = bitmap.ToImage ()
imgNum <- imgNum + 1
- let imgJSONEntry = file.GetEntry(imgEntry.Name + ".json")
- use imgJSONFileReader = new StreamReader(imgJSONEntry.Open())
- let imgInfo = JsonConvert.DeserializeObject(imgJSONFileReader.ReadToEnd())
+ let imgJSONEntry = file.GetEntry (imgEntry.Name + ".json")
+ use imgJSONFileReader = new StreamReader (imgJSONEntry.Open ())
+ let imgInfo = JsonConvert.DeserializeObject (imgJSONFileReader.ReadToEnd ())
- let config = defaultConfig.Copy()
+ let config = defaultConfig.Copy ()
config.Parameters <-
{
ParasitemiaCore.Config.defaultParameters with
@@ -132,16 +131,7 @@ let load (filePath : string) (defaultConfig : ParasitemiaCore.Config.Config) : D
}
config.SetRBCRadius imgInfo.RBCRadius
- yield
- {
- num = imgNum
- name = imgInfo.name
- config = config
- dateLastAnalysis = imgInfo.dateLastAnalysis
- img = img
- rbcs = imgInfo.rbcs
- healthyRBCBrightness = imgInfo.healthyRBCBrightness
- infectedRBCBrightness = imgInfo.infectedRBCBrightness
- }
+
+ SourceImage (imgNum, imgInfo.name, config, imgInfo.dateLastAnalysis, img, imgInfo.rbcs, HealthyRBCBrightness = imgInfo.healthyRBCBrightness, InfectedRBCBrightness = imgInfo.infectedRBCBrightness)
]
}
\ No newline at end of file