<?xml version="1.0" encoding="utf-8"?>
<configuration>
<startup>
- <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1" />
+ <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" />
</startup>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
open System
open Const
+open UnitsOfMeasure
type Debug =
| DebugOff
| DebugOn of string // Output directory.
type Parameters = {
- initialAreaOpen: int // Area of the first initial opening to remove the central illumination of RBC.
- ratioSecondAreaOpen: float32 // The area of the second opening is 'ratioSecondAreaOpen' * mean RBC area. It's applied only if greater than 'initialAreaOpen'.
+ rbcDiameter: float<μm>
+ resolution: float<ppi>
+
+ ratioAreaPaleCenter: float32 // The area of the second opening is 'ratioSecondAreaOpen' * mean RBC area. It's applied only if greater than 'initialAreaOpen'.
+
+ granulometryRange: float32 // The radius will be seeked from radius - granulometryRange * radius to radius + granulometryRange * radius.
minRbcRadius: float32 // Factor of the mean RBC radius.
maxRbcRadius: float32 // Factor of the mean RBC radius.
- preFilterSigma: float // To remove the high frequency noise.
+ LPFStandardDeviation: float<μm> // Sigma parameter of the gaussian to remove the high frequency noise.
// Ellipse.
factorNbPick: float // The number of computed ellipse per edge pixel.
minimumCellAreaFactor: float32 // Factor of the mean RBC area.
}
+let defaultParameters = {
+ rbcDiameter = 8.<μm>
+ resolution = 200.e3<ppi> // Correspond to 50X.
+
+ ratioAreaPaleCenter = 1.f / 3.f // The ratio between an RBC area and the area of the its pale center.
+
+ granulometryRange = 0.5f
+
+ minRbcRadius = -0.3f
+ maxRbcRadius = 0.3f
+
+ LPFStandardDeviation = 0.2<μm> // 8.5e-6<inch>.
+
+ factorNbPick = 1.0
+
+ darkStainLevel = 0.25 // 0.3
+ maxDarkStainRatio = 0.1 // 10 %
+
+ infectionArea = 0.012f // 1.2 %
+ infectionLevel = 1.12 // Lower -> more sensitive.
+
+ stainArea = 0.08f // 8 %
+ stainLevel = 1.1 // Lower -> more sensitive.
+ maxStainRatio = 0.12 // 12 %
+
+ standardDeviationMaxRatio = 0.5 // 0.5
+ minimumCellAreaFactor = 0.4f }
+
type Config (param: Parameters) =
+ let initialRBCRadius : float32 =
+ let rbcRadiusInch: float<inch> = μm.ConvertToInch(param.rbcDiameter) / 2.
+ let rbcRadiusPx: float<px> = param.resolution * rbcRadiusInch
+ float32 rbcRadiusPx
+
member this.Parameters = param
member val Debug = DebugOff with get, set
+ member this.LPFStandardDeviation =
+ let stdDeviation: float<px> = μm.ConvertToInch(param.LPFStandardDeviation) * param.resolution
+ float stdDeviation
+
// Mean RBC radius.
- member val RBCRadius = 30.f with get, set
+ member val RBCRadius : float32 = initialRBCRadius with get, set
member this.RBCMinRadius = this.RBCRadius + param.minRbcRadius * this.RBCRadius
member this.RBCMaxRadius = this.RBCRadius + param.maxRbcRadius * this.RBCRadius
member this.Copy () =
this.MemberwiseClone() :?> Config
+
let y = rbc.center.Y - rbcHeight / 2. |> Utils.roundInt
let w = Utils.roundInt rbcWidth
let h = Utils.roundInt rbcHeight
- //Utils.dprintfn "w: %A, h: %A, cx: %A, cy: %A, img.w: %A, img.h: %A" w h x y img.Width img.Height
img.GetSubRect(System.Drawing.Rectangle(System.Drawing.Point((if x < 0 then 0 else x), (if y < 0 then 0 else y)),
System.Drawing.Size((if x + w >= img.Width then img.Width - x else w),
(if y + h >= img.Height then img.Height - y else h))))
<MenuItem x:Name="menuAddSourceImage" Header="_Add a source image" />
</MenuItem>
<MenuItem Header="_Analysis">
- <MenuItem x:Name="menuStartAnalysis" Header="_Show analyses window" />
+ <MenuItem x:Name="menuStartAnalysis" Header="_Show analysis window" />
</MenuItem>
<MenuItem Header="_View">
<MenuItem x:Name="menuHightlightRBC" Header="_Highlight healthy erytrocytes" IsCheckable="True" />
open Config
open Types
-
let doAnalysis (img: Image<Bgr, byte>) (name: string) (config: Config) (reportProgress: (int -> unit) option) : Cell list =
+ // To report the progress of this function from 0 to 100.
let inline report (percent: int) =
match reportProgress with
| Some f -> f percent
use green = img.Item(1)
let greenFloat = green.Convert<Gray, float32>()
- let filteredGreen = gaussianFilter greenFloat (float config.Parameters.preFilterSigma)
+ let filteredGreen = gaussianFilter greenFloat config.LPFStandardDeviation
- logTime "areaOpen 1" (fun () -> ImgTools.areaOpenF filteredGreen config.Parameters.initialAreaOpen)
+ let initialAreaOpening = int<| config.RBCArea * config.Parameters.ratioAreaPaleCenter
+ logTime "Area opening number one" (fun () -> ImgTools.areaOpenF filteredGreen initialAreaOpening)
report 8
- let r1 = logTime "Granulometry (morpho)" (fun() -> Granulometry.findRadiusByClosing (filteredGreen.Convert<Gray, byte>()) (10, 80) 0.5 |> float32)
- // let r2 = logTime "Granulometry (area)" (fun() -> Granulometry.findRadiusByAreaClosing filteredGreen (10, 80) |> float32)
+ let range =
+ let delta = config.Parameters.granulometryRange * config.RBCRadius
+ int <| config.RBCRadius - delta, int <| config.RBCRadius + delta
+ //let r1 = logTime "Granulometry (morpho)" (fun() -> Granulometry.findRadiusByClosing (filteredGreen.Convert<Gray, byte>()) range 1.0 |> float32)
+ let r2 = logTime "Granulometry (area)" (fun() -> Granulometry.findRadiusByAreaClosing filteredGreen range |> float32)
// log (sprintf "r1: %A, r2: %A" r1 r2)
- config.RBCRadius <- r1
+ config.RBCRadius <- r2
report 24
- let secondAreaOpen = int <| config.RBCArea * config.Parameters.ratioSecondAreaOpen
-
- if secondAreaOpen > config.Parameters.initialAreaOpen
+ let secondAreaOpening = int <| config.RBCArea * config.Parameters.ratioAreaPaleCenter
+ if secondAreaOpening > initialAreaOpening
then
- logTime "areaOpen 2" (fun () -> ImgTools.areaOpenF filteredGreen secondAreaOpen)
+ logTime "Area opening number two" (fun () -> ImgTools.areaOpenF filteredGreen secondAreaOpening)
let parasites, filteredGreenWhitoutStain = ParasitesMarker.find filteredGreen config
//let parasites, filteredGreenWhitoutInfection, filteredGreenWhitoutStain = ParasitesMarker.findMa greenFloat filteredGreenFloat config
drawCells imgCells' true cells
saveImg imgCells' (buildFileName " - cells - full.png")
- let filteredGreenMaxima = gaussianFilter greenFloat config.Parameters.preFilterSigma
+ let filteredGreenMaxima = gaussianFilter greenFloat config.LPFStandardDeviation
for m in ImgTools.findMaxima filteredGreenMaxima do
ImgTools.drawPoints filteredGreenMaxima m 255.f
saveImg filteredGreenMaxima (buildFileName " - filtered - maxima.png")
cells
-
// ID * cell radius * cell list.
let doMultipleAnalysis (imgs: (string * Image<Bgr, byte>) list) (config : Config) (reportProgress: (int -> unit) option) : (string * float * Cell list) list =
let inline report (percent: int) =
<OutputType>WinExe</OutputType>
<RootNamespace>Parasitemia</RootNamespace>
<AssemblyName>Parasitemia</AssemblyName>
- <TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
+ <TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<TargetFSharpCoreVersion>4.4.0.0</TargetFSharpCoreVersion>
<Name>Parasitemia</Name>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<WarningLevel>3</WarningLevel>
- <PlatformTarget>x64</PlatformTarget>
+ <PlatformTarget>AnyCPU</PlatformTarget>
<DocumentationFile>bin\Release\Parasitemia.XML</DocumentationFile>
<Prefer32Bit>false</Prefer32Bit>
<StartArguments>--folder "../../../Images/release" --output "../../../Images/output" --debug</StartArguments>
<ItemGroup>
<Compile Include="AssemblyInfo.fs" />
<Compile Include="Heap.fs" />
+ <Compile Include="UnitsOfMeasure.fs" />
<Compile Include="Const.fs" />
<Compile Include="Types.fs" />
<Compile Include="EEOver.fs" />
</ProjectReference>
</ItemGroup>
<PropertyGroup>
- <PostBuildEvent>xcopy "D:\Emgu\emgucv-windows-universal 3.0.0.2157\bin\x64" "$(TargetDir)x64" /Y /D /I</PostBuildEvent>
+ <PostBuildEvent>xcopy "D:\Emgu\emgucv-windows-universal 3.0.0.2157\bin\x64" "$(TargetDir)x64" /Y /D /I
+xcopy "D:\Emgu\emgucv-windows-universal 3.0.0.2157\bin\x86" "$(TargetDir)x86" /Y /D /I</PostBuildEvent>
</PropertyGroup>
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
let main args =
match parseArgs args with
| mode, debug ->
- let config =
- Config(
- {
- initialAreaOpen = 2000
- ratioSecondAreaOpen = 1.f / 3.f
-
- minRbcRadius = -0.3f
- maxRbcRadius = 0.3f
-
- preFilterSigma = 1.7 // 1.5
-
- factorNbPick = 1.0
-
- darkStainLevel = 0.25 // 0.3
- maxDarkStainRatio = 0.1 // 10 %
-
- infectionArea = 0.012f // 1.2 %
- infectionLevel = 1.12 // Lower -> more sensitive.
-
- stainArea = 0.08f // 8 %
- stainLevel = 1.1 // Lower -> more sensitive.
- maxStainRatio = 0.12 // 12 %
-
- standardDeviationMaxRatio = 0.5 // 0.55
- minimumCellAreaFactor = 0.5f })
+ let config = Config(defaultParameters)
match mode with
| CmdLine (input, output) ->
--- /dev/null
+module UnitsOfMeasure
+
+[<Measure>]
+type px
+
+[<Measure>]
+type μm =
+ static member ConvertToInch(x: float<μm>) : float<inch> =
+ x * 1.<inch> / 25.4e3<μm>
+
+and [<Measure>] inch
+
+
+[<Measure>]
+type ppi = px / inch
+
+
+