member this.X = this.Cx
member this.Y = this.Cy
-let findCells (ellipses: Ellipse list) (parasites: ParasitesMarker.Result) (img: Image<Gray, float32>) (config: Config.Config) : Cell list =
+let findCells (ellipses: Ellipse list) (parasites: ParasitesMarker.Result) (width: int) (height: int) (config: Config.Config) : Cell list =
if ellipses.IsEmpty
then
[]
let a = int (e.A + 0.5f)
cx - a, cy - a, cx + a, cy + a
- let w = img.Width
- let w_f = float32 w
- let h = img.Height
- let h_f = float32 h
-
// Return 'true' if the point 'p' is owned by e.
// The lines represents all intersections with other ellipses.
let pixelOwnedByE (p: PointF) (e: Ellipse) (others: (Ellipse * Line) list) =
let ellipsesWithNeigbors = ellipses |> List.map (fun e -> e, neighbors e) |> List.rev
// 2) Remove ellipses touching the edges.
+ let widthF, heightF = float32 width, float32 height
for e in ellipses do
- if e.isOutside w_f h_f then e.Removed <- true
+ if e.isOutside widthF heightF then e.Removed <- true
// 3) Remove ellipses with a high standard deviation (high contrast).
- let imgData = img.Data
+ // Obsolete. It was useful when the ellipses result quality wasn't good.
+ (* let imgData = img.Data
let globalStdDeviation = MathNet.Numerics.Statistics.Statistics.PopulationStandardDeviation(seq {
for y in 0 .. h - 1 do
for x in 0 .. w - 1 do
yield float imgData.[y, x, 0] })
if stdDeviation > globalStdDeviation * config.Parameters.standardDeviationMaxRatio then
- e.Removed <- true
+ e.Removed <- true *)
// 4) Remove ellipses with little area.
let minArea = config.RBCRadius.MinArea
let minX, minY, maxX, maxY = ellipseWindow e
let mutable area = 0
- for y in (if minY < 0 then 0 else minY) .. (if maxY >= h then h - 1 else maxY) do
- for x in (if minX < 0 then 0 else minX) .. (if maxX >= w then w - 1 else maxX) do
+ for y in (if minY < 0 then 0 else minY) .. (if maxY >= height then height - 1 else maxY) do
+ for x in (if minX < 0 then 0 else minX) .. (if maxX >= width then width - 1 else maxX) do
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
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 diameterParasiteSquared = (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.
if nucleusPixels.Count > 0
then
for parasitePixel in parasitePixels do
- if nucleusPixels.Exists(fun p -> pown (p.X - parasitePixel.X) 2 + pown (p.Y - parasitePixel.Y) 2 <= perimeterParasiteSquared)
+ if nucleusPixels.Exists(fun p -> pown (p.X - parasitePixel.X) 2 + pown (p.Y - parasitePixel.Y) 2 <= diameterParasiteSquared)
then
parasiteArea <- parasiteArea + 1
nucleusAreaRatio: float32 // Factor of a RBC area. 0.5 means the half of RBC area.
infectionSensitivity: float // between 0 (the least sensitive) and 1 (the most sensitive).
- standardDeviationMaxRatio: float // The standard deviation of the pixel values of a cell can't be greater than standardDeviationMaxRatio * global standard deviation
+ // [<Obsolete>] standardDeviationMaxRatio: float // The standard deviation of the pixel values of a cell can't be greater than standardDeviationMaxRatio * global standard deviation
minimumCellAreaFactor: float32 } // Factor of the mean RBC area. A cell with an area below this will be rejected.
let defaultParameters = {
nucleusAreaRatio = 0.01f // 1.0 %
infectionSensitivity = 0.92
- standardDeviationMaxRatio = 0.6
+ // standardDeviationMaxRatio = 0.6 // Obsolete.
minimumCellAreaFactor = 0.4f }
type RBCRadius (radius: float32, parameters: Parameters) =