then
[]
else
- let infection = parasites.infection.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)
e.Removed <- true
// 5) Define pixels associated to each ellipse and create the cells.
- let radiusParasiteRatio = 0.4f
- let radiusParasite = config.RBCRadius.Pixel * 0.5f
- let perimeterParasiteSquared = (2.f * radiusParasite) ** 2.f |> roundInt
- let parasiteOccupation = 0.08f // 8 %
- let minimumParasiteArea = Const.PI * radiusParasite ** 2.f * parasiteOccupation |> roundInt
- //let minimumStainArea = roundInt <| config.RBCRadius.Area * 0.02f // 1.5 %
+ 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 stainPixels = 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.stain.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
- stainPixels.Add(Point(x, y))
+ parasitePixels.Add(Point(x, y))
- if darkStain
+ if darkStainData.[y, x, 0] > 0uy
then
darkStainPixels <- darkStainPixels + 1
- let mutable stainArea = 0
- if infectedPixels.Count > 0
+ let mutable parasiteArea = 0
+ if nucleusPixels.Count > 0
then
- for stainPixel in stainPixels do
- if infectedPixels.Exists(fun p -> pown (p.X - stainPixel.X) 2 + pown (p.Y - stainPixel.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
- stainArea <- stainArea + 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 && stainArea >= minimumParasiteArea
+ elif nucleusPixels.Count > 0 && parasiteArea >= minimumParasiteArea
then
- let infectionToRemove = ImgTools.connectedComponents parasites.stain infectedPixels
+ let infectionToRemove = ImgTools.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)
- infectedArea = if cellClass = InfectedRBC then infectedPixels.Count else 0
- stainArea = stainArea
+ nucleusArea = if cellClass = InfectedRBC then nucleusPixels.Count else 0
+ parasiteArea = parasiteArea
elements = elements })