X-Git-Url: http://git.euphorik.ch/?a=blobdiff_plain;f=Parasitemia%2FParasitemiaUI%2FState.fs;h=69662d502fb71ab9124cdc7ce8eb68c60f971469;hb=000e7091983f20ef75d0eba9bf1c865c76483f24;hp=63b9bbf5d1240e67867b8a32c45fec17dfd1d15e;hpb=cb90b01c85183b2c75ee6d22b378b3ca99df6bf3;p=master-thesis.git diff --git a/Parasitemia/ParasitemiaUI/State.fs b/Parasitemia/ParasitemiaUI/State.fs index 63b9bbf..69662d5 100644 --- a/Parasitemia/ParasitemiaUI/State.fs +++ b/Parasitemia/ParasitemiaUI/State.fs @@ -9,7 +9,7 @@ open Emgu.CV.Structure open Types -type State () = +type State (defaultConfig: ParasitemiaCore.Config.Config) = let sourceImages = List() let mutable alteredSinceLastSave = false let mutable patientID = "" @@ -30,9 +30,24 @@ type State () = List.length srcImg.rbcs, srcImg.rbcs |> List.fold (fun nbInfected rbc -> if rbc.infected then nbInfected + 1 else nbInfected) 0 - member this.ImageNbAltered (srcImg: SourceImage) : int * int = + member this.ImageNbManuallyChangedRBC (srcImg: SourceImage) (setAsInfected: bool) : int * int = List.length srcImg.rbcs, - srcImg.rbcs |> List.fold (fun nbAltered rbc -> if rbc.setManually then nbAltered + 1 else nbAltered) 0 + srcImg.rbcs |> List.fold (fun nb rbc -> if rbc.setManually && rbc.infected = setAsInfected then nb + 1 else nb) 0 + + member this.ImageNbManuallyChangedRBCStr (srcImg: SourceImage) (setAsInfected: bool) : string = + Utils.percentText (this.ImageNbManuallyChangedRBC srcImg setAsInfected) + + member this.ImageManuallyChangedRBC (srcImg: SourceImage) (setAsInfected: bool) : int seq = + query { + for rbc in srcImg.rbcs do + where (rbc.setManually && rbc.infected = setAsInfected) + select rbc.num } + + member this.ImageManuallyChangedRBCStr (srcImg: SourceImage) (setAsInfected: bool) : string = + let listStr = Utils.listAsStr <| this.ImageManuallyChangedRBC srcImg setAsInfected + if listStr = "" + then "" + else "[" + listStr + "]" member this.GlobalParasitemia : int * int = sourceImages @@ -62,7 +77,7 @@ type State () = /// /// If the file cannot be loaded member this.Load () = - let data = PiaZ.load this.FilePath + let data = PiaZ.load this.FilePath defaultConfig this.PatientID <- data.patientID sourceImages.Clear() sourceImages.InsertRange(0, data.images) @@ -75,6 +90,7 @@ type State () = member this.AddSourceImage (filePath: string) (defaultConfig: ParasitemiaCore.Config.Config) : SourceImage = let srcImg = { num = sourceImages.Count + 1 + name = System.IO.FileInfo(filePath).Name config = defaultConfig.Copy() dateLastAnalysis = DateTime(0L) rbcs = [] @@ -103,6 +119,12 @@ type State () = // Re-numbered the images. sourceImages |> Seq.iteri (fun i srcImg -> srcImg.num <- i + 1) + member this.SetName (srcImg: SourceImage) (name: string) = + if name <> srcImg.name + then + srcImg.name <- name + alteredSinceLastSave <- true + member this.SetResult (imgNum: int) (cells: ParasitemiaCore.Types.Cell list) = let sourceImage = sourceImages.Find(fun srcImg -> srcImg.num = imgNum) @@ -114,26 +136,27 @@ type State () = // To match with previously manually altered RBC. let manuallyAlteredPreviousRBCS = sourceImage.rbcs |> List.filter (fun rbc -> rbc.setManually) let tolerance = (float sourceImage.config.RBCRadius.Pixel) * 0.5 // +/-. - let getPreviousRBC (center: Point) : RBC option = + let getPreviousManuallyAlteredRBC (center: Point) : RBC option = manuallyAlteredPreviousRBCS |> List.tryFind (fun rbc -> rbc.center.X > center.X - tolerance && rbc.center.X < center.X + tolerance && rbc.center.Y > center.Y - tolerance && rbc.center.Y < center.Y + tolerance) sourceImage.rbcs <- cells |> List.filter (fun cell -> match cell.cellClass with ParasitemiaCore.Types.HealthyRBC | ParasitemiaCore.Types.InfectedRBC -> true | _ -> false ) - |> List.sortByDescending (fun cell -> cell.infectedArea, (w - cell.center.X) + (h - cell.center.Y)) + |> List.sortByDescending (fun cell -> cell.nucleusArea, (w - cell.center.X) + (h - cell.center.Y)) |> List.mapi (fun i cell -> let center = Point(float cell.center.X, float cell.center.Y) let infected, setManually = - match getPreviousRBC center with - | Some rbc -> rbc.infected, true - | _ -> cell.cellClass = ParasitemiaCore.Types.InfectedRBC, false + let infected = cell.cellClass = ParasitemiaCore.Types.InfectedRBC + match getPreviousManuallyAlteredRBC center with + | Some rbc when rbc.infected <> infected -> rbc.infected, true // If it has been previously manually changed and now match the result, the manually flag is removed. + | _ -> infected, false { num = i + 1 infected = infected setManually = setManually center = center size = Size(float cell.elements.Width, float cell.elements.Height) - infectedArea = cell.infectedArea }) + infectedArea = cell.nucleusArea }) alteredSinceLastSave <- true