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
if e.Contains xf yf && neighbors |> List.forall (fun (otherE, _, _) -> not <| otherE.Contains xf yf)
then
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 mutable median_bg = (!max).[0] - ((!max).[0] - (!min).[0]) / 4.0
let mutable median_fg = (!min).[0] + ((!max).[0] - (!min).[0]) / 4.0
- let mutable d_bg = new Image<Gray, float32>(img.Size)
+ use mutable d_bg = new Image<Gray, float32>(img.Size)
let mutable d_fg = new Image<Gray, float32>(img.Size)
let mutable fg = new Image<Gray, byte>(img.Size)
- for i in 1..nbIteration do
+ for i in 1 .. nbIteration do
CvInvoke.Pow(img - median_bg, 2.0, d_bg)
CvInvoke.Pow(img - median_fg, 2.0, d_fg)
fg <- (d_fg * fgFactor).Cmp(d_bg, CvEnum.CmpType.LessThan)
logTime "Finding edges" (fun() -> thin edges)
logTime "Removing small connected components from thinning" (fun () -> removeArea edges 12)
- let kmediansResults = KMedians.kmedians filteredGreen 1.0
+ let kmediansResults = logTime "Finding foreground (k-medians)" (fun () -> KMedians.kmedians filteredGreen 1.0)
let parasites = ParasitesMarker.find green filteredGreen kmediansResults config
let total, infected = Utils.countCells cells
fprintf resultFile "File: %s %d %d %.2f\n" file total infected (100. * (float infected) / (float total))
with
- | _ as ex -> Utils.log (sprintf "Unable to open the image '%A': %A" file ex)
+ | :? IOException as ex -> Utils.log (sprintf "Unable to open the image '%A': %A" file ex)
0
| Window ->