projects
/
master-thesis.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Remove the parasite detection function from Ma.
[master-thesis.git]
/
Parasitemia
/
ParasitemiaCore
/
Classifier.fs
diff --git
a/Parasitemia/ParasitemiaCore/Classifier.fs
b/Parasitemia/ParasitemiaCore/Classifier.fs
index
479ba59
..
2b6f3be
100644
(file)
--- a/
Parasitemia/ParasitemiaCore/Classifier.fs
+++ b/
Parasitemia/ParasitemiaCore/Classifier.fs
@@
-10,7
+10,6
@@
open Emgu.CV.Structure
open Types
open Utils
open Types
open Utils
-
type private EllipseFlaggedKd (e: Ellipse) =
inherit Ellipse (e.Cx, e.Cy, e.A, e.B, e.Alpha)
type private EllipseFlaggedKd (e: Ellipse) =
inherit Ellipse (e.Cx, e.Cy, e.A, e.B, e.Alpha)
@@
-20,13
+19,12
@@
type private EllipseFlaggedKd (e: Ellipse) =
member this.X = this.Cx
member this.Y = this.Cy
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 =
if ellipses.IsEmpty
then
[]
else
let findCells (ellipses: Ellipse list) (parasites: ParasitesMarker.Result) (img: Image<Gray, float32>) (config: Config.Config) : Cell list =
if ellipses.IsEmpty
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)
// 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)
@@
-57,13
+55,13
@@
let findCells (ellipses: Ellipse list) (parasites: ParasitesMarker.Result) (img:
let c' = PointF(e'.Cx, e'.Cy)
let v = pointFromTwoLines d1 (lineFromTwoPoints c c')
let case1 = sign (v.X - c.X) <> sign (v.X - c'.X) || Utils.squaredDistanceTwoPoints v c > Utils.squaredDistanceTwoPoints v c'
let c' = PointF(e'.Cx, e'.Cy)
let v = pointFromTwoLines d1 (lineFromTwoPoints c c')
let case1 = sign (v.X - c.X) <> sign (v.X - c'.X) || Utils.squaredDistanceTwoPoints v c > Utils.squaredDistanceTwoPoints v c'
- if
d2.Valid
+ if
not (Single.IsInfinity d2.A)
then
let p' = Utils.pointFromTwoLines d1 d2
let delta, delta' =
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 d
x1, dx2 = (c.X - p.X), (c.X - p'.X)
+ // To avoid rounding
issue
.
+ if abs d
x1 < 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
// Yield 'false' when the point is owned by another ellipse.
if case1
@@
-130,7
+128,6
@@
let findCells (ellipses: Ellipse list) (parasites: ParasitesMarker.Result) (img:
if stdDeviation > globalStdDeviation * config.Parameters.standardDeviationMaxRatio then
e.Removed <- true
if stdDeviation > globalStdDeviation * config.Parameters.standardDeviationMaxRatio then
e.Removed <- true
-
// 4) Remove ellipses with little area.
let minArea = config.RBCRadius.MinArea
for e, neighbors in ellipsesWithNeigbors do
// 4) Remove ellipses with little area.
let minArea = config.RBCRadius.MinArea
for e, neighbors in ellipsesWithNeigbors do
@@
-151,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.
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
ellipsesWithNeigbors
|> List.choose (fun (e, neighbors) ->
if e.Removed
@@
-160,7
+159,9
@@
let findCells (ellipses: Ellipse list) (parasites: ParasitesMarker.Result) (img:
let minX, minY, maxX, maxY = ellipseWindow e
let infectedPixels = List<Point>()
let minX, minY, maxX, maxY = ellipseWindow e
let infectedPixels = List<Point>()
- let mutable stainPixels = 0
+ let cytoplasmPixels = List<Point>()
+
+ //let mutable stainPixels = 0
let mutable darkStainPixels = 0
let mutable nbElement = 0
let mutable darkStainPixels = 0
let mutable nbElement = 0
@@
-173,34
+174,49
@@
let findCells (ellipses: Ellipse list) (parasites: ParasitesMarker.Result) (img:
elements.[y-minY, x-minX] <- 1uy
nbElement <- nbElement + 1
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))
then
infectedPixels.Add(Point(x, y))
- if
parasites.stain.Data.[y, x, 0] > 0uy
+ if
stain
then
then
- stainPixels <- stainPixels + 1
+ cytoplasmPixels.Add(Point(x, y))
- if
parasites.darkStain.Data.[y, x, 0] > 0uy
+ if
darkStain
then
darkStainPixels <- darkStainPixels + 1
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 =
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
then
Peculiar
- elif infectedPixels.Count >= 1
+
+ elif infectedPixels.Count > 0 && cytoplasmArea >= minimumParasiteArea
then
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
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)
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 })
elements = elements })