X-Git-Url: http://git.euphorik.ch/?p=master-thesis.git;a=blobdiff_plain;f=Parasitemia%2FParasitemiaCore%2FParasitesMarker.fs;h=f4d9f35d0129a246b1fa2ad5662c7c158a8e74ef;hp=ffe0d14b4289b35e4602c7aac5d87149552ca6ee;hb=db49e167a602ef1df02a8b5f7de334355a4917dd;hpb=c4a76a01f62568c6353396ff85551a3151fc5236 diff --git a/Parasitemia/ParasitemiaCore/ParasitesMarker.fs b/Parasitemia/ParasitemiaCore/ParasitesMarker.fs index ffe0d14..f4d9f35 100644 --- a/Parasitemia/ParasitemiaCore/ParasitesMarker.fs +++ b/Parasitemia/ParasitemiaCore/ParasitesMarker.fs @@ -48,12 +48,15 @@ let findMa (green: Image) (filteredGreen: Image) ( // * 'Dark stain' corresponds to the colored pixel, it's independent of the size of the areas. // * 'Stain' corresponds to the stain around the parasites. // * 'Infection' corresponds to the parasite. It shouldn't contain thrombocytes. -let find (filteredGreen: Image) (config: Config.Config) : Result * Image = - use filteredGreenWithoutInfection = filteredGreen.Copy() +let find (img: Image) (config: Config.Config) : Result * Image * Image = + + let imgFilteredInfection = ImgTools.gaussianFilter img config.LPFStandardDeviationParasite + let filteredGreenWithoutInfection = imgFilteredInfection.Copy() ImgTools.areaCloseF filteredGreenWithoutInfection (int config.RBCRadius.InfectionArea) + (* let filteredGreenWithoutStain = filteredGreenWithoutInfection.Copy() - ImgTools.areaCloseF filteredGreenWithoutStain (int config.RBCRadius.StainArea) + ImgTools.areaCloseF filteredGreenWithoutStain (int config.RBCRadius.StainArea) *) let darkStain = // We use the filtered image to find the dark stain. @@ -69,19 +72,34 @@ let find (filteredGreen: Image) (config: Config.Config) : Result diff._ThresholdBinary(Gray(0.0), Gray(255.)) diff.Convert() - let infectionMarker = marker filteredGreen filteredGreenWithoutInfection (1. / config.Parameters.infectionSensitivity) - let stainMarker = marker filteredGreenWithoutInfection filteredGreenWithoutStain (1. / config.Parameters.stainSensitivity) - - // TODO: comprendre pourquoi des valeurs sont negatives!?!? - (* - let blackTopHat = filteredGreen.CopyBlank() - CvInvoke.Subtract(filteredGreenWithoutInfection, filteredGreen, blackTopHat) - ImgTools.saveImg (ImgTools.normalizeAndConvert blackTopHat) "BottomHat.png" - *) + let infectionMarker = marker imgFilteredInfection filteredGreenWithoutInfection (1. / config.Parameters.infectionSensitivity) + + let imgFilteredStain = ImgTools.gaussianFilter img config.LPFStandardDeviationStain + let areaOpening = int <| config.RBCRadius.Area * config.Parameters.ratioAreaPaleCenter + //ImgTools.areaOpenF imgFilteredStain areaOpening + + let filteredGreenWithoutStain = imgFilteredStain.CopyBlank() + let kernelSize = + let size = roundInt (config.RBCRadius.Pixel / 5.f) + if size % 2 = 0 then size + 1 else size + use kernel = + if kernelSize <= 3 + then + CvInvoke.GetStructuringElement(CvEnum.ElementShape.Rectangle, Size(3, 3), Point(-1, -1)) + else + CvInvoke.GetStructuringElement(CvEnum.ElementShape.Ellipse, Size(kernelSize, kernelSize), Point(-1, -1)) + CvInvoke.MorphologyEx(imgFilteredStain, filteredGreenWithoutStain, CvEnum.MorphOp.Close, kernel, Point(-1, -1), 1, CvEnum.BorderType.Replicate, MCvScalar()) + let stainMarker = marker (*filteredGreenWithoutInfection*) imgFilteredStain filteredGreenWithoutStain (1. / config.Parameters.stainSensitivity) + + // + (*let blackTopHat = filteredGreenWithoutStain.CopyBlank() + CvInvoke.Subtract(filteredGreenWithoutStain, imgFilteredStain, blackTopHat) + ImgTools.saveImg blackTopHat "blackTopHat.png"*) { darkStain = darkStain infection = infectionMarker stain = stainMarker }, - filteredGreenWithoutStain + filteredGreenWithoutStain, + filteredGreenWithoutInfection