then
[]
else
- 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)
KdTree.maxX = e.Cx + (e.A + config.RBCRadius.Max)
// 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
+
+ let nucleusData = parasites.nucleus.Copy().Data // Will be modified thus the copy.
+ let parasiteData = parasites.parasite.Data
+ let darkStainData = parasites.darkStain.Data
+
ellipsesWithNeigbors
|> List.choose (fun (e, neighbors) ->
if e.Removed
else
let minX, minY, maxX, maxY = ellipseWindow e
- let infectedPixels = List<Point>()
- let cytoplasmPixels = List<Point>()
+ let nucleusPixels = List<Point>()
+ let parasitePixels = List<Point>()
- //let mutable stainPixels = 0
let mutable darkStainPixels = 0
let mutable nbElement = 0
let p = PointF(float32 x, float32 y)
if pixelOwnedByE p e (neighbors |> List.choose (fun (otherE, p1, p2) -> if otherE.Removed then None else Some (otherE :> Ellipse, Utils.lineFromTwoPoints p1 p2)))
then
- elements.[y-minY, x-minX] <- 1uy
+ elements.[y - minY, x - minX] <- 1uy
nbElement <- nbElement + 1
- 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
+ if nucleusData.[y, x, 0] > 0uy
then
- infectedPixels.Add(Point(x, y))
+ nucleusPixels.Add(Point(x, y))
- if stain
+ if parasiteData.[y, x, 0] > 0uy
then
- cytoplasmPixels.Add(Point(x, y))
+ parasitePixels.Add(Point(x, y))
- if darkStain
+ if darkStainData.[y, x, 0] > 0uy
then
darkStainPixels <- darkStainPixels + 1
- let mutable cytoplasmArea = 0
- if infectedPixels.Count > 0
+ let mutable parasiteArea = 0
+ if nucleusPixels.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)
+ for parasitePixel in parasitePixels do
+ if nucleusPixels.Exists(fun p -> pown (p.X - parasitePixel.X) 2 + pown (p.Y - parasitePixel.Y) 2 <= perimeterParasiteSquared)
then
- cytoplasmArea <- cytoplasmArea + 1
-
+ parasiteArea <- parasiteArea + 1
let cellClass =
if float darkStainPixels > config.Parameters.maxDarkStainRatio * (float nbElement)
- //|| float stainPixels > config.Parameters.maxStainRatio * (float nbElement)
then
Peculiar
- elif infectedPixels.Count > 0 && cytoplasmArea >= minimumParasiteArea
+ elif nucleusPixels.Count > 0 && parasiteArea >= minimumParasiteArea
then
- let infectionToRemove = ImgTools.connectedComponents parasites.cytoplasm infectedPixels
+ let infectionToRemove = Morpho.connectedComponents parasites.parasite nucleusPixels
for p in infectionToRemove do
- infection.Data.[p.Y, p.X, 0] <- 0uy
+ nucleusData.[p.Y, p.X, 0] <- 0uy
InfectedRBC
else
Some { cellClass = cellClass
center = Point(roundInt e.Cx, roundInt e.Cy)
- nucleusArea = if cellClass = InfectedRBC then infectedPixels.Count else 0
- parasiteArea = cytoplasmArea
+ nucleusArea = if cellClass = InfectedRBC then nucleusPixels.Count else 0
+ parasiteArea = parasiteArea
elements = elements })