projects
/
master-thesis.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Add functions to apply an area opening and to compute granulometry.
[master-thesis.git]
/
Parasitemia
/
Parasitemia
/
Classifier.fs
diff --git
a/Parasitemia/Parasitemia/Classifier.fs
b/Parasitemia/Parasitemia/Classifier.fs
index
e0bbfa9
..
3ed42f0
100644
(file)
--- a/
Parasitemia/Parasitemia/Classifier.fs
+++ b/
Parasitemia/Parasitemia/Classifier.fs
@@
-40,13
+40,13
@@
let findCells (ellipses: Ellipse list) (parasites: ParasitesMarker.Result) (fg:
let a = int (e.A + 0.5)
cx - a, cy - a, cx + a, cy + a
let a = int (e.A + 0.5)
cx - a, cy - a, cx + a, cy + a
- // 1) Remove ellipses touching the edges.
let w = float fg.Width
let h = float fg.Height
let w = float fg.Width
let h = float fg.Height
- let ellipsesInside = ellipses |> List.map (fun e -> EllipseFlaggedKd (e, Removed = e.isOutside w h))
- // 2) Associate touching ellipses with each ellipses.
- let tree = KdTree.Tree.BuildTree ellipsesInside
+ let ellipses = ellipses |> List.map EllipseFlaggedKd
+
+ // 1) Associate touching ellipses with each ellipses.
+ let tree = KdTree.Tree.BuildTree ellipses
let neighbors (e: Ellipse) : (EllipseFlaggedKd * PointD * PointD) list =
tree.Search (searchRegion e)
// We only keep the ellipses touching 'e'.
let neighbors (e: Ellipse) : (EllipseFlaggedKd * PointD * PointD) list =
tree.Search (searchRegion e)
// We only keep the ellipses touching 'e'.
@@
-57,18
+57,18
@@
let findCells (ellipses: Ellipse list) (parasites: ParasitesMarker.Result) (fg:
| _ ->
None )
| _ ->
None )
- let ellipsesWithNeigbors = ellipses
Inside
|> List.choose (fun e -> if e.Removed then None else Some (e, neighbors e))
+ let ellipsesWithNeigbors = ellipses |> List.choose (fun e -> if e.Removed then None else Some (e, neighbors e))
- //
3) Remove ellipses with a lower percentage of foreground
.
- for e, neighbors in ellipsesWithNeigbors do
+ //
2) Remove ellipses with a lower percentage of foreground. (taken from the lower score to the highest)
.
+ for e, neighbors in
List.rev
ellipsesWithNeigbors do
let minX, minY, maxX, maxY = ellipseWindow e
let mutable totalElement = 0
let mutable fgElement = 0
let minX, minY, maxX, maxY = ellipseWindow e
let mutable totalElement = 0
let mutable fgElement = 0
- for y in
minY .. maxY
do
- for x in
minX .. maxX
do
+ for y in
(if minY < 0 then 0 else minY) .. (if maxY >= fg.Height then fg.Height - 1 else maxY)
do
+ for x in
(if minX < 0 then 0 else minX) .. (if maxX >= fg.Width then fg.Width - 1 else maxX)
do
let yf, xf = float y, float x
let yf, xf = float y, float x
- if e.Contains xf yf && neighbors |> List.forall (fun (otherE, _, _) -> not <| otherE.Contains xf yf)
+ if e.Contains xf yf && neighbors |> List.forall (fun (otherE, _, _) ->
otherE.Removed ||
not <| otherE.Contains xf yf)
then
totalElement <- totalElement + 1
if fg.Data.[y, x, 0] > 0uy
then
totalElement <- totalElement + 1
if fg.Data.[y, x, 0] > 0uy
@@
-79,6
+79,10
@@
let findCells (ellipses: Ellipse list) (parasites: ParasitesMarker.Result) (fg:
then
e.Removed <- true
then
e.Removed <- true
+ // 3) Remove ellipses touching the edges.
+ for e in ellipses do
+ if e.isOutside w h then e.Removed <- true
+
// 4) Remove ellipses with little area.
for e, neighbors in ellipsesWithNeigbors do
if not e.Removed
// 4) Remove ellipses with little area.
for e, neighbors in ellipsesWithNeigbors do
if not e.Removed
@@
-86,8
+90,8
@@
let findCells (ellipses: Ellipse list) (parasites: ParasitesMarker.Result) (fg:
let minX, minY, maxX, maxY = ellipseWindow e
let mutable area = 0
let minX, minY, maxX, maxY = ellipseWindow e
let mutable area = 0
- for y in
minY .. maxY
do
- for x in
minX .. maxX
do
+ for y in
(if minY < 0 then 0 else minY) .. (if maxY >= fg.Height then fg.Height - 1 else maxY)
do
+ for x in
(if minX < 0 then 0 else minX) .. (if maxX >= fg.Width then fg.Width - 1 else maxX)
do
let yf, xf = float y, float x
if fg.Data.[y, x, 0] > 0uy &&
e.Contains xf yf &&
let yf, xf = float y, float x
if fg.Data.[y, x, 0] > 0uy &&
e.Contains xf yf &&