X-Git-Url: http://git.euphorik.ch/?p=master-thesis.git;a=blobdiff_plain;f=Parasitemia%2FParasitemiaCore%2FParasitesMarker.fs;h=b89caa68c02760b2dc4af0af0be28b48d4d12a1a;hp=0d7c7aebe89a14a8f64abdf5a9e5241b02e8d362;hb=2d712781def419c9acc98368f7102b19b064f16d;hpb=3f8b0d281b3058faf23dbd0363de440bd04c6574 diff --git a/Parasitemia/ParasitemiaCore/ParasitesMarker.fs b/Parasitemia/ParasitemiaCore/ParasitesMarker.fs index 0d7c7ae..b89caa6 100644 --- a/Parasitemia/ParasitemiaCore/ParasitesMarker.fs +++ b/Parasitemia/ParasitemiaCore/ParasitesMarker.fs @@ -12,14 +12,16 @@ open Otsu open Morpho open ImgTools -type Result = { - darkStain: Image // Colored pixel, it's independent of the size of the areas. It corresponds to white cells, schizontes, gametocytes, throphozoites. - nucleus: Image // Parasite nucleus. It may contain some debris. It shouldn't contain thrombocytes or larger elements. - parasite: Image } // The whole parasites. +type Result = + { + darkStain : Image // Colored pixel, it's independent of the size of the areas. It corresponds to white cells, schizontes, gametocytes, throphozoites. + nucleus : Image // Parasite nucleus. It may contain some debris. It shouldn't contain thrombocytes or larger elements. + parasite : Image // The whole parasites. + } -let find (img: Image) (config: Config.Config) : Result * Image * Image = +let find (img : Image) (config : Config.Config) : Result * Image * Image = - let imgWithoutNucleus = img.Copy() + let imgWithoutNucleus = img.Copy () areaCloseF imgWithoutNucleus (roundInt config.RBCRadius.NucleusArea) let darkStain = @@ -27,34 +29,37 @@ let find (img: Image) (config: Config.Config) : Result * Image) (closed: Image) (level: float) : Image = - let diff = img.Copy() - diff._Mul(level) - CvInvoke.Subtract(closed, diff, diff) - diff._ThresholdBinary(Gray(0.0), Gray(255.)) - diff.Convert() + let marker (img : Image) (closed : Image) (level : float) : Image = + let diff = img.Copy () + diff._Mul level + CvInvoke.Subtract (closed, diff, diff) + diff._ThresholdBinary (Gray 0.0, Gray 255.) + diff.Convert () + // Nucleus. let nucleusMarker = marker img imgWithoutNucleus (1. / config.Parameters.infectionSensitivity) - let imgWithoutParasite = img.CopyBlank() + // Cytoplasm. + let imgWithoutParasite = img.CopyBlank () let kernelSize = - let size = roundInt (config.RBCRadius.Pixel / 5.f) + let size = roundInt config.RBCRadius.CytoplasmSize 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)) + 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.GetStructuringElement (CvEnum.ElementShape.Ellipse, Size (kernelSize, kernelSize), Point (-1, -1)) - CvInvoke.MorphologyEx(img, imgWithoutParasite, CvEnum.MorphOp.Close, kernel, Point(-1, -1), 1, CvEnum.BorderType.Replicate, MCvScalar()) + CvInvoke.MorphologyEx (img, imgWithoutParasite, CvEnum.MorphOp.Close, kernel, Point(-1, -1), 1, CvEnum.BorderType.Replicate, MCvScalar()) let parasiteMarker = marker img imgWithoutParasite (1. / config.Parameters.cytoplasmSensitivity) - { darkStain = darkStain - nucleus = nucleusMarker - parasite = parasiteMarker }, + { + darkStain = darkStain + nucleus = nucleusMarker + parasite = parasiteMarker + }, imgWithoutParasite, imgWithoutNucleus