From: Greg Burri Date: Mon, 14 Dec 2015 21:06:31 +0000 (+0100) Subject: Fix an out-of-bound array access. X-Git-Tag: 1.0.11~79 X-Git-Url: http://git.euphorik.ch/?a=commitdiff_plain;h=8cf3b0a302943312c588690b4e4c90af17b3e87a;p=master-thesis.git Fix an out-of-bound array access. --- diff --git a/Parasitemia/Parasitemia/Classifier.fs b/Parasitemia/Parasitemia/Classifier.fs index e0bbfa9..8467d24 100644 --- a/Parasitemia/Parasitemia/Classifier.fs +++ b/Parasitemia/Parasitemia/Classifier.fs @@ -65,8 +65,8 @@ let findCells (ellipses: Ellipse list) (parasites: ParasitesMarker.Result) (fg: 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 @@ -86,8 +86,8 @@ let findCells (ellipses: Ellipse list) (parasites: ParasitesMarker.Result) (fg: 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 && diff --git a/Parasitemia/Parasitemia/KMedians.fs b/Parasitemia/Parasitemia/KMedians.fs index 82e09cb..1822c75 100644 --- a/Parasitemia/Parasitemia/KMedians.fs +++ b/Parasitemia/Parasitemia/KMedians.fs @@ -25,11 +25,11 @@ let kmedians (img: Image) (fgFactor: float) : Result = 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(img.Size) + use mutable d_bg = new Image(img.Size) let mutable d_fg = new Image(img.Size) let mutable fg = new Image(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) diff --git a/Parasitemia/Parasitemia/MainAnalysis.fs b/Parasitemia/Parasitemia/MainAnalysis.fs index 9308780..3f35fb7 100644 --- a/Parasitemia/Parasitemia/MainAnalysis.fs +++ b/Parasitemia/Parasitemia/MainAnalysis.fs @@ -59,7 +59,7 @@ let doAnalysis (img: Image) (name: string) (config: Config) : Cell li 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 diff --git a/Parasitemia/Parasitemia/Program.fs b/Parasitemia/Parasitemia/Program.fs index f23cd39..d7348cf 100644 --- a/Parasitemia/Parasitemia/Program.fs +++ b/Parasitemia/Parasitemia/Program.fs @@ -115,7 +115,7 @@ let main args = 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 ->