X-Git-Url: http://git.euphorik.ch/?p=master-thesis.git;a=blobdiff_plain;f=Parasitemia%2FParasitemiaCore%2FMainAnalysis.fs;h=813d090968995969f3f7e08f34786c73fd5d16e8;hp=4ab52d92889eba251cb32d0ec6c11a79a169fb27;hb=db49e167a602ef1df02a8b5f7de334355a4917dd;hpb=c4a76a01f62568c6353396ff85551a3151fc5236 diff --git a/Parasitemia/ParasitemiaCore/MainAnalysis.fs b/Parasitemia/ParasitemiaCore/MainAnalysis.fs index 4ab52d9..813d090 100644 --- a/Parasitemia/ParasitemiaCore/MainAnalysis.fs +++ b/Parasitemia/ParasitemiaCore/MainAnalysis.fs @@ -50,20 +50,28 @@ let doAnalysis (img: Image) (name: string) (config: Config) (reportPr logWithName "Starting analysis ..." - use green = img.[1] - let greenFloat = green.Convert() - let filteredGreen = gaussianFilter greenFloat config.LPFStandardDeviation + use img_RBC = + use imgFloat = img.Convert() + let redFactor, greenFactor, blueFactor = config.Parameters.colorContribution_BG_RBC + blueFactor * imgFloat.[0] + greenFactor * imgFloat.[1] + redFactor * imgFloat.[2] + + let img_RBC_filtered = gaussianFilter img_RBC config.LPFStandardDeviationRBC + + use img_parasites = + use imgFloat = img.Convert() + let redFactor, greenFactor, blueFactor = config.Parameters.colorContribution_RBC_parasite + blueFactor * imgFloat.[0] + greenFactor * imgFloat.[1] + redFactor * imgFloat.[2] logWithName (sprintf "Nominal erytrocyte diameter: %A" config.RBCRadiusByResolution) - let initialAreaOpening = int <| config.RBCRadiusByResolution.Area * config.Parameters.ratioAreaPaleCenter * 1.2f // We do an area opening a little larger to avoid to do a second one in the case the radius found is near the initial one. - do! logTimeWithName "First area opening" (fun () -> ImgTools.areaOpenF filteredGreen initialAreaOpening; report 10) + let initialAreaOpening = int <| config.RBCRadiusByResolution.Area * config.Parameters.ratioAreaPaleCenter * 1.1f // We do an area opening a little larger to avoid to do a second one in the case the radius found is near the initial one. + do! logTimeWithName "First area opening" (fun () -> ImgTools.areaOpenF img_RBC_filtered initialAreaOpening; report 10) let range = let delta = config.Parameters.granulometryRange * config.RBCRadiusByResolution.Pixel int <| config.RBCRadiusByResolution.Pixel - delta, int <| config.RBCRadiusByResolution.Pixel + delta //let r1 = log "Granulometry (morpho)" (fun() -> Granulometry.findRadiusByClosing (filteredGreen.Convert()) range 1.0 |> float32) - let! radius = logTimeWithName "Granulometry (area)" (fun() -> reportWithVal 10 (Granulometry.findRadiusByAreaClosing filteredGreen range |> float32)) + let! radius = logTimeWithName "Granulometry (area)" (fun() -> reportWithVal 10 (Granulometry.findRadiusByAreaClosing img_RBC_filtered range |> float32)) config.SetRBCRadius <| radius logWithName (sprintf "Found erytrocyte diameter: %A" config.RBCRadius) @@ -74,15 +82,17 @@ let doAnalysis (img: Image) (name: string) (config: Config) (reportPr let secondAreaOpening = int <| config.RBCRadius.Area * config.Parameters.ratioAreaPaleCenter if secondAreaOpening > initialAreaOpening then - logTimeWithName "Second area opening" (fun () -> ImgTools.areaOpenF filteredGreen secondAreaOpening; report 30) + logTimeWithName "Second area opening" (fun () -> ImgTools.areaOpenF img_RBC_filtered secondAreaOpening; report 30) else report 30 - let parasites, filteredGreenWhitoutStain = ParasitesMarker.find filteredGreen config + ImgTools.areaCloseF img_RBC_filtered (config.RBCRadius.Area * 0.1f |> roundInt) + + let parasites, filteredGreenWhitoutStain, filteredGreenWithoutInfection = ParasitesMarker.find img_parasites config //let parasites, filteredGreenWhitoutInfection, filteredGreenWhitoutStain = ParasitesMarker.findMa greenFloat filteredGreenFloat config let! edges, xGradient, yGradient = logTimeWithName "Finding edges" (fun () -> - let edges, xGradient, yGradient = ImgTools.findEdges filteredGreenWhitoutStain + let edges, xGradient, yGradient = ImgTools.findEdges img_RBC_filtered removeArea edges (config.RBCRadius.Pixel ** 2.f / 50.f |> int) reportWithVal 40 (edges, xGradient, yGradient)) @@ -90,7 +100,7 @@ let doAnalysis (img: Image) (name: string) (config: Config) (reportPr let! prunedEllipses = logTimeWithName "Ellipses pruning" (fun () -> reportWithVal 80 (matchingEllipses.PrunedEllipses)) - let! cells = logTimeWithName "Classifier" (fun () -> reportWithVal 100 (Classifier.findCells prunedEllipses parasites filteredGreenWhitoutStain config)) + let! cells = logTimeWithName "Classifier" (fun () -> reportWithVal 100 (Classifier.findCells prunedEllipses parasites img_RBC_filtered config)) logWithName "Analysis finished" @@ -125,22 +135,17 @@ let doAnalysis (img: Image) (name: string) (config: Config) (reportPr drawCells imgCells' true cells saveImg imgCells' (buildFileName " - cells - full.png") - let filteredGreenMaxima = gaussianFilter greenFloat config.LPFStandardDeviation + let filteredGreenMaxima = gaussianFilter img_RBC config.LPFStandardDeviationRBC for m in ImgTools.findMaxima filteredGreenMaxima do ImgTools.drawPoints filteredGreenMaxima m 255.f saveImg filteredGreenMaxima (buildFileName " - filtered - maxima.png") - saveImg filteredGreen (buildFileName " - filtered.png") + saveImg img_RBC_filtered (buildFileName " - filtered.png") saveImg filteredGreenWhitoutStain (buildFileName " - filtered closed stain.png") - //saveImg filteredGreenWhitoutInfection (buildFileName " - filtered closed infection.png") - - saveImg green (buildFileName " - green.png") - - use blue = img.Item(0) - saveImg blue (buildFileName " - blue.png") + saveImg filteredGreenWithoutInfection (buildFileName " - filtered closed infection.png") - use red = img.Item(2) - saveImg red (buildFileName " - red.png") + saveImg img_RBC (buildFileName " - source - RBC.png") + saveImg img_parasites (buildFileName " - source - parasites.png") | _ -> () return cells }