X-Git-Url: http://git.euphorik.ch/?a=blobdiff_plain;f=Parasitemia%2FParasitemiaCore%2FParasitesMarker.fs;h=73f9fe1da720cc9fe8bb215c823ebee636f87ee5;hb=3b645f8ff5259f88a33ffbd9a63b10a8640c439f;hp=ffe0d14b4289b35e4602c7aac5d87149552ca6ee;hpb=6c70577f0bcc17881c753f7a527d2ff4672bb6aa;p=master-thesis.git diff --git a/Parasitemia/ParasitemiaCore/ParasitesMarker.fs b/Parasitemia/ParasitemiaCore/ParasitesMarker.fs index ffe0d14..73f9fe1 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() - ImgTools.areaCloseF filteredGreenWithoutInfection (int config.RBCRadius.InfectionArea) +let find (img: Image) (config: Config.Config) : Result * Image * Image = + let imgFilteredInfection = ImgTools.gaussianFilter img config.LPFStandardDeviationParasite + let filteredGreenWithoutInfection = imgFilteredInfection.Copy() + ImgTools.areaCloseF filteredGreenWithoutInfection (roundInt config.RBCRadius.NucleusArea) + + (* 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,35 @@ 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) + let infectionMarker = marker imgFilteredInfection filteredGreenWithoutInfection (1. / config.Parameters.infectionSensitivity) - // TODO: comprendre pourquoi des valeurs sont negatives!?!? - (* - let blackTopHat = filteredGreen.CopyBlank() - CvInvoke.Subtract(filteredGreenWithoutInfection, filteredGreen, blackTopHat) - ImgTools.saveImg (ImgTools.normalizeAndConvert blackTopHat) "BottomHat.png" - *) + 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.cytoplasmSensitivity) + + // + (*let blackTopHat = filteredGreenWithoutStain.CopyBlank() + CvInvoke.Subtract(filteredGreenWithoutStain, imgFilteredStain, blackTopHat) + ImgTools.saveImg blackTopHat "blackTopHat.png"*) { darkStain = darkStain infection = infectionMarker stain = stainMarker }, - filteredGreenWithoutStain + filteredGreenWithoutStain, + filteredGreenWithoutInfection