X-Git-Url: http://git.euphorik.ch/?a=blobdiff_plain;f=Parasitemia%2FParasitemiaCore%2FClassifier.fs;h=2b6f3bee0ab729f6c401ffceca5f58c7b260c0ef;hb=828e126c88524d3dc123abc966a132532aed118b;hp=9f4fdd051d5553765bb2ba113e42d5e67ddadc2f;hpb=074d6b0377f51e868deb1c427891c722d0270deb;p=master-thesis.git diff --git a/Parasitemia/ParasitemiaCore/Classifier.fs b/Parasitemia/ParasitemiaCore/Classifier.fs index 9f4fdd0..2b6f3be 100644 --- a/Parasitemia/ParasitemiaCore/Classifier.fs +++ b/Parasitemia/ParasitemiaCore/Classifier.fs @@ -24,7 +24,7 @@ let findCells (ellipses: Ellipse list) (parasites: ParasitesMarker.Result) (img: then [] else - let infection = parasites.infection.Copy() // To avoid to modify the parameter. + let infection = parasites.nucleus.Copy() // To avoid to modify the parameter. // This is the minimum window size to check if other ellipses touch 'e'. let searchRegion (e: Ellipse) = { KdTree.minX = e.Cx - (e.A + config.RBCRadius.Max) @@ -59,9 +59,9 @@ let findCells (ellipses: Ellipse list) (parasites: ParasitesMarker.Result) (img: then let p' = Utils.pointFromTwoLines d1 d2 let delta, delta' = - let d = c.X - p.X - // To avoid rounding. - if abs d < 0.001f then c.Y - p.Y, c.Y - p'.Y else d, c.X - p'.X + let dx1, dx2 = (c.X - p.X), (c.X - p'.X) + // To avoid rounding issue. + if abs dx1 < 0.01f || abs dx2 < 0.01f then c.Y - p.Y, c.Y - p'.Y else dx1, dx2 // Yield 'false' when the point is owned by another ellipse. if case1 @@ -148,6 +148,8 @@ let findCells (ellipses: Ellipse list) (parasites: ParasitesMarker.Result) (img: e.Removed <- true // 5) Define pixels associated to each ellipse and create the cells. + let perimeterParasiteSquared = (2.f * config.RBCRadius.ParasiteRadius) ** 2.f |> roundInt + let minimumParasiteArea = config.RBCRadius.MinimumParasiteArea |> roundInt ellipsesWithNeigbors |> List.choose (fun (e, neighbors) -> if e.Removed @@ -157,7 +159,9 @@ let findCells (ellipses: Ellipse list) (parasites: ParasitesMarker.Result) (img: let minX, minY, maxX, maxY = ellipseWindow e let infectedPixels = List() - let mutable stainPixels = 0 + let cytoplasmPixels = List() + + //let mutable stainPixels = 0 let mutable darkStainPixels = 0 let mutable nbElement = 0 @@ -170,34 +174,49 @@ let findCells (ellipses: Ellipse list) (parasites: ParasitesMarker.Result) (img: elements.[y-minY, x-minX] <- 1uy nbElement <- nbElement + 1 - if infection.Data.[y, x, 0] > 0uy + let infected = infection.Data.[y, x, 0] > 0uy + let stain = parasites.cytoplasm.Data.[y, x, 0] > 0uy + let darkStain = parasites.darkStain.Data.[y, x, 0] > 0uy + + if infected then infectedPixels.Add(Point(x, y)) - if parasites.stain.Data.[y, x, 0] > 0uy + if stain then - stainPixels <- stainPixels + 1 + cytoplasmPixels.Add(Point(x, y)) - if parasites.darkStain.Data.[y, x, 0] > 0uy + if darkStain then darkStainPixels <- darkStainPixels + 1 + let mutable cytoplasmArea = 0 + if infectedPixels.Count > 0 + then + for cytoplasmPixel in cytoplasmPixels do + if infectedPixels.Exists(fun p -> pown (p.X - cytoplasmPixel.X) 2 + pown (p.Y - cytoplasmPixel.Y) 2 <= perimeterParasiteSquared) + then + cytoplasmArea <- cytoplasmArea + 1 + + let cellClass = - if float darkStainPixels > config.Parameters.maxDarkStainRatio * (float nbElement) || - float stainPixels > config.Parameters.maxStainRatio * (float nbElement) + if float darkStainPixels > config.Parameters.maxDarkStainRatio * (float nbElement) + //|| float stainPixels > config.Parameters.maxStainRatio * (float nbElement) then Peculiar - elif infectedPixels.Count >= 1 + + elif infectedPixels.Count > 0 && cytoplasmArea >= minimumParasiteArea then - let infectionToRemove = ImgTools.connectedComponents parasites.stain infectedPixels + let infectionToRemove = ImgTools.connectedComponents parasites.cytoplasm infectedPixels for p in infectionToRemove do infection.Data.[p.Y, p.X, 0] <- 0uy InfectedRBC + else HealthyRBC Some { cellClass = cellClass center = Point(roundInt e.Cx, roundInt e.Cy) - infectedArea = infectedPixels.Count - stainArea = stainPixels + nucleusArea = if cellClass = InfectedRBC then infectedPixels.Count else 0 + parasiteArea = cytoplasmArea elements = elements })